Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/lifetime/application_lifetime.cc

Issue 1388303002: Move assorted function in application_lifetime to where they are used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/lifetime/application_lifetime.h" 5 #include "chrome/browser/lifetime/application_lifetime.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
13 #include "base/process/process.h" 12 #include "base/process/process.h"
14 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
15 #include "base/trace_event/trace_event.h"
16 #include "build/build_config.h" 14 #include "build/build_config.h"
17 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browser_process_platform_part.h" 16 #include "chrome/browser/browser_process_platform_part.h"
19 #include "chrome/browser/browser_shutdown.h" 17 #include "chrome/browser/browser_shutdown.h"
20 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/download/download_service.h" 19 #include "chrome/browser/download/download_service.h"
22 #include "chrome/browser/lifetime/browser_close_manager.h" 20 #include "chrome/browser/lifetime/browser_close_manager.h"
23 #include "chrome/browser/metrics/thread_watcher.h" 21 #include "chrome/browser/metrics/thread_watcher.h"
24 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_iterator.h" 26 #include "chrome/browser/ui/browser_iterator.h"
29 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
30 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/browser/ui/user_manager.h" 30 #include "chrome/browser/ui/user_manager.h"
33 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
34 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
36 #include "components/tracing/tracing_switches.h"
37 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/navigation_details.h" 34 #include "content/public/browser/navigation_details.h"
39 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
40 36
41 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
42 #include "base/sys_info.h" 38 #include "base/sys_info.h"
43 #include "chrome/browser/chromeos/boot_times_recorder.h" 39 #include "chrome/browser/chromeos/boot_times_recorder.h"
44 #include "chromeos/dbus/dbus_thread_manager.h" 40 #include "chromeos/dbus/dbus_thread_manager.h"
45 #include "chromeos/dbus/session_manager_client.h" 41 #include "chromeos/dbus/session_manager_client.h"
46 #include "chromeos/dbus/update_engine_client.h" 42 #include "chromeos/dbus/update_engine_client.h"
47 #endif 43 #endif
48 44
49 #if defined(OS_WIN) 45 #if defined(OS_WIN)
50 #include "base/win/win_util.h" 46 #include "base/win/win_util.h"
51 #endif 47 #endif
52 48
53 #if defined(USE_ASH)
54 #include "ash/shell.h"
55 #endif
56
57 namespace chrome { 49 namespace chrome {
58 namespace { 50 namespace {
59 51
60 #if !defined(OS_ANDROID) 52 #if !defined(OS_ANDROID)
61 // Returns true if all browsers can be closed without user interaction. 53 // Returns true if all browsers can be closed without user interaction.
62 // This currently checks if there is pending download, or if it needs to 54 // This currently checks if there is pending download, or if it needs to
63 // handle unload handler. 55 // handle unload handler.
64 bool AreAllBrowsersCloseable() { 56 bool AreAllBrowsersCloseable() {
65 chrome::BrowserIterator browser_it; 57 chrome::BrowserIterator browser_it;
66 if (browser_it.done()) 58 if (browser_it.done())
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( 133 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker(
142 "StartedClosingWindows", false); 134 "StartedClosingWindows", false);
143 #endif 135 #endif
144 scoped_refptr<BrowserCloseManager> browser_close_manager = 136 scoped_refptr<BrowserCloseManager> browser_close_manager =
145 new BrowserCloseManager; 137 new BrowserCloseManager;
146 browser_close_manager->StartClosingBrowsers(); 138 browser_close_manager->StartClosingBrowsers();
147 } 139 }
148 140
149 void AttemptUserExit() { 141 void AttemptUserExit() {
150 #if defined(OS_CHROMEOS) 142 #if defined(OS_CHROMEOS)
151 StartShutdownTracing(); 143 browser_shutdown::StartShutdownTracing();
152 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted", 144 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted",
153 false); 145 false);
154 146
155 PrefService* state = g_browser_process->local_state(); 147 PrefService* state = g_browser_process->local_state();
156 if (state) { 148 if (state) {
157 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state); 149 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state);
158 150
159 // Login screen should show up in owner's locale. 151 // Login screen should show up in owner's locale.
160 std::string owner_locale = state->GetString(prefs::kOwnerLocale); 152 std::string owner_locale = state->GetString(prefs::kOwnerLocale);
161 if (!owner_locale.empty() && 153 if (!owner_locale.empty() &&
(...skipping 11 matching lines...) Expand all
173 #else 165 #else
174 // Reset the restart bit that might have been set in cancelled restart 166 // Reset the restart bit that might have been set in cancelled restart
175 // request. 167 // request.
176 UserManager::Hide(); 168 UserManager::Hide();
177 PrefService* pref_service = g_browser_process->local_state(); 169 PrefService* pref_service = g_browser_process->local_state();
178 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); 170 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false);
179 AttemptExitInternal(false); 171 AttemptExitInternal(false);
180 #endif 172 #endif
181 } 173 }
182 174
183 void StartShutdownTracing() {
184 const base::CommandLine& command_line =
185 *base::CommandLine::ForCurrentProcess();
186 if (command_line.HasSwitch(switches::kTraceShutdown)) {
187 base::trace_event::TraceConfig trace_config(
188 command_line.GetSwitchValueASCII(switches::kTraceShutdown), "");
189 base::trace_event::TraceLog::GetInstance()->SetEnabled(
190 trace_config,
191 base::trace_event::TraceLog::RECORDING_MODE);
192 }
193 TRACE_EVENT0("shutdown", "StartShutdownTracing");
194 }
195
196 // The Android implementation is in application_lifetime_android.cc 175 // The Android implementation is in application_lifetime_android.cc
197 #if !defined(OS_ANDROID) 176 #if !defined(OS_ANDROID)
198 void AttemptRestart() { 177 void AttemptRestart() {
199 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? 178 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead?
200 for (chrome::BrowserIterator it; !it.done(); it.Next()) 179 for (chrome::BrowserIterator it; !it.done(); it.Next())
201 content::BrowserContext::SaveSessionState(it->profile()); 180 content::BrowserContext::SaveSessionState(it->profile());
202 181
203 PrefService* pref_service = g_browser_process->local_state(); 182 PrefService* pref_service = g_browser_process->local_state();
204 pref_service->SetBoolean(prefs::kWasRestarted, true); 183 pref_service->SetBoolean(prefs::kWasRestarted, true);
205 184
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 360 }
382 361
383 void OnAppExiting() { 362 void OnAppExiting() {
384 static bool notified = false; 363 static bool notified = false;
385 if (notified) 364 if (notified)
386 return; 365 return;
387 notified = true; 366 notified = true;
388 HandleAppExitingForPlatform(); 367 HandleAppExitingForPlatform();
389 } 368 }
390 369
391 bool ShouldStartShutdown(Browser* browser) {
392 if (BrowserList::GetInstance(browser->host_desktop_type())->size() > 1)
393 return false;
394 #if defined(OS_WIN)
395 // On Windows 8 the desktop and ASH environments could be active
396 // at the same time.
397 // We should not start the shutdown process in the following cases:-
398 // 1. If the desktop type of the browser going away is ASH and there
399 // are browser windows open in the desktop.
400 // 2. If the desktop type of the browser going away is desktop and the ASH
401 // environment is still active.
402 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE)
403 return !ash::Shell::HasInstance();
404 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
405 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty();
406 #endif
407 return true;
408 }
409
410 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { 370 void DisableShutdownForTesting(bool disable_shutdown_for_testing) {
411 g_disable_shutdown_for_testing = disable_shutdown_for_testing; 371 g_disable_shutdown_for_testing = disable_shutdown_for_testing;
412 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) 372 if (!g_disable_shutdown_for_testing && !WillKeepAlive())
413 CloseAllBrowsersIfNeeded(); 373 CloseAllBrowsersIfNeeded();
414 } 374 }
415 375
416 } // namespace chrome 376 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698