| 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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 69 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 70 #include "chrome/browser/profiles/profile_manager.h" | 70 #include "chrome/browser/profiles/profile_manager.h" |
| 71 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 71 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 72 #include "chrome/browser/shell_integration.h" | 72 #include "chrome/browser/shell_integration.h" |
| 73 #include "chrome/browser/status_icons/status_tray.h" | 73 #include "chrome/browser/status_icons/status_tray.h" |
| 74 #include "chrome/browser/ui/browser_dialogs.h" | 74 #include "chrome/browser/ui/browser_dialogs.h" |
| 75 #include "chrome/browser/ui/browser_finder.h" | 75 #include "chrome/browser/ui/browser_finder.h" |
| 76 #include "chrome/browser/update_client/chrome_update_query_params_delegate.h" | 76 #include "chrome/browser/update_client/chrome_update_query_params_delegate.h" |
| 77 #include "chrome/common/channel_info.h" | 77 #include "chrome/common/channel_info.h" |
| 78 #include "chrome/common/chrome_constants.h" | 78 #include "chrome/common/chrome_constants.h" |
| 79 #include "chrome/common/chrome_features.h" |
| 79 #include "chrome/common/chrome_paths.h" | 80 #include "chrome/common/chrome_paths.h" |
| 80 #include "chrome/common/chrome_switches.h" | 81 #include "chrome/common/chrome_switches.h" |
| 81 #include "chrome/common/crash_keys.h" | 82 #include "chrome/common/crash_keys.h" |
| 82 #include "chrome/common/extensions/chrome_extensions_client.h" | 83 #include "chrome/common/extensions/chrome_extensions_client.h" |
| 83 #include "chrome/common/extensions/extension_process_policy.h" | 84 #include "chrome/common/extensions/extension_process_policy.h" |
| 84 #include "chrome/common/features.h" | 85 #include "chrome/common/features.h" |
| 85 #include "chrome/common/pref_names.h" | 86 #include "chrome/common/pref_names.h" |
| 86 #include "chrome/common/switch_utils.h" | 87 #include "chrome/common/switch_utils.h" |
| 87 #include "chrome/common/url_constants.h" | 88 #include "chrome/common/url_constants.h" |
| 88 #include "chrome/installer/util/google_update_constants.h" | 89 #include "chrome/installer/util/google_update_constants.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 #include "ui/message_center/message_center.h" | 133 #include "ui/message_center/message_center.h" |
| 133 | 134 |
| 134 #if defined(OS_WIN) | 135 #if defined(OS_WIN) |
| 135 #include "base/win/windows_version.h" | 136 #include "base/win/windows_version.h" |
| 136 #include "ui/views/focus/view_storage.h" | 137 #include "ui/views/focus/view_storage.h" |
| 137 #elif defined(OS_MACOSX) | 138 #elif defined(OS_MACOSX) |
| 138 #include "chrome/browser/chrome_browser_main_mac.h" | 139 #include "chrome/browser/chrome_browser_main_mac.h" |
| 139 #endif | 140 #endif |
| 140 | 141 |
| 141 #if !defined(OS_ANDROID) | 142 #if !defined(OS_ANDROID) |
| 143 #include "chrome/browser/features.h" |
| 142 #include "chrome/browser/gcm/gcm_product_util.h" | 144 #include "chrome/browser/gcm/gcm_product_util.h" |
| 143 #include "chrome/browser/lifetime/keep_alive_registry.h" | 145 #include "chrome/browser/lifetime/keep_alive_registry.h" |
| 144 #include "chrome/browser/ui/user_manager.h" | 146 #include "chrome/browser/ui/user_manager.h" |
| 145 #include "components/gcm_driver/gcm_client_factory.h" | 147 #include "components/gcm_driver/gcm_client_factory.h" |
| 146 #include "components/gcm_driver/gcm_desktop_utils.h" | 148 #include "components/gcm_driver/gcm_desktop_utils.h" |
| 147 #endif | 149 #endif |
| 148 | 150 |
| 149 #if BUILDFLAG(ENABLE_BACKGROUND) | 151 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 150 #include "chrome/browser/background/background_mode_manager.h" | 152 #include "chrome/browser/background/background_mode_manager.h" |
| 151 #endif | 153 #endif |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // How often to check if the persistent instance of Chrome needs to restart | 189 // How often to check if the persistent instance of Chrome needs to restart |
| 188 // to install an update. | 190 // to install an update. |
| 189 static const int kUpdateCheckIntervalHours = 6; | 191 static const int kUpdateCheckIntervalHours = 6; |
| 190 #endif | 192 #endif |
| 191 | 193 |
| 192 #if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE) | 194 #if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE) |
| 193 // How long to wait for the File thread to complete during EndSession, on Linux | 195 // How long to wait for the File thread to complete during EndSession, on Linux |
| 194 // and Windows. We have a timeout here because we're unable to run the UI | 196 // and Windows. We have a timeout here because we're unable to run the UI |
| 195 // messageloop and there's some deadlock risk. Our only option is to exit | 197 // messageloop and there's some deadlock risk. Our only option is to exit |
| 196 // anyway. | 198 // anyway. |
| 197 static const int kEndSessionTimeoutSeconds = 10; | 199 static constexpr base::TimeDelta kEndSessionTimeout = |
| 200 base::TimeDelta::FromSeconds(10); |
| 198 #endif | 201 #endif |
| 199 | 202 |
| 200 using content::BrowserThread; | 203 using content::BrowserThread; |
| 201 using content::ChildProcessSecurityPolicy; | 204 using content::ChildProcessSecurityPolicy; |
| 202 using content::PluginService; | 205 using content::PluginService; |
| 203 using content::ResourceDispatcherHost; | 206 using content::ResourceDispatcherHost; |
| 204 | 207 |
| 205 rappor::RapporService* GetBrowserRapporService() { | 208 rappor::RapporService* GetBrowserRapporService() { |
| 206 if (g_browser_process != nullptr) | 209 if (g_browser_process != nullptr) |
| 207 return g_browser_process->rappor_service(); | 210 return g_browser_process->rappor_service(); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return waitable_event_.TimedWait(max_time); | 463 return waitable_event_.TimedWait(max_time); |
| 461 } | 464 } |
| 462 | 465 |
| 463 } // namespace | 466 } // namespace |
| 464 | 467 |
| 465 void BrowserProcessImpl::EndSession() { | 468 void BrowserProcessImpl::EndSession() { |
| 466 // Mark all the profiles as clean. | 469 // Mark all the profiles as clean. |
| 467 ProfileManager* pm = profile_manager(); | 470 ProfileManager* pm = profile_manager(); |
| 468 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); | 471 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); |
| 469 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); | 472 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); |
| 473 const bool kEnablePrefService = |
| 474 base::FeatureList::IsEnabled(features::kPrefService); |
| 475 std::vector<scoped_refptr<base::SequencedTaskRunner>> profile_writer_runners; |
| 470 for (size_t i = 0; i < profiles.size(); ++i) { | 476 for (size_t i = 0; i < profiles.size(); ++i) { |
| 471 Profile* profile = profiles[i]; | 477 Profile* profile = profiles[i]; |
| 472 profile->SetExitType(Profile::EXIT_SESSION_ENDED); | 478 profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
| 473 if (profile->GetPrefs()) { | 479 if (profile->GetPrefs()) { |
| 474 profile->GetPrefs()->CommitPendingWrite(); | 480 profile->GetPrefs()->CommitPendingWrite(); |
| 475 rundown_counter->Post(profile->GetIOTaskRunner().get()); | 481 if (kEnablePrefService) { |
| 482 rundown_counter->Post(content::BrowserThread::GetTaskRunnerForThread( |
| 483 content::BrowserThread::IO) |
| 484 .get()); |
| 485 profile_writer_runners.push_back(profile->GetIOTaskRunner()); |
| 486 } else { |
| 487 rundown_counter->Post(profile->GetIOTaskRunner().get()); |
| 488 } |
| 476 } | 489 } |
| 477 } | 490 } |
| 478 | 491 |
| 479 // Tell the metrics service it was cleanly shutdown. | 492 // Tell the metrics service it was cleanly shutdown. |
| 480 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 493 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 481 if (metrics && local_state()) { | 494 if (metrics && local_state()) { |
| 482 metrics->RecordStartOfSessionEnd(); | 495 metrics->RecordStartOfSessionEnd(); |
| 483 #if !defined(OS_CHROMEOS) | 496 #if !defined(OS_CHROMEOS) |
| 484 // MetricsService lazily writes to prefs, force it to write now. | 497 // MetricsService lazily writes to prefs, force it to write now. |
| 485 // On ChromeOS, chrome gets killed when hangs, so no need to | 498 // On ChromeOS, chrome gets killed when hangs, so no need to |
| (...skipping 20 matching lines...) Expand all Loading... |
| 506 // | 519 // |
| 507 // On Windows, we previously posted a message to FILE and then ran a nested | 520 // On Windows, we previously posted a message to FILE and then ran a nested |
| 508 // message loop, waiting for that message to be processed until quitting. | 521 // message loop, waiting for that message to be processed until quitting. |
| 509 // However, doing so means that other messages will also be processed. In | 522 // However, doing so means that other messages will also be processed. In |
| 510 // particular, if the GPU process host notices that the GPU has been killed | 523 // particular, if the GPU process host notices that the GPU has been killed |
| 511 // during shutdown, it races exiting the nested loop with the process host | 524 // during shutdown, it races exiting the nested loop with the process host |
| 512 // blocking the message loop attempting to re-establish a connection to the | 525 // blocking the message loop attempting to re-establish a connection to the |
| 513 // GPU process synchronously. Because the system may not be allowing | 526 // GPU process synchronously. Because the system may not be allowing |
| 514 // processes to launch, this can result in a hang. See | 527 // processes to launch, this can result in a hang. See |
| 515 // http://crbug.com/318527. | 528 // http://crbug.com/318527. |
| 516 rundown_counter->TimedWait( | 529 base::Time start = base::Time::Now(); |
| 517 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds)); | 530 if (rundown_counter->TimedWait(kEndSessionTimeout) && kEnablePrefService) { |
| 531 scoped_refptr<RundownTaskCounter> profile_write_rundown_counter( |
| 532 new RundownTaskCounter()); |
| 533 for (auto& profile_writer_runner : profile_writer_runners) { |
| 534 profile_write_rundown_counter->Post(profile_writer_runner.get()); |
| 535 } |
| 536 profile_write_rundown_counter->TimedWait(kEndSessionTimeout - |
| 537 (base::Time::Now() - start)); |
| 538 } |
| 518 #else | 539 #else |
| 519 NOTIMPLEMENTED(); | 540 NOTIMPLEMENTED(); |
| 520 #endif | 541 #endif |
| 521 } | 542 } |
| 522 | 543 |
| 523 metrics_services_manager::MetricsServicesManager* | 544 metrics_services_manager::MetricsServicesManager* |
| 524 BrowserProcessImpl::GetMetricsServicesManager() { | 545 BrowserProcessImpl::GetMetricsServicesManager() { |
| 525 DCHECK(CalledOnValidThread()); | 546 DCHECK(CalledOnValidThread()); |
| 526 if (!metrics_services_manager_) { | 547 if (!metrics_services_manager_) { |
| 527 metrics_services_manager_.reset( | 548 metrics_services_manager_.reset( |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 #if defined(LEAK_SANITIZER) | 1359 #if defined(LEAK_SANITIZER) |
| 1339 // Check for memory leaks now, before we start shutting down threads. Doing | 1360 // Check for memory leaks now, before we start shutting down threads. Doing |
| 1340 // this early means we won't report any shutdown-only leaks (as they have | 1361 // this early means we won't report any shutdown-only leaks (as they have |
| 1341 // not yet happened at this point). | 1362 // not yet happened at this point). |
| 1342 // If leaks are found, this will make the process exit immediately. | 1363 // If leaks are found, this will make the process exit immediately. |
| 1343 __lsan_do_leak_check(); | 1364 __lsan_do_leak_check(); |
| 1344 #endif | 1365 #endif |
| 1345 | 1366 |
| 1346 CHECK(base::MessageLoop::current()->is_running()); | 1367 CHECK(base::MessageLoop::current()->is_running()); |
| 1347 | 1368 |
| 1369 if (base::FeatureList::IsEnabled(features::kPrefService)) { |
| 1370 bool fast_shutdown_enabled = |
| 1371 #if !defined(OS_ANDROID) |
| 1372 base::FeatureList::IsEnabled(features::kDesktopFastShutdown); |
| 1373 #else |
| 1374 false; |
| 1375 #endif |
| 1376 for (auto* profile : profile_manager()->GetLoadedProfiles()) { |
| 1377 profile->SetExitType(fast_shutdown_enabled ? Profile::EXIT_SESSION_ENDED |
| 1378 : Profile::EXIT_NORMAL); |
| 1379 } |
| 1380 } |
| 1381 |
| 1348 #if defined(OS_MACOSX) | 1382 #if defined(OS_MACOSX) |
| 1349 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1383 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1350 FROM_HERE, base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); | 1384 FROM_HERE, base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); |
| 1351 #endif | 1385 #endif |
| 1352 base::MessageLoop::current()->QuitWhenIdle(); | 1386 base::MessageLoop::current()->QuitWhenIdle(); |
| 1353 | 1387 |
| 1354 #if !defined(OS_ANDROID) | 1388 #if !defined(OS_ANDROID) |
| 1355 chrome::ShutdownIfNeeded(); | 1389 chrome::ShutdownIfNeeded(); |
| 1356 #endif // !defined(OS_ANDROID) | 1390 #endif // !defined(OS_ANDROID) |
| 1357 } | 1391 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 } | 1447 } |
| 1414 | 1448 |
| 1415 void BrowserProcessImpl::OnAutoupdateTimer() { | 1449 void BrowserProcessImpl::OnAutoupdateTimer() { |
| 1416 if (CanAutorestartForUpdate()) { | 1450 if (CanAutorestartForUpdate()) { |
| 1417 DLOG(WARNING) << "Detected update. Restarting browser."; | 1451 DLOG(WARNING) << "Detected update. Restarting browser."; |
| 1418 RestartBackgroundInstance(); | 1452 RestartBackgroundInstance(); |
| 1419 } | 1453 } |
| 1420 } | 1454 } |
| 1421 | 1455 |
| 1422 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1456 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| OLD | NEW |