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 98 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 | 188 // How often to check if the persistent instance of Chrome needs to restart |
188 // to install an update. | 189 // to install an update. |
189 static const int kUpdateCheckIntervalHours = 6; | 190 static const int kUpdateCheckIntervalHours = 6; |
190 #endif | 191 #endif |
191 | 192 |
192 #if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE) | 193 #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 | 194 // 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 | 195 // 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 | 196 // messageloop and there's some deadlock risk. Our only option is to exit |
196 // anyway. | 197 // anyway. |
197 static const int kEndSessionTimeoutSeconds = 10; | 198 static constexpr base::TimeDelta kEndSessionTimeout = |
199 base::TimeDelta::FromSeconds(10); | |
198 #endif | 200 #endif |
199 | 201 |
200 using content::BrowserThread; | 202 using content::BrowserThread; |
201 using content::ChildProcessSecurityPolicy; | 203 using content::ChildProcessSecurityPolicy; |
202 using content::PluginService; | 204 using content::PluginService; |
203 using content::ResourceDispatcherHost; | 205 using content::ResourceDispatcherHost; |
204 | 206 |
205 rappor::RapporService* GetBrowserRapporService() { | 207 rappor::RapporService* GetBrowserRapporService() { |
206 if (g_browser_process != nullptr) | 208 if (g_browser_process != nullptr) |
207 return g_browser_process->rappor_service(); | 209 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); | 462 return waitable_event_.TimedWait(max_time); |
461 } | 463 } |
462 | 464 |
463 } // namespace | 465 } // namespace |
464 | 466 |
465 void BrowserProcessImpl::EndSession() { | 467 void BrowserProcessImpl::EndSession() { |
466 // Mark all the profiles as clean. | 468 // Mark all the profiles as clean. |
467 ProfileManager* pm = profile_manager(); | 469 ProfileManager* pm = profile_manager(); |
468 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); | 470 std::vector<Profile*> profiles(pm->GetLoadedProfiles()); |
469 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); | 471 scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); |
472 const bool pref_service_enabled = | |
473 base::FeatureList::IsEnabled(features::kPrefService); | |
474 std::vector<scoped_refptr<base::SequencedTaskRunner>> profile_writer_runners; | |
470 for (size_t i = 0; i < profiles.size(); ++i) { | 475 for (size_t i = 0; i < profiles.size(); ++i) { |
471 Profile* profile = profiles[i]; | 476 Profile* profile = profiles[i]; |
472 profile->SetExitType(Profile::EXIT_SESSION_ENDED); | 477 profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
473 if (profile->GetPrefs()) { | 478 if (profile->GetPrefs()) { |
474 profile->GetPrefs()->CommitPendingWrite(); | 479 profile->GetPrefs()->CommitPendingWrite(); |
475 rundown_counter->Post(profile->GetIOTaskRunner().get()); | 480 if (pref_service_enabled) { |
481 rundown_counter->Post(content::BrowserThread::GetTaskRunnerForThread( | |
482 content::BrowserThread::IO) | |
483 .get()); | |
484 profile_writer_runners.push_back(profile->GetIOTaskRunner()); | |
485 } else { | |
486 rundown_counter->Post(profile->GetIOTaskRunner().get()); | |
487 } | |
476 } | 488 } |
477 } | 489 } |
478 | 490 |
479 // Tell the metrics service it was cleanly shutdown. | 491 // Tell the metrics service it was cleanly shutdown. |
480 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 492 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
481 if (metrics && local_state()) { | 493 if (metrics && local_state()) { |
482 metrics->RecordStartOfSessionEnd(); | 494 metrics->RecordStartOfSessionEnd(); |
483 #if !defined(OS_CHROMEOS) | 495 #if !defined(OS_CHROMEOS) |
484 // MetricsService lazily writes to prefs, force it to write now. | 496 // MetricsService lazily writes to prefs, force it to write now. |
485 // On ChromeOS, chrome gets killed when hangs, so no need to | 497 // On ChromeOS, chrome gets killed when hangs, so no need to |
(...skipping 20 matching lines...) Expand all Loading... | |
506 // | 518 // |
507 // On Windows, we previously posted a message to FILE and then ran a nested | 519 // 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. | 520 // message loop, waiting for that message to be processed until quitting. |
509 // However, doing so means that other messages will also be processed. In | 521 // 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 | 522 // 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 | 523 // 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 | 524 // blocking the message loop attempting to re-establish a connection to the |
513 // GPU process synchronously. Because the system may not be allowing | 525 // GPU process synchronously. Because the system may not be allowing |
514 // processes to launch, this can result in a hang. See | 526 // processes to launch, this can result in a hang. See |
515 // http://crbug.com/318527. | 527 // http://crbug.com/318527. |
516 rundown_counter->TimedWait( | 528 base::Time start = base::Time::Now(); |
sky
2017/03/15 15:19:17
Use timeticks?
Sam McNally
2017/03/16 06:58:22
Done.
| |
517 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds)); | 529 if (rundown_counter->TimedWait(kEndSessionTimeout) && pref_service_enabled) { |
sky
2017/03/15 15:19:17
What does a return value of true mean for TimedWai
Sam McNally
2017/03/16 06:58:22
It returns whether everything finished before the
| |
530 scoped_refptr<RundownTaskCounter> profile_write_rundown_counter( | |
531 new RundownTaskCounter()); | |
532 for (auto& profile_writer_runner : profile_writer_runners) { | |
sky
2017/03/15 15:19:17
no {}
Sam McNally
2017/03/16 06:58:22
Done.
| |
533 profile_write_rundown_counter->Post(profile_writer_runner.get()); | |
534 } | |
535 profile_write_rundown_counter->TimedWait(kEndSessionTimeout - | |
sky
2017/03/15 15:19:17
Does RundownTaskCounter deal with potentially nega
Sam McNally
2017/03/16 06:58:22
I think it should, but I've changed it to take an
| |
536 (base::Time::Now() - start)); | |
537 } | |
518 #else | 538 #else |
519 NOTIMPLEMENTED(); | 539 NOTIMPLEMENTED(); |
520 #endif | 540 #endif |
521 } | 541 } |
522 | 542 |
523 metrics_services_manager::MetricsServicesManager* | 543 metrics_services_manager::MetricsServicesManager* |
524 BrowserProcessImpl::GetMetricsServicesManager() { | 544 BrowserProcessImpl::GetMetricsServicesManager() { |
525 DCHECK(CalledOnValidThread()); | 545 DCHECK(CalledOnValidThread()); |
526 if (!metrics_services_manager_) { | 546 if (!metrics_services_manager_) { |
527 metrics_services_manager_.reset( | 547 metrics_services_manager_.reset( |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1413 } | 1433 } |
1414 | 1434 |
1415 void BrowserProcessImpl::OnAutoupdateTimer() { | 1435 void BrowserProcessImpl::OnAutoupdateTimer() { |
1416 if (CanAutorestartForUpdate()) { | 1436 if (CanAutorestartForUpdate()) { |
1417 DLOG(WARNING) << "Detected update. Restarting browser."; | 1437 DLOG(WARNING) << "Detected update. Restarting browser."; |
1418 RestartBackgroundInstance(); | 1438 RestartBackgroundInstance(); |
1419 } | 1439 } |
1420 } | 1440 } |
1421 | 1441 |
1422 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1442 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
OLD | NEW |