Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser_process_impl.h" | 5 #include "chrome/browser/browser_process_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "chrome/browser/devtools/devtools_auto_opener.h" | 39 #include "chrome/browser/devtools/devtools_auto_opener.h" |
| 40 #include "chrome/browser/devtools/remote_debugging_server.h" | 40 #include "chrome/browser/devtools/remote_debugging_server.h" |
| 41 #include "chrome/browser/download/download_request_limiter.h" | 41 #include "chrome/browser/download/download_request_limiter.h" |
| 42 #include "chrome/browser/download/download_status_updater.h" | 42 #include "chrome/browser/download/download_status_updater.h" |
| 43 #include "chrome/browser/gpu/gl_string_manager.h" | 43 #include "chrome/browser/gpu/gl_string_manager.h" |
| 44 #include "chrome/browser/gpu/gpu_mode_manager.h" | 44 #include "chrome/browser/gpu/gpu_mode_manager.h" |
| 45 #include "chrome/browser/icon_manager.h" | 45 #include "chrome/browser/icon_manager.h" |
| 46 #include "chrome/browser/intranet_redirect_detector.h" | 46 #include "chrome/browser/intranet_redirect_detector.h" |
| 47 #include "chrome/browser/io_thread.h" | 47 #include "chrome/browser/io_thread.h" |
| 48 #include "chrome/browser/lifetime/application_lifetime.h" | 48 #include "chrome/browser/lifetime/application_lifetime.h" |
| 49 #include "chrome/browser/lifetime/keep_alive_registry.h" | |
| 50 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 49 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 51 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h" | 50 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h" |
| 52 #include "chrome/browser/metrics/thread_watcher.h" | 51 #include "chrome/browser/metrics/thread_watcher.h" |
| 53 #include "chrome/browser/net/chrome_net_log_helper.h" | 52 #include "chrome/browser/net/chrome_net_log_helper.h" |
| 54 #include "chrome/browser/net/crl_set_fetcher.h" | 53 #include "chrome/browser/net/crl_set_fetcher.h" |
| 55 #include "chrome/browser/notifications/notification_ui_manager.h" | 54 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 56 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 55 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 57 #include "chrome/browser/plugins/plugin_finder.h" | 56 #include "chrome/browser/plugins/plugin_finder.h" |
| 58 #include "chrome/browser/prefs/browser_prefs.h" | 57 #include "chrome/browser/prefs/browser_prefs.h" |
| 59 #include "chrome/browser/prefs/chrome_pref_service_factory.h" | 58 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 114 |
| 116 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
| 117 #include "base/win/windows_version.h" | 116 #include "base/win/windows_version.h" |
| 118 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" | 117 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" |
| 119 #include "ui/views/focus/view_storage.h" | 118 #include "ui/views/focus/view_storage.h" |
| 120 #elif defined(OS_MACOSX) | 119 #elif defined(OS_MACOSX) |
| 121 #include "chrome/browser/chrome_browser_main_mac.h" | 120 #include "chrome/browser/chrome_browser_main_mac.h" |
| 122 #endif | 121 #endif |
| 123 | 122 |
| 124 #if !defined(OS_ANDROID) | 123 #if !defined(OS_ANDROID) |
| 124 #include "chrome/browser/lifetime/keep_alive_registry.h" | |
| 125 #include "chrome/browser/ui/user_manager.h" | 125 #include "chrome/browser/ui/user_manager.h" |
| 126 #include "components/gcm_driver/gcm_client_factory.h" | 126 #include "components/gcm_driver/gcm_client_factory.h" |
| 127 #include "components/gcm_driver/gcm_desktop_utils.h" | 127 #include "components/gcm_driver/gcm_desktop_utils.h" |
| 128 #endif | 128 #endif |
| 129 | 129 |
| 130 #if BUILDFLAG(ENABLE_BACKGROUND) | 130 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 131 #include "chrome/browser/background/background_mode_manager.h" | 131 #include "chrome/browser/background/background_mode_manager.h" |
| 132 #endif | 132 #endif |
| 133 | 133 |
| 134 #if defined(ENABLE_EXTENSIONS) | 134 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 BrowserProcessImpl::BrowserProcessImpl( | 183 BrowserProcessImpl::BrowserProcessImpl( |
| 184 base::SequencedTaskRunner* local_state_task_runner, | 184 base::SequencedTaskRunner* local_state_task_runner, |
| 185 const base::CommandLine& command_line) | 185 const base::CommandLine& command_line) |
| 186 : created_watchdog_thread_(false), | 186 : created_watchdog_thread_(false), |
| 187 created_browser_policy_connector_(false), | 187 created_browser_policy_connector_(false), |
| 188 created_profile_manager_(false), | 188 created_profile_manager_(false), |
| 189 created_local_state_(false), | 189 created_local_state_(false), |
| 190 created_icon_manager_(false), | 190 created_icon_manager_(false), |
| 191 created_notification_ui_manager_(false), | 191 created_notification_ui_manager_(false), |
| 192 created_safe_browsing_service_(false), | 192 created_safe_browsing_service_(false), |
| 193 module_ref_count_(0), | 193 shutting_down_(false), |
| 194 did_start_(false), | |
| 195 tearing_down_(false), | 194 tearing_down_(false), |
| 196 download_status_updater_(new DownloadStatusUpdater), | 195 download_status_updater_(new DownloadStatusUpdater), |
| 197 local_state_task_runner_(local_state_task_runner), | 196 local_state_task_runner_(local_state_task_runner), |
| 198 cached_default_web_client_state_(shell_integration::UNKNOWN_DEFAULT) { | 197 cached_default_web_client_state_(shell_integration::UNKNOWN_DEFAULT) { |
| 199 g_browser_process = this; | 198 g_browser_process = this; |
| 200 platform_part_.reset(new BrowserProcessPlatformPart()); | 199 platform_part_.reset(new BrowserProcessPlatformPart()); |
| 201 | 200 |
| 202 #if defined(ENABLE_PRINTING) | 201 #if defined(ENABLE_PRINTING) |
| 203 // Must be created after the NotificationService. | 202 // Must be created after the NotificationService. |
| 204 print_job_manager_.reset(new printing::PrintJobManager); | 203 print_job_manager_.reset(new printing::PrintJobManager); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 235 |
| 237 extensions_browser_client_.reset( | 236 extensions_browser_client_.reset( |
| 238 new extensions::ChromeExtensionsBrowserClient); | 237 new extensions::ChromeExtensionsBrowserClient); |
| 239 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); | 238 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); |
| 240 #endif | 239 #endif |
| 241 | 240 |
| 242 message_center::MessageCenter::Initialize(); | 241 message_center::MessageCenter::Initialize(); |
| 243 | 242 |
| 244 update_client::UpdateQueryParams::SetDelegate( | 243 update_client::UpdateQueryParams::SetDelegate( |
| 245 ChromeUpdateQueryParamsDelegate::GetInstance()); | 244 ChromeUpdateQueryParamsDelegate::GetInstance()); |
| 245 | |
| 246 #if !defined(OS_ANDROID) | |
| 247 KeepAliveRegistry::GetInstance()->AddObserver(this); | |
| 248 #endif // !defined(OS_ANDROID) | |
| 246 } | 249 } |
| 247 | 250 |
| 248 BrowserProcessImpl::~BrowserProcessImpl() { | 251 BrowserProcessImpl::~BrowserProcessImpl() { |
| 252 #if !defined(OS_ANDROID) | |
| 253 KeepAliveRegistry::GetInstance()->RemoveObserver(this); | |
| 254 #endif // !defined(OS_ANDROID) | |
| 255 | |
| 249 tracked_objects::ThreadData::EnsureCleanupWasCalled(4); | 256 tracked_objects::ThreadData::EnsureCleanupWasCalled(4); |
| 250 | 257 |
| 251 g_browser_process = NULL; | 258 g_browser_process = NULL; |
| 252 } | 259 } |
| 253 | 260 |
| 254 #if !defined(OS_ANDROID) | 261 #if !defined(OS_ANDROID) |
| 255 void BrowserProcessImpl::StartTearDown() { | 262 void BrowserProcessImpl::StartTearDown() { |
| 256 TRACE_EVENT0("shutdown", "BrowserProcessImpl::StartTearDown"); | 263 TRACE_EVENT0("shutdown", "BrowserProcessImpl::StartTearDown"); |
| 257 // TODO(crbug.com/560486): Fix the tests that make the check of | 264 // TODO(crbug.com/560486): Fix the tests that make the check of |
| 258 // |tearing_down_| necessary in IsShuttingDown(). | 265 // |tearing_down_| necessary in IsShuttingDown(). |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 // as io_thread_.global_ cleanup happens in CleanUp on the IO | 362 // as io_thread_.global_ cleanup happens in CleanUp on the IO |
| 356 // thread, i.e. as the thread exits its message loop. | 363 // thread, i.e. as the thread exits its message loop. |
| 357 // | 364 // |
| 358 // This is important also because in various places, the | 365 // This is important also because in various places, the |
| 359 // IOThread object being NULL is considered synonymous with the | 366 // IOThread object being NULL is considered synonymous with the |
| 360 // IO thread having stopped. | 367 // IO thread having stopped. |
| 361 io_thread_.reset(); | 368 io_thread_.reset(); |
| 362 } | 369 } |
| 363 #endif // !defined(OS_ANDROID) | 370 #endif // !defined(OS_ANDROID) |
| 364 | 371 |
| 365 unsigned int BrowserProcessImpl::AddRefModule() { | 372 void BrowserProcessImpl::Pin() { |
| 366 DCHECK(CalledOnValidThread()); | 373 DCHECK(CalledOnValidThread()); |
| 367 | 374 |
| 368 // CHECK(!IsShuttingDown()); | 375 // CHECK(!IsShuttingDown()); |
| 369 if (IsShuttingDown()) { | 376 if (IsShuttingDown()) { |
| 370 // Copy the stacktrace which released the final reference onto our stack so | 377 // Copy the stacktrace which released the final reference onto our stack so |
| 371 // it will be available in the crash report for inspection. | 378 // it will be available in the crash report for inspection. |
| 372 base::debug::StackTrace callstack = release_last_reference_callstack_; | 379 base::debug::StackTrace callstack = release_last_reference_callstack_; |
| 373 base::debug::Alias(&callstack); | 380 base::debug::Alias(&callstack); |
| 374 CHECK(false); | 381 CHECK(false); |
| 375 } | 382 } |
| 376 | |
| 377 did_start_ = true; | |
| 378 module_ref_count_++; | |
| 379 return module_ref_count_; | |
| 380 } | 383 } |
| 381 | 384 |
| 382 unsigned int BrowserProcessImpl::ReleaseModule() { | 385 void BrowserProcessImpl::Unpin() { |
| 383 DCHECK(CalledOnValidThread()); | 386 DCHECK(CalledOnValidThread()); |
| 384 DCHECK_NE(0u, module_ref_count_); | 387 release_last_reference_callstack_ = base::debug::StackTrace(); |
| 385 module_ref_count_--; | |
| 386 if (0 == module_ref_count_) { | |
| 387 release_last_reference_callstack_ = base::debug::StackTrace(); | |
| 388 | 388 |
| 389 shutting_down_ = true; | |
| 389 #if defined(ENABLE_PRINTING) | 390 #if defined(ENABLE_PRINTING) |
| 390 // Wait for the pending print jobs to finish. Don't do this later, since | 391 // Wait for the pending print jobs to finish. Don't do this later, since |
| 391 // this might cause a nested message loop to run, and we don't want pending | 392 // this might cause a nested message loop to run, and we don't want pending |
| 392 // tasks to run once teardown has started. | 393 // tasks to run once teardown has started. |
| 393 print_job_manager_->Shutdown(); | 394 print_job_manager_->Shutdown(); |
| 394 #endif | 395 #endif |
| 395 | 396 |
| 396 #if defined(LEAK_SANITIZER) | 397 #if defined(LEAK_SANITIZER) |
| 397 // Check for memory leaks now, before we start shutting down threads. Doing | 398 // Check for memory leaks now, before we start shutting down threads. Doing |
| 398 // this early means we won't report any shutdown-only leaks (as they have | 399 // this early means we won't report any shutdown-only leaks (as they have |
| 399 // not yet happened at this point). | 400 // not yet happened at this point). |
| 400 // If leaks are found, this will make the process exit immediately. | 401 // If leaks are found, this will make the process exit immediately. |
| 401 __lsan_do_leak_check(); | 402 __lsan_do_leak_check(); |
| 402 #endif | 403 #endif |
| 403 | 404 |
| 404 CHECK(base::MessageLoop::current()->is_running()); | 405 CHECK(base::MessageLoop::current()->is_running()); |
| 405 | 406 |
| 406 #if defined(OS_MACOSX) | 407 #if defined(OS_MACOSX) |
| 407 base::MessageLoop::current()->PostTask( | 408 base::MessageLoop::current()->PostTask( |
| 408 FROM_HERE, | 409 FROM_HERE, base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); |
| 409 base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); | |
| 410 #endif | 410 #endif |
| 411 base::MessageLoop::current()->QuitWhenIdle(); | 411 base::MessageLoop::current()->QuitWhenIdle(); |
| 412 } | 412 |
| 413 return module_ref_count_; | 413 #if !defined(OS_ANDROID) |
| 414 chrome::ShutdownIfNeeded(); | |
| 415 #endif // !defined(OS_ANDROID) | |
| 414 } | 416 } |
| 415 | 417 |
| 416 namespace { | 418 namespace { |
| 417 | 419 |
| 418 // Used at the end of session to block the UI thread for completion of sentinel | 420 // Used at the end of session to block the UI thread for completion of sentinel |
| 419 // tasks on the set of threads used to persist profile data and local state. | 421 // tasks on the set of threads used to persist profile data and local state. |
| 420 // This is done to ensure that the data has been persisted to disk before | 422 // This is done to ensure that the data has been persisted to disk before |
| 421 // continuing. | 423 // continuing. |
| 422 class RundownTaskCounter : | 424 class RundownTaskCounter : |
| 423 public base::RefCountedThreadSafe<RundownTaskCounter> { | 425 public base::RefCountedThreadSafe<RundownTaskCounter> { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 // is started with several profiles or existing browser process is reused. | 684 // is started with several profiles or existing browser process is reused. |
| 683 if (!devtools_auto_opener_.get()) | 685 if (!devtools_auto_opener_.get()) |
| 684 devtools_auto_opener_.reset(new DevToolsAutoOpener()); | 686 devtools_auto_opener_.reset(new DevToolsAutoOpener()); |
| 685 #endif | 687 #endif |
| 686 } | 688 } |
| 687 | 689 |
| 688 bool BrowserProcessImpl::IsShuttingDown() { | 690 bool BrowserProcessImpl::IsShuttingDown() { |
| 689 DCHECK(CalledOnValidThread()); | 691 DCHECK(CalledOnValidThread()); |
| 690 // TODO(crbug.com/560486): Fix the tests that make the check of | 692 // TODO(crbug.com/560486): Fix the tests that make the check of |
| 691 // |tearing_down_| necessary here. | 693 // |tearing_down_| necessary here. |
| 692 return (did_start_ && 0 == module_ref_count_) || tearing_down_; | 694 return shutting_down_ || tearing_down_; |
| 693 } | 695 } |
| 694 | 696 |
| 695 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { | 697 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { |
| 696 DCHECK(CalledOnValidThread()); | 698 DCHECK(CalledOnValidThread()); |
| 697 return print_job_manager_.get(); | 699 return print_job_manager_.get(); |
| 698 } | 700 } |
| 699 | 701 |
| 700 printing::PrintPreviewDialogController* | 702 printing::PrintPreviewDialogController* |
| 701 BrowserProcessImpl::print_preview_dialog_controller() { | 703 BrowserProcessImpl::print_preview_dialog_controller() { |
| 702 #if defined(ENABLE_PRINT_PREVIEW) | 704 #if defined(ENABLE_PRINT_PREVIEW) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 ResourceDispatcherHost::Get()->SetDelegate( | 971 ResourceDispatcherHost::Get()->SetDelegate( |
| 970 resource_dispatcher_host_delegate_.get()); | 972 resource_dispatcher_host_delegate_.get()); |
| 971 | 973 |
| 972 pref_change_registrar_.Add( | 974 pref_change_registrar_.Add( |
| 973 prefs::kAllowCrossOriginAuthPrompt, | 975 prefs::kAllowCrossOriginAuthPrompt, |
| 974 base::Bind(&BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy, | 976 base::Bind(&BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy, |
| 975 base::Unretained(this))); | 977 base::Unretained(this))); |
| 976 ApplyAllowCrossOriginAuthPromptPolicy(); | 978 ApplyAllowCrossOriginAuthPromptPolicy(); |
| 977 } | 979 } |
| 978 | 980 |
| 981 void BrowserProcessImpl::OnKeepingAliveStateChanged(bool is_keeping_alive) { | |
|
sky
2016/03/17 00:02:24
Did you make sure we don't unnecessary call this q
dgn
2016/03/17 10:00:08
Which case are you referring to? In the normal sta
| |
| 982 if (is_keeping_alive) | |
| 983 Pin(); | |
| 984 else | |
| 985 Unpin(); | |
| 986 }; | |
|
sky
2016/03/17 00:02:24
nit: no {}
dgn
2016/03/17 10:00:08
Do you mean no semicolon? Or no brackets on same l
| |
| 987 | |
| 988 void BrowserProcessImpl::OnKeepAliveRestartStateChanged(bool can_restart){}; | |
| 989 | |
| 979 void BrowserProcessImpl::CreateWatchdogThread() { | 990 void BrowserProcessImpl::CreateWatchdogThread() { |
| 980 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL); | 991 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL); |
| 981 created_watchdog_thread_ = true; | 992 created_watchdog_thread_ = true; |
| 982 | 993 |
| 983 scoped_ptr<WatchDogThread> thread(new WatchDogThread()); | 994 scoped_ptr<WatchDogThread> thread(new WatchDogThread()); |
| 984 base::Thread::Options options; | 995 base::Thread::Options options; |
| 985 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 996 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 986 if (!thread->StartWithOptions(options)) | 997 if (!thread->StartWithOptions(options)) |
| 987 return; | 998 return; |
| 988 watchdog_thread_.swap(thread); | 999 watchdog_thread_.swap(thread); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 } | 1306 } |
| 1296 | 1307 |
| 1297 void BrowserProcessImpl::OnAutoupdateTimer() { | 1308 void BrowserProcessImpl::OnAutoupdateTimer() { |
| 1298 if (CanAutorestartForUpdate()) { | 1309 if (CanAutorestartForUpdate()) { |
| 1299 DLOG(WARNING) << "Detected update. Restarting browser."; | 1310 DLOG(WARNING) << "Detected update. Restarting browser."; |
| 1300 RestartBackgroundInstance(); | 1311 RestartBackgroundInstance(); |
| 1301 } | 1312 } |
| 1302 } | 1313 } |
| 1303 | 1314 |
| 1304 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1315 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| OLD | NEW |