Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 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/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/histogram.h" | 12 #include "base/histogram.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/thread.h" | 15 #include "base/thread.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/waitable_event.h" | 17 #include "base/waitable_event.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chrome_thread.h" | 20 #include "chrome/browser/chrome_thread.h" |
| 21 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 21 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 22 #include "chrome/browser/first_run.h" | 22 #include "chrome/browser/first_run.h" |
| 23 #include "chrome/browser/jankometer.h" | 23 #include "chrome/browser/jankometer.h" |
| 24 #include "chrome/browser/metrics/metrics_service.h" | 24 #include "chrome/browser/metrics/metrics_service.h" |
| 25 #include "chrome/browser/plugin_process_host.h" | 25 #include "chrome/browser/plugin_process_host.h" |
| 26 #include "chrome/browser/pref_service.h" | 26 #include "chrome/browser/pref_service.h" |
| 27 #include "chrome/browser/renderer_host/render_process_host.h" | 27 #include "chrome/browser/renderer_host/render_process_host.h" |
| 28 #include "chrome/browser/renderer_host/render_view_host.h" | 28 #include "chrome/browser/renderer_host/render_view_host.h" |
| 29 #include "chrome/browser/renderer_host/render_widget_host.h" | 29 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/chrome_switches.h" | |
| 31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/chrome_plugin_lib.h" | 33 #include "chrome/common/chrome_plugin_lib.h" |
| 33 #include "net/dns_global.h" | 34 #include "net/dns_global.h" |
| 34 | 35 |
| 35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 36 #include "chrome/browser/rlz/rlz.h" | 37 #include "chrome/browser/rlz/rlz.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 using base::Time; | 40 using base::Time; |
| 40 using base::TimeDelta; | 41 using base::TimeDelta; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 122 |
| 122 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { | 123 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { |
| 123 // Record the shutdown info so that we can put it into a histogram at next | 124 // Record the shutdown info so that we can put it into a histogram at next |
| 124 // startup. | 125 // startup. |
| 125 prefs->SetInteger(prefs::kShutdownType, shutdown_type_); | 126 prefs->SetInteger(prefs::kShutdownType, shutdown_type_); |
| 126 prefs->SetInteger(prefs::kShutdownNumProcesses, shutdown_num_processes_); | 127 prefs->SetInteger(prefs::kShutdownNumProcesses, shutdown_num_processes_); |
| 127 prefs->SetInteger(prefs::kShutdownNumProcessesSlow, | 128 prefs->SetInteger(prefs::kShutdownNumProcessesSlow, |
| 128 shutdown_num_processes_slow_); | 129 shutdown_num_processes_slow_); |
| 129 } | 130 } |
| 130 | 131 |
| 132 // Check local state for the restart flag so we can restart the session below. | |
| 133 bool restart_last_session = false; | |
| 134 if (prefs->HasPrefPath(prefs::kRestartLastSessionOnShutdown)) { | |
| 135 restart_last_session = | |
| 136 prefs->GetBoolean(prefs::kRestartLastSessionOnShutdown); | |
| 137 prefs->ClearPref(prefs::kRestartLastSessionOnShutdown); | |
| 138 } | |
| 139 | |
| 131 prefs->SavePersistentPrefs(); | 140 prefs->SavePersistentPrefs(); |
| 132 | 141 |
| 133 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
| 134 // Cleanup any statics created by RLZ. Must be done before NotificationService | 143 // Cleanup any statics created by RLZ. Must be done before NotificationService |
| 135 // is destroyed. | 144 // is destroyed. |
| 136 RLZTracker::CleanupRlz(); | 145 RLZTracker::CleanupRlz(); |
| 137 #endif | 146 #endif |
| 138 | 147 |
| 139 // The jank'o'meter requires that the browser process has been destroyed | 148 // The jank'o'meter requires that the browser process has been destroyed |
| 140 // before calling UninstallJankometer(). | 149 // before calling UninstallJankometer(). |
| 141 delete g_browser_process; | 150 delete g_browser_process; |
| 142 g_browser_process = NULL; | 151 g_browser_process = NULL; |
| 143 | 152 |
| 144 // Uninstall Jank-O-Meter here after the IO thread is no longer running. | 153 // Uninstall Jank-O-Meter here after the IO thread is no longer running. |
| 145 UninstallJankometer(); | 154 UninstallJankometer(); |
| 146 | 155 |
| 147 if (delete_resources_on_shutdown) | 156 if (delete_resources_on_shutdown) |
| 148 ResourceBundle::CleanupSharedInstance(); | 157 ResourceBundle::CleanupSharedInstance(); |
| 149 | 158 |
| 150 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 151 if (!Upgrade::IsBrowserAlreadyRunning() && | 160 if (!Upgrade::IsBrowserAlreadyRunning() && |
| 152 shutdown_type_ != browser_shutdown::END_SESSION) { | 161 shutdown_type_ != browser_shutdown::END_SESSION) { |
| 153 Upgrade::SwapNewChromeExeIfPresent(); | 162 Upgrade::SwapNewChromeExeIfPresent(); |
| 154 } | 163 } |
| 164 | |
| 165 if (restart_last_session) { | |
| 166 // Make sure to relaunch the browser with the same command line and add | |
| 167 // Restore Last Session flag if session restore is not set. | |
| 168 CommandLine command_line = CommandLine::FromString( | |
| 169 CommandLine::ForCurrentProcess()->command_line_string()); | |
| 170 if (!command_line.HasSwitch(switches::kRestoreLastSession)) | |
| 171 command_line.AppendSwitch(switches::kRestoreLastSession); | |
| 172 Upgrade::RelaunchChromeBrowser(command_line); | |
|
Nico
2010/08/27 05:14:09
Isn't this very racy? RelaunchChromeBrowser() most
Nico
2010/08/27 05:17:15
This might be the cause for http://crbug.com/50803
| |
| 173 } | |
| 174 #endif | |
| 175 #if !defined(OS_WIN) | |
| 176 if (restart_last_session) | |
| 177 NOTIMPLEMENTED(); | |
| 155 #endif | 178 #endif |
| 156 | 179 |
| 157 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { | 180 if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) { |
| 158 // Measure total shutdown time as late in the process as possible | 181 // Measure total shutdown time as late in the process as possible |
| 159 // and then write it to a file to be read at startup. | 182 // and then write it to a file to be read at startup. |
| 160 // We can't use prefs since all services are shutdown at this point. | 183 // We can't use prefs since all services are shutdown at this point. |
| 161 TimeDelta shutdown_delta = Time::Now() - shutdown_started_; | 184 TimeDelta shutdown_delta = Time::Now() - shutdown_started_; |
| 162 std::string shutdown_ms = Int64ToString(shutdown_delta.InMilliseconds()); | 185 std::string shutdown_ms = Int64ToString(shutdown_delta.InMilliseconds()); |
| 163 int len = static_cast<int>(shutdown_ms.length()) + 1; | 186 int len = static_cast<int>(shutdown_ms.length()) + 1; |
| 164 FilePath shutdown_ms_file = GetShutdownMsPath(); | 187 FilePath shutdown_ms_file = GetShutdownMsPath(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 void SetTryingToQuit(bool quitting) { | 258 void SetTryingToQuit(bool quitting) { |
| 236 g_trying_to_quit = quitting; | 259 g_trying_to_quit = quitting; |
| 237 } | 260 } |
| 238 | 261 |
| 239 bool IsTryingToQuit() { | 262 bool IsTryingToQuit() { |
| 240 return g_trying_to_quit; | 263 return g_trying_to_quit; |
| 241 } | 264 } |
| 242 #endif | 265 #endif |
| 243 | 266 |
| 244 } // namespace browser_shutdown | 267 } // namespace browser_shutdown |
| OLD | NEW |