blob: 74dfbb275797b88203f39e5b97f92a974bced4b3 [file] [log] [blame]
[email protected]3a80ea332012-01-09 19:53:291// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5// When each service is created, we set a flag indicating this. At this point,
6// the service initialization could fail or succeed. This allows us to remember
7// if we tried to create a service, and not try creating it over and over if
8// the creation failed.
9
[email protected]58dca552009-06-17 00:35:0210#ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
11#define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
[email protected]32b76ef2010-07-26 23:08:2412#pragma once
initial.commit09911bf2008-07-26 23:55:2913
14#include <string>
15
16#include "base/basictypes.h"
[email protected]6b4e6852012-02-14 04:02:4817#include "base/debug/stack_trace.h"
[email protected]3b63f8f42011-03-28 01:54:1518#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/message_loop.h"
[email protected]c9177502011-01-01 04:48:4920#include "base/threading/non_thread_safe.h"
[email protected]bd48c2b02010-04-09 20:32:4221#include "base/timer.h"
initial.commit09911bf2008-07-26 23:55:2922#include "chrome/browser/browser_process.h"
[email protected]492d2142010-09-10 13:55:1823#include "chrome/browser/prefs/pref_change_registrar.h"
[email protected]8b08a47f2011-02-25 12:36:3724#include "chrome/browser/prefs/pref_member.h"
[email protected]2e5b60a22011-11-28 15:56:4125#include "content/public/browser/browser_thread.h"
[email protected]6c2381d2011-10-19 02:52:5326#include "content/public/browser/notification_observer.h"
[email protected]d55aaa132009-09-28 21:08:0427#include "ipc/ipc_message.h"
[email protected]b112a4c2009-02-01 20:24:0128
[email protected]b2fcd0e2010-12-01 15:19:4029class ChromeNetLog;
[email protected]8bcdf072011-06-03 16:52:1530class ChromeResourceDispatcherHostDelegate;
initial.commit09911bf2008-07-26 23:55:2931class CommandLine;
[email protected]4475d232011-07-27 15:29:2032class RemoteDebuggingServer;
[email protected]0b4d3382010-07-14 16:13:0433class TabCloseableStateWatcher;
initial.commit09911bf2008-07-26 23:55:2934
[email protected]5b869962011-09-20 19:49:3335namespace policy {
[email protected]fcf53572011-06-29 15:44:3736class BrowserPolicyConnector;
[email protected]a4179c2a2012-02-09 18:14:2137class PolicyService;
[email protected]fcf53572011-06-29 15:44:3738};
39
initial.commit09911bf2008-07-26 23:55:2940// Real implementation of BrowserProcess that creates and returns the services.
[email protected]6618d1d2010-12-15 21:18:4741class BrowserProcessImpl : public BrowserProcess,
[email protected]c9177502011-01-01 04:48:4942 public base::NonThreadSafe,
[email protected]6c2381d2011-10-19 02:52:5343 public content::NotificationObserver {
initial.commit09911bf2008-07-26 23:55:2944 public:
[email protected]f3a4f302009-08-21 22:35:2945 explicit BrowserProcessImpl(const CommandLine& command_line);
initial.commit09911bf2008-07-26 23:55:2946 virtual ~BrowserProcessImpl();
47
[email protected]99907362012-01-11 05:41:4048 // Called before the browser threads are created.
49 void PreCreateThreads();
[email protected]2e5b60a22011-11-28 15:56:4150
[email protected]d2caaa22011-12-12 03:04:1551 // Called after the threads have been created but before the message loops
52 // starts running. Allows the browser process to do any initialization that
53 // requires all threads running.
54 void PreMainMessageLoopRun();
55
[email protected]2e5b60a22011-11-28 15:56:4156 // Most cleanup is done by these functions, driven from
57 // ChromeBrowserMain based on notifications from the content
58 // framework, rather than in the destructor, so that we can
59 // interleave cleanup with threads being stopped.
60 void StartTearDown();
[email protected]99907362012-01-11 05:41:4061 void PostDestroyThreads();
[email protected]2e5b60a22011-11-28 15:56:4162
[email protected]6618d1d2010-12-15 21:18:4763 // BrowserProcess methods
[email protected]99907362012-01-11 05:41:4064 virtual void ResourceDispatcherHostCreated() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3265 virtual void EndSession() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3266 virtual MetricsService* metrics_service() OVERRIDE;
67 virtual IOThread* io_thread() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3268 virtual WatchDogThread* watchdog_thread() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3269 virtual ProfileManager* profile_manager() OVERRIDE;
70 virtual PrefService* local_state() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3271 virtual ui::Clipboard* clipboard() OVERRIDE;
72 virtual net::URLRequestContextGetter* system_request_context() OVERRIDE;
[email protected]db0e86dd2011-03-16 14:47:2173#if defined(OS_CHROMEOS)
[email protected]5b869962011-09-20 19:49:3374 virtual browser::OomPriorityManager* oom_priority_manager() OVERRIDE;
[email protected]db0e86dd2011-03-16 14:47:2175#endif // defined(OS_CHROMEOS)
[email protected]120655d2011-09-16 22:10:3276 virtual ExtensionEventRouterForwarder*
77 extension_event_router_forwarder() OVERRIDE;
78 virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
79 virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE;
[email protected]a4179c2a2012-02-09 18:14:2180 virtual policy::PolicyService* policy_service() OVERRIDE;
[email protected]120655d2011-09-16 22:10:3281 virtual IconManager* icon_manager() OVERRIDE;
82 virtual ThumbnailGenerator* GetThumbnailGenerator() OVERRIDE;
83 virtual AutomationProviderList* GetAutomationProviderList() OVERRIDE;
[email protected]5613126e2011-01-31 15:27:5584 virtual void InitDevToolsHttpProtocolHandler(
[email protected]4475d232011-07-27 15:29:2085 Profile* profile,
[email protected]01000cf12011-02-04 11:39:2286 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:5587 int port,
[email protected]120655d2011-09-16 22:10:3288 const std::string& frontend_url) OVERRIDE;
[email protected]120655d2011-09-16 22:10:3289 virtual unsigned int AddRefModule() OVERRIDE;
90 virtual unsigned int ReleaseModule() OVERRIDE;
91 virtual bool IsShuttingDown() OVERRIDE;
92 virtual printing::PrintJobManager* print_job_manager() OVERRIDE;
93 virtual printing::PrintPreviewTabController*
94 print_preview_tab_controller() OVERRIDE;
95 virtual printing::BackgroundPrintingManager*
96 background_printing_manager() OVERRIDE;
97 virtual GoogleURLTracker* google_url_tracker() OVERRIDE;
98 virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
99 virtual const std::string& GetApplicationLocale() OVERRIDE;
100 virtual void SetApplicationLocale(const std::string& locale) OVERRIDE;
101 virtual DownloadStatusUpdater* download_status_updater() OVERRIDE;
102 virtual DownloadRequestLimiter* download_request_limiter() OVERRIDE;
103 virtual TabCloseableStateWatcher* tab_closeable_state_watcher() OVERRIDE;
104 virtual BackgroundModeManager* background_mode_manager() OVERRIDE;
105 virtual StatusTray* status_tray() OVERRIDE;
106 virtual SafeBrowsingService* safe_browsing_service() OVERRIDE;
[email protected]a7a5e992010-12-09 23:39:51107 virtual safe_browsing::ClientSideDetectionService*
[email protected]120655d2011-09-16 22:10:32108 safe_browsing_detection_service() OVERRIDE;
109 virtual bool plugin_finder_disabled() const OVERRIDE;
[email protected]6641bf662009-08-21 00:34:09110
[email protected]6c2381d2011-10-19 02:52:53111 // content::NotificationObserver methods
[email protected]432115822011-07-10 15:52:27112 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) OVERRIDE;
[email protected]6618d1d2010-12-15 21:18:47115
[email protected]3cdacd42010-04-30 18:55:53116#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]120655d2011-09-16 22:10:32117 virtual void StartAutoupdateTimer() OVERRIDE;
[email protected]3cdacd42010-04-30 18:55:53118#endif
[email protected]bd48c2b02010-04-09 20:32:42119
[email protected]120655d2011-09-16 22:10:32120 virtual ChromeNetLog* net_log() OVERRIDE;
[email protected]120655d2011-09-16 22:10:32121 virtual prerender::PrerenderTracker* prerender_tracker() OVERRIDE;
[email protected]120655d2011-09-16 22:10:32122 virtual ComponentUpdateService* component_updater() OVERRIDE;
[email protected]0d5c08e2011-11-21 16:51:06123 virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE;
[email protected]ca167a32011-09-30 15:19:11124
initial.commit09911bf2008-07-26 23:55:29125 private:
initial.commit09911bf2008-07-26 23:55:29126 void CreateMetricsService();
[email protected]0b565182011-03-02 18:11:15127 void CreateWatchdogThread();
[email protected]2d14b3732011-05-10 16:48:44128#if defined(OS_CHROMEOS)
[email protected]2e5b60a22011-11-28 15:56:41129 void InitializeWebSocketProxyThread();
[email protected]2d14b3732011-05-10 16:48:44130#endif
[email protected]8e5c89a2011-06-07 18:13:33131 void CreateTemplateURLService();
initial.commit09911bf2008-07-26 23:55:29132 void CreateProfileManager();
133 void CreateWebDataService();
134 void CreateLocalState();
135 void CreateViewedPageTracker();
136 void CreateIconManager();
initial.commit09911bf2008-07-26 23:55:29137 void CreateGoogleURLTracker();
[email protected]c4ff4952010-01-08 19:12:47138 void CreateIntranetRedirectDetector();
[email protected]29672ab2009-10-30 03:44:03139 void CreateNotificationUIManager();
[email protected]ccb55cf52010-03-06 22:02:04140 void CreateStatusTrayManager();
[email protected]0b4d3382010-07-14 16:13:04141 void CreateTabCloseableStateWatcher();
[email protected]dbeebd52010-11-16 20:34:16142 void CreatePrintPreviewTabController();
[email protected]68f88b992011-05-07 02:01:39143 void CreateBackgroundPrintingManager();
[email protected]462a0ff2011-06-02 17:15:34144 void CreateSafeBrowsingService();
[email protected]a7a5e992010-12-09 23:39:51145 void CreateSafeBrowsingDetectionService();
[email protected]9e7f015f2011-05-28 00:24:25146 void CreateStatusTray();
147 void CreateBackgroundModeManager();
[email protected]a7a5e992010-12-09 23:39:51148
[email protected]419a0572011-04-18 22:21:46149 void ApplyDisabledSchemesPolicy();
[email protected]40850a52011-05-26 22:07:35150 void ApplyAllowCrossOriginAuthPromptPolicy();
[email protected]b61f62a2011-11-01 02:02:10151 void ApplyDefaultBrowserPolicy();
[email protected]419a0572011-04-18 22:21:46152
initial.commit09911bf2008-07-26 23:55:29153 bool created_metrics_service_;
154 scoped_ptr<MetricsService> metrics_service_;
155
[email protected]0ac83682010-01-22 17:46:27156 scoped_ptr<IOThread> io_thread_;
initial.commit09911bf2008-07-26 23:55:29157
[email protected]0b565182011-03-02 18:11:15158 bool created_watchdog_thread_;
159 scoped_ptr<WatchDogThread> watchdog_thread_;
160
[email protected]8d6b2432012-03-31 12:11:18161 // Must be destroyed after |local_state_|.
162 scoped_ptr<policy::PolicyService> policy_service_;
163
initial.commit09911bf2008-07-26 23:55:29164 bool created_profile_manager_;
165 scoped_ptr<ProfileManager> profile_manager_;
166
167 bool created_local_state_;
168 scoped_ptr<PrefService> local_state_;
169
initial.commit09911bf2008-07-26 23:55:29170 bool created_icon_manager_;
171 scoped_ptr<IconManager> icon_manager_;
172
[email protected]3ce02412011-03-01 12:01:15173 scoped_refptr<ExtensionEventRouterForwarder>
174 extension_event_router_forwarder_;
175
[email protected]4475d232011-07-27 15:29:20176 scoped_ptr<RemoteDebuggingServer> remote_debugging_server_;
[email protected]5613126e2011-01-31 15:27:55177
[email protected]985655a2011-02-23 09:54:25178 bool created_browser_policy_connector_;
179 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
[email protected]f2a893c2011-01-05 09:38:07180
[email protected]dbeebd52010-11-16 20:34:16181 scoped_refptr<printing::PrintPreviewTabController>
182 print_preview_tab_controller_;
183
[email protected]68f88b992011-05-07 02:01:39184 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
185
[email protected]2dfeaf92011-01-10 21:08:21186 scoped_ptr<ui::Clipboard> clipboard_;
initial.commit09911bf2008-07-26 23:55:29187
[email protected]29672ab2009-10-30 03:44:03188 // Manager for desktop notification UI.
189 bool created_notification_ui_manager_;
190 scoped_ptr<NotificationUIManager> notification_ui_manager_;
191
[email protected]2e22e2f2012-03-15 21:53:10192#if defined(ENABLE_AUTOMATION)
initial.commit09911bf2008-07-26 23:55:29193 scoped_ptr<AutomationProviderList> automation_provider_list_;
[email protected]2e22e2f2012-03-15 21:53:10194#endif
initial.commit09911bf2008-07-26 23:55:29195
initial.commit09911bf2008-07-26 23:55:29196 scoped_ptr<GoogleURLTracker> google_url_tracker_;
[email protected]c4ff4952010-01-08 19:12:47197 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
initial.commit09911bf2008-07-26 23:55:29198
[email protected]0b4d3382010-07-14 16:13:04199 scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_;
200
[email protected]9e7f015f2011-05-28 00:24:25201 scoped_ptr<StatusTray> status_tray_;
202
[email protected]3ba226c52011-10-27 22:50:24203 scoped_ptr<BackgroundModeManager> background_mode_manager_;
204
[email protected]462a0ff2011-06-02 17:15:34205 bool created_safe_browsing_service_;
206 scoped_refptr<SafeBrowsingService> safe_browsing_service_;
207
initial.commit09911bf2008-07-26 23:55:29208 unsigned int module_ref_count_;
[email protected]afd20c022010-06-10 00:48:20209 bool did_start_;
initial.commit09911bf2008-07-26 23:55:29210
211 // Ensures that all the print jobs are finished before closing the browser.
212 scoped_ptr<printing::PrintJobManager> print_job_manager_;
213
[email protected]d70539de2009-06-24 22:17:06214 std::string locale_;
initial.commit09911bf2008-07-26 23:55:29215
[email protected]1b2db1a2008-08-08 17:46:13216 bool checked_for_new_frames_;
217 bool using_new_frames_;
218
[email protected]cb85aba2010-09-22 18:34:15219 // This service just sits around and makes thumbnails for tabs. It does
220 // nothing in the constructor so we don't have to worry about lazy init.
[email protected]7a0e72f2011-09-20 19:59:11221 scoped_ptr<ThumbnailGenerator> thumbnail_generator_;
[email protected]67a46b7f2009-06-16 21:41:02222
[email protected]073ed7b2010-09-27 09:20:02223 // Download status updates (like a changing application icon on dock/taskbar)
224 // are global per-application. DownloadStatusUpdater does no work in the ctor
225 // so we don't have to worry about lazy initialization.
[email protected]7a0e72f2011-09-20 19:59:11226 scoped_ptr<DownloadStatusUpdater> download_status_updater_;
[email protected]073ed7b2010-09-27 09:20:02227
[email protected]254ed742011-08-16 18:45:27228 scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
229
[email protected]2a7e7c152010-10-01 20:12:09230 // Ensures that the observers of plugin/print disable/enable state
[email protected]492d2142010-09-10 13:55:18231 // notifications are properly added and removed.
[email protected]2a7e7c152010-10-01 20:12:09232 PrefChangeRegistrar pref_change_registrar_;
[email protected]492d2142010-09-10 13:55:18233
[email protected]b2fcd0e2010-12-01 15:19:40234 // Lives here so can safely log events on shutdown.
235 scoped_ptr<ChromeNetLog> net_log_;
236
[email protected]8bcdf072011-06-03 16:52:15237 // Ordered before resource_dispatcher_host_delegate_ due to destruction
[email protected]1459fb62011-05-25 19:03:27238 // ordering.
239 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_;
240
[email protected]8bcdf072011-06-03 16:52:15241 scoped_ptr<ChromeResourceDispatcherHostDelegate>
242 resource_dispatcher_host_delegate_;
[email protected]1459fb62011-05-25 19:03:27243
[email protected]8b08a47f2011-02-25 12:36:37244 // Monitors the state of the 'DisablePluginFinder' policy.
[email protected]2e5b60a22011-11-28 15:56:41245 scoped_ptr<BooleanPrefMember> plugin_finder_disabled_pref_;
[email protected]8b08a47f2011-02-25 12:36:37246
[email protected]3cdacd42010-04-30 18:55:53247#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42248 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
249
250 // Gets called by autoupdate timer to see if browser needs restart and can be
251 // restarted, and if that's the case, restarts the browser.
252 void OnAutoupdateTimer();
253 bool CanAutorestartForUpdate() const;
[email protected]f6e6d2e2011-10-28 18:39:22254 void RestartBackgroundInstance();
[email protected]3cdacd42010-04-30 18:55:53255#endif // defined(OS_WIN) || defined(OS_LINUX)
[email protected]bd48c2b02010-04-09 20:32:42256
[email protected]db0e86dd2011-03-16 14:47:21257#if defined(OS_CHROMEOS)
[email protected]5b869962011-09-20 19:49:33258 scoped_ptr<browser::OomPriorityManager> oom_priority_manager_;
[email protected]db0e86dd2011-03-16 14:47:21259#endif
260
[email protected]c1adf5a2011-08-03 22:11:37261#if !defined(OS_CHROMEOS)
262 scoped_ptr<ComponentUpdateService> component_updater_;
[email protected]ca167a32011-09-30 15:19:11263
264 scoped_refptr<CRLSetFetcher> crl_set_fetcher_;
[email protected]c1adf5a2011-08-03 22:11:37265#endif
266
[email protected]6b4e6852012-02-14 04:02:48267 // TODO(eroman): Remove this when done debugging 113031. This tracks
268 // the callstack which released the final module reference count.
269 base::debug::StackTrace release_last_reference_callstack_;
270
[email protected]58dca552009-06-17 00:35:02271 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
initial.commit09911bf2008-07-26 23:55:29272};
273
[email protected]58dca552009-06-17 00:35:02274#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_