Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_shutdown.h" | 5 #include "chrome/browser/browser_shutdown.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/thread.h" | 18 #include "base/thread.h" |
| 19 #include "base/thread_restrictions.h" | 19 #include "base/thread_restrictions.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "chrome/browser/about_flags.h" | 22 #include "chrome/browser/about_flags.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/browser_thread.h" | 24 #include "chrome/browser/browser_thread.h" |
| 25 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 25 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 26 #include "chrome/browser/first_run/first_run.h" | 26 #include "chrome/browser/first_run/first_run.h" |
| 27 #include "chrome/browser/jankometer.h" | 27 #include "chrome/browser/jankometer.h" |
| 28 #include "chrome/browser/metrics/metrics_service.h" | 28 #include "chrome/browser/metrics/metrics_service.h" |
| 29 #include "chrome/browser/plugin_data_remover.h" | |
| 29 #include "chrome/browser/plugin_process_host.h" | 30 #include "chrome/browser/plugin_process_host.h" |
| 30 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
| 32 #include "chrome/browser/profile_manager.h" | |
| 31 #include "chrome/browser/renderer_host/render_process_host.h" | 33 #include "chrome/browser/renderer_host/render_process_host.h" |
| 32 #include "chrome/browser/renderer_host/render_view_host.h" | 34 #include "chrome/browser/renderer_host/render_view_host.h" |
| 33 #include "chrome/browser/renderer_host/render_widget_host.h" | 35 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 34 #include "chrome/browser/service/service_process_control_manager.h" | 36 #include "chrome/browser/service/service_process_control_manager.h" |
| 35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/chrome_plugin_lib.h" | 40 #include "chrome/common/chrome_plugin_lib.h" |
| 39 #include "chrome/common/switch_utils.h" | 41 #include "chrome/common/switch_utils.h" |
| 40 #include "net/predictor_api.h" | 42 #include "net/predictor_api.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
| 109 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker( | 111 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker( |
| 110 "BrowserShutdownStarted", false); | 112 "BrowserShutdownStarted", false); |
| 111 #endif | 113 #endif |
| 112 // During shutdown we will end up some blocking operations. But the | 114 // During shutdown we will end up some blocking operations. But the |
| 113 // work needs to get done and we're going to wait for them no matter | 115 // work needs to get done and we're going to wait for them no matter |
| 114 // what thread they're on, so don't worry about it slowing down | 116 // what thread they're on, so don't worry about it slowing down |
| 115 // shutdown. | 117 // shutdown. |
| 116 base::ThreadRestrictions::SetIOAllowed(true); | 118 base::ThreadRestrictions::SetIOAllowed(true); |
| 117 | 119 |
| 118 // Unload plugins. This needs to happen on the IO thread. | |
| 119 BrowserThread::PostTask( | |
| 120 BrowserThread::IO, FROM_HERE, | |
| 121 NewRunnableFunction(&ChromePluginLib::UnloadAllPlugins)); | |
| 122 | |
| 123 // Shutdown all IPC channels to service processes. | |
| 124 ServiceProcessControlManager::instance()->Shutdown(); | |
| 125 | |
| 126 // WARNING: During logoff/shutdown (WM_ENDSESSION) we may not have enough | 120 // WARNING: During logoff/shutdown (WM_ENDSESSION) we may not have enough |
| 127 // time to get here. If you have something that *must* happen on end session, | 121 // time to get here. If you have something that *must* happen on end session, |
| 128 // consider putting it in BrowserProcessImpl::EndSession. | 122 // consider putting it in BrowserProcessImpl::EndSession. |
| 129 DCHECK(g_browser_process); | 123 DCHECK(g_browser_process); |
| 130 | 124 |
| 131 // Notifies we are going away. | 125 // Notifies we are going away. |
| 132 g_browser_process->shutdown_event()->Signal(); | 126 g_browser_process->shutdown_event()->Signal(); |
| 133 | 127 |
| 134 PrefService* prefs = g_browser_process->local_state(); | 128 PrefService* local_state = g_browser_process->local_state(); |
| 135 | 129 |
| 136 chrome_browser_net::SavePredictorStateForNextStartupAndTrim(prefs); | 130 // Unload plugins. This needs to happen on the IO thread. |
| 131 BrowserThread::PostTask( | |
| 132 BrowserThread::IO, FROM_HERE, | |
| 133 NewRunnableFunction(&ChromePluginLib::UnloadAllPlugins)); | |
| 134 | |
| 135 Profile* profile = ProfileManager::GetDefaultProfile(); | |
| 136 if (profile) { | |
| 137 // Store the profile path for clearing local state data on exit. | |
| 138 PrefService* prefs = profile->GetPrefs(); | |
| 139 if (prefs->GetBoolean(prefs::kClearPluginLSODataOnExit) && | |
| 140 local_state->GetBoolean(prefs::kClearPluginLSODataEnabled)) { | |
| 141 PluginDataRemover remover; | |
| 142 remover.StartRemoving(base::Time(), new MessageLoop::QuitTask()); | |
|
jam
2010/11/29 17:14:08
I have a big concern about blocking our shutdown t
| |
| 143 MessageLoop::current()->Run(); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 // Shutdown all IPC channels to service processes. | |
| 148 ServiceProcessControlManager::instance()->Shutdown(); | |
| 149 | |
| 150 chrome_browser_net::SavePredictorStateForNextStartupAndTrim(local_state); | |
| 137 | 151 |
| 138 MetricsService* metrics = g_browser_process->metrics_service(); | 152 MetricsService* metrics = g_browser_process->metrics_service(); |
| 139 if (metrics) { | 153 if (metrics) { |
| 140 metrics->RecordCleanShutdown(); | 154 metrics->RecordCleanShutdown(); |
| 141 metrics->RecordCompletedSessionEnd(); | 155 metrics->RecordCompletedSessionEnd(); |
| 142 } | 156 } |
| 143 | 157 |
| 144 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { | 158 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { |
| 145 // Record the shutdown info so that we can put it into a histogram at next | 159 // Record the shutdown info so that we can put it into a histogram at next |
| 146 // startup. | 160 // startup. |
| 147 prefs->SetInteger(prefs::kShutdownType, shutdown_type_); | 161 local_state->SetInteger(prefs::kShutdownType, shutdown_type_); |
| 148 prefs->SetInteger(prefs::kShutdownNumProcesses, shutdown_num_processes_); | 162 local_state->SetInteger(prefs::kShutdownNumProcesses, |
| 149 prefs->SetInteger(prefs::kShutdownNumProcessesSlow, | 163 shutdown_num_processes_); |
| 150 shutdown_num_processes_slow_); | 164 local_state->SetInteger(prefs::kShutdownNumProcessesSlow, |
| 165 shutdown_num_processes_slow_); | |
| 151 } | 166 } |
| 152 | 167 |
| 153 // Check local state for the restart flag so we can restart the session below. | 168 // Check local state for the restart flag so we can restart the session below. |
| 154 bool restart_last_session = false; | 169 bool restart_last_session = false; |
| 155 if (prefs->HasPrefPath(prefs::kRestartLastSessionOnShutdown)) { | 170 if (local_state->HasPrefPath(prefs::kRestartLastSessionOnShutdown)) { |
| 156 restart_last_session = | 171 restart_last_session = |
| 157 prefs->GetBoolean(prefs::kRestartLastSessionOnShutdown); | 172 local_state->GetBoolean(prefs::kRestartLastSessionOnShutdown); |
| 158 prefs->ClearPref(prefs::kRestartLastSessionOnShutdown); | 173 local_state->ClearPref(prefs::kRestartLastSessionOnShutdown); |
| 159 } | 174 } |
| 160 | 175 |
| 161 prefs->SavePersistentPrefs(); | 176 local_state->SavePersistentPrefs(); |
| 162 | 177 |
| 163 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 178 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
| 164 // Cleanup any statics created by RLZ. Must be done before NotificationService | 179 // Cleanup any statics created by RLZ. Must be done before NotificationService |
| 165 // is destroyed. | 180 // is destroyed. |
| 166 RLZTracker::CleanupRlz(); | 181 RLZTracker::CleanupRlz(); |
| 167 #endif | 182 #endif |
| 168 | 183 |
| 169 // The jank'o'meter requires that the browser process has been destroyed | 184 // The jank'o'meter requires that the browser process has been destroyed |
| 170 // before calling UninstallJankometer(). | 185 // before calling UninstallJankometer(). |
| 171 delete g_browser_process; | 186 delete g_browser_process; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 334 |
| 320 bool ShuttingDownWithoutClosingBrowsers() { | 335 bool ShuttingDownWithoutClosingBrowsers() { |
| 321 #if defined(USE_X11) | 336 #if defined(USE_X11) |
| 322 if (GetShutdownType() == browser_shutdown::END_SESSION) | 337 if (GetShutdownType() == browser_shutdown::END_SESSION) |
| 323 return true; | 338 return true; |
| 324 #endif | 339 #endif |
| 325 return false; | 340 return false; |
| 326 } | 341 } |
| 327 | 342 |
| 328 } // namespace browser_shutdown | 343 } // namespace browser_shutdown |
| OLD | NEW |