| 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 172 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // as io_thread_.global_ cleanup happens in CleanUp on the IO | 354 // as io_thread_.global_ cleanup happens in CleanUp on the IO |
| 356 // thread, i.e. as the thread exits its message loop. | 355 // thread, i.e. as the thread exits its message loop. |
| 357 // | 356 // |
| 358 // This is important also because in various places, the | 357 // This is important also because in various places, the |
| 359 // IOThread object being NULL is considered synonymous with the | 358 // IOThread object being NULL is considered synonymous with the |
| 360 // IO thread having stopped. | 359 // IO thread having stopped. |
| 361 io_thread_.reset(); | 360 io_thread_.reset(); |
| 362 } | 361 } |
| 363 #endif // !defined(OS_ANDROID) | 362 #endif // !defined(OS_ANDROID) |
| 364 | 363 |
| 365 unsigned int BrowserProcessImpl::AddRefModule() { | 364 void BrowserProcessImpl::Pin() { |
| 366 DCHECK(CalledOnValidThread()); | 365 DCHECK(CalledOnValidThread()); |
| 367 | 366 |
| 368 // CHECK(!IsShuttingDown()); | 367 // CHECK(!IsShuttingDown()); |
| 369 if (IsShuttingDown()) { | 368 if (IsShuttingDown()) { |
| 370 // Copy the stacktrace which released the final reference onto our stack so | 369 // Copy the stacktrace which released the final reference onto our stack so |
| 371 // it will be available in the crash report for inspection. | 370 // it will be available in the crash report for inspection. |
| 372 base::debug::StackTrace callstack = release_last_reference_callstack_; | 371 base::debug::StackTrace callstack = release_last_reference_callstack_; |
| 373 base::debug::Alias(&callstack); | 372 base::debug::Alias(&callstack); |
| 374 CHECK(false); | 373 CHECK(false); |
| 375 } | 374 } |
| 376 | |
| 377 did_start_ = true; | |
| 378 module_ref_count_++; | |
| 379 return module_ref_count_; | |
| 380 } | 375 } |
| 381 | 376 |
| 382 unsigned int BrowserProcessImpl::ReleaseModule() { | 377 void BrowserProcessImpl::Unpin() { |
| 383 DCHECK(CalledOnValidThread()); | 378 DCHECK(CalledOnValidThread()); |
| 384 DCHECK_NE(0u, module_ref_count_); | 379 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 | 380 |
| 381 shutting_down_ = true; |
| 389 #if defined(ENABLE_PRINTING) | 382 #if defined(ENABLE_PRINTING) |
| 390 // Wait for the pending print jobs to finish. Don't do this later, since | 383 // 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 | 384 // this might cause a nested message loop to run, and we don't want pending |
| 392 // tasks to run once teardown has started. | 385 // tasks to run once teardown has started. |
| 393 print_job_manager_->Shutdown(); | 386 print_job_manager_->Shutdown(); |
| 394 #endif | 387 #endif |
| 395 | 388 |
| 396 #if defined(LEAK_SANITIZER) | 389 #if defined(LEAK_SANITIZER) |
| 397 // Check for memory leaks now, before we start shutting down threads. Doing | 390 // 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 | 391 // this early means we won't report any shutdown-only leaks (as they have |
| 399 // not yet happened at this point). | 392 // not yet happened at this point). |
| 400 // If leaks are found, this will make the process exit immediately. | 393 // If leaks are found, this will make the process exit immediately. |
| 401 __lsan_do_leak_check(); | 394 __lsan_do_leak_check(); |
| 402 #endif | 395 #endif |
| 403 | 396 |
| 404 CHECK(base::MessageLoop::current()->is_running()); | 397 CHECK(base::MessageLoop::current()->is_running()); |
| 405 | 398 |
| 406 #if defined(OS_MACOSX) | 399 #if defined(OS_MACOSX) |
| 407 base::MessageLoop::current()->PostTask( | 400 base::MessageLoop::current()->PostTask( |
| 408 FROM_HERE, | 401 FROM_HERE, base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); |
| 409 base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); | |
| 410 #endif | 402 #endif |
| 411 base::MessageLoop::current()->QuitWhenIdle(); | 403 base::MessageLoop::current()->QuitWhenIdle(); |
| 412 } | |
| 413 return module_ref_count_; | |
| 414 } | 404 } |
| 415 | 405 |
| 416 namespace { | 406 namespace { |
| 417 | 407 |
| 418 // Used at the end of session to block the UI thread for completion of sentinel | 408 // 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. | 409 // 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 | 410 // This is done to ensure that the data has been persisted to disk before |
| 421 // continuing. | 411 // continuing. |
| 422 class RundownTaskCounter : | 412 class RundownTaskCounter : |
| 423 public base::RefCountedThreadSafe<RundownTaskCounter> { | 413 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. | 672 // is started with several profiles or existing browser process is reused. |
| 683 if (!devtools_auto_opener_.get()) | 673 if (!devtools_auto_opener_.get()) |
| 684 devtools_auto_opener_.reset(new DevToolsAutoOpener()); | 674 devtools_auto_opener_.reset(new DevToolsAutoOpener()); |
| 685 #endif | 675 #endif |
| 686 } | 676 } |
| 687 | 677 |
| 688 bool BrowserProcessImpl::IsShuttingDown() { | 678 bool BrowserProcessImpl::IsShuttingDown() { |
| 689 DCHECK(CalledOnValidThread()); | 679 DCHECK(CalledOnValidThread()); |
| 690 // TODO(crbug.com/560486): Fix the tests that make the check of | 680 // TODO(crbug.com/560486): Fix the tests that make the check of |
| 691 // |tearing_down_| necessary here. | 681 // |tearing_down_| necessary here. |
| 692 return (did_start_ && 0 == module_ref_count_) || tearing_down_; | 682 return shutting_down_ || tearing_down_; |
| 693 } | 683 } |
| 694 | 684 |
| 695 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { | 685 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { |
| 696 DCHECK(CalledOnValidThread()); | 686 DCHECK(CalledOnValidThread()); |
| 697 return print_job_manager_.get(); | 687 return print_job_manager_.get(); |
| 698 } | 688 } |
| 699 | 689 |
| 700 printing::PrintPreviewDialogController* | 690 printing::PrintPreviewDialogController* |
| 701 BrowserProcessImpl::print_preview_dialog_controller() { | 691 BrowserProcessImpl::print_preview_dialog_controller() { |
| 702 #if defined(ENABLE_PRINT_PREVIEW) | 692 #if defined(ENABLE_PRINT_PREVIEW) |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 } | 1285 } |
| 1296 | 1286 |
| 1297 void BrowserProcessImpl::OnAutoupdateTimer() { | 1287 void BrowserProcessImpl::OnAutoupdateTimer() { |
| 1298 if (CanAutorestartForUpdate()) { | 1288 if (CanAutorestartForUpdate()) { |
| 1299 DLOG(WARNING) << "Detected update. Restarting browser."; | 1289 DLOG(WARNING) << "Detected update. Restarting browser."; |
| 1300 RestartBackgroundInstance(); | 1290 RestartBackgroundInstance(); |
| 1301 } | 1291 } |
| 1302 } | 1292 } |
| 1303 | 1293 |
| 1304 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1294 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| OLD | NEW |