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/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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) | 62 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) |
63 return false; | 63 return false; |
64 | 64 |
65 // Check TabsNeedBeforeUnloadFired(). | 65 // Check TabsNeedBeforeUnloadFired(). |
66 for (auto* browser : *BrowserList::GetInstance()) { | 66 for (auto* browser : *BrowserList::GetInstance()) { |
67 if (browser->TabsNeedBeforeUnloadFired()) | 67 if (browser->TabsNeedBeforeUnloadFired()) |
68 return false; | 68 return false; |
69 } | 69 } |
70 return true; | 70 return true; |
71 } | 71 } |
72 #endif // !defined(OS_ANDROID) | |
73 | 72 |
74 int g_keep_alive_count = 0; | 73 int g_keep_alive_count = 0; |
75 bool g_disable_shutdown_for_testing = false; | 74 bool g_disable_shutdown_for_testing = false; |
75 #endif // !defined(OS_ANDROID) | |
76 | 76 |
77 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
78 // Whether chrome should send stop request to a session manager. | 78 // Whether chrome should send stop request to a session manager. |
79 bool g_send_stop_request_to_session_manager = false; | 79 bool g_send_stop_request_to_session_manager = false; |
80 #endif | 80 #endif |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 void MarkAsCleanShutdown() { | 84 void MarkAsCleanShutdown() { |
85 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? | 85 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? |
86 for (auto* browser : *BrowserList::GetInstance()) | 86 for (auto* browser : *BrowserList::GetInstance()) |
87 browser->profile()->SetExitType(Profile::EXIT_NORMAL); | 87 browser->profile()->SetExitType(Profile::EXIT_NORMAL); |
88 } | 88 } |
89 | 89 |
90 void AttemptExitInternal(bool try_to_quit_application) { | 90 void AttemptExitInternal(bool try_to_quit_application) { |
91 // On Mac, the platform-specific part handles setting this. | 91 // On Mac, the platform-specific part handles setting this. |
92 #if !defined(OS_MACOSX) | 92 #if !defined(OS_MACOSX) |
93 if (try_to_quit_application) | 93 if (try_to_quit_application) |
94 browser_shutdown::SetTryingToQuit(true); | 94 browser_shutdown::SetTryingToQuit(true); |
95 #endif | 95 #endif |
96 | 96 |
97 content::NotificationService::current()->Notify( | 97 content::NotificationService::current()->Notify( |
98 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 98 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
99 content::NotificationService::AllSources(), | 99 content::NotificationService::AllSources(), |
100 content::NotificationService::NoDetails()); | 100 content::NotificationService::NoDetails()); |
101 | 101 |
102 g_browser_process->platform_part()->AttemptExit(); | 102 g_browser_process->platform_part()->AttemptExit(); |
103 } | 103 } |
104 | 104 |
105 #if !defined(OS_ANDROID) | |
105 void CloseAllBrowsersAndQuit() { | 106 void CloseAllBrowsersAndQuit() { |
106 browser_shutdown::SetTryingToQuit(true); | 107 browser_shutdown::SetTryingToQuit(true); |
107 CloseAllBrowsers(); | 108 CloseAllBrowsers(); |
108 } | 109 } |
109 | 110 |
110 void CloseAllBrowsers() { | 111 void CloseAllBrowsers() { |
111 // If there are no browsers and closing the last browser would quit the | 112 // If there are no browsers and closing the last browser would quit the |
112 // application, send the APP_TERMINATING action here. Otherwise, it will be | 113 // application, send the APP_TERMINATING action here. Otherwise, it will be |
113 // sent by RemoveBrowser() when the last browser has closed. | 114 // sent by RemoveBrowser() when the last browser has closed. |
114 if (chrome::GetTotalBrowserCount() == 0 && | 115 if (chrome::GetTotalBrowserCount() == 0 && |
(...skipping 14 matching lines...) Expand all Loading... | |
129 } | 130 } |
130 | 131 |
131 #if defined(OS_CHROMEOS) | 132 #if defined(OS_CHROMEOS) |
132 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( | 133 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( |
133 "StartedClosingWindows", false); | 134 "StartedClosingWindows", false); |
134 #endif | 135 #endif |
135 scoped_refptr<BrowserCloseManager> browser_close_manager = | 136 scoped_refptr<BrowserCloseManager> browser_close_manager = |
136 new BrowserCloseManager; | 137 new BrowserCloseManager; |
137 browser_close_manager->StartClosingBrowsers(); | 138 browser_close_manager->StartClosingBrowsers(); |
138 } | 139 } |
140 #endif | |
139 | 141 |
140 void AttemptUserExit() { | 142 void AttemptUserExit() { |
141 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
142 browser_shutdown::StartShutdownTracing(); | 144 browser_shutdown::StartShutdownTracing(); |
143 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted", | 145 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted", |
144 false); | 146 false); |
145 | 147 |
146 PrefService* state = g_browser_process->local_state(); | 148 PrefService* state = g_browser_process->local_state(); |
147 if (state) { | 149 if (state) { |
148 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state); | 150 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 // can be false in following cases. a) power-off b) signout from | 228 // can be false in following cases. a) power-off b) signout from |
227 // screen locker. | 229 // screen locker. |
228 if (!AreAllBrowsersCloseable()) | 230 if (!AreAllBrowsersCloseable()) |
229 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 231 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
230 else | 232 else |
231 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); | 233 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); |
232 AttemptExitInternal(true); | 234 AttemptExitInternal(true); |
233 } | 235 } |
234 #endif | 236 #endif |
235 | 237 |
238 #if !defined(OS_ANDROID) | |
236 void SessionEnding() { | 239 void SessionEnding() { |
237 // This is a time-limited shutdown where we need to write as much to | 240 // This is a time-limited shutdown where we need to write as much to |
238 // disk as we can as soon as we can, and where we must kill the | 241 // disk as we can as soon as we can, and where we must kill the |
239 // process within a hang timeout to avoid user prompts. | 242 // process within a hang timeout to avoid user prompts. |
240 | 243 |
241 // Start watching for hang during shutdown, and crash it if takes too long. | 244 // Start watching for hang during shutdown, and crash it if takes too long. |
242 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 245 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
243 // exit this function. | 246 // exit this function. |
244 ShutdownWatcherHelper shutdown_watcher; | 247 ShutdownWatcherHelper shutdown_watcher; |
245 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | 248 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // Allow the app to shutdown again. | 304 // Allow the app to shutdown again. |
302 if (!WillKeepAlive()) { | 305 if (!WillKeepAlive()) { |
303 g_browser_process->ReleaseModule(); | 306 g_browser_process->ReleaseModule(); |
304 CloseAllBrowsersIfNeeded(); | 307 CloseAllBrowsersIfNeeded(); |
305 } | 308 } |
306 } | 309 } |
307 | 310 |
308 bool WillKeepAlive() { | 311 bool WillKeepAlive() { |
309 return g_keep_alive_count > 0; | 312 return g_keep_alive_count > 0; |
310 } | 313 } |
314 #endif | |
Lei Zhang
2016/02/10 20:14:10
It would be nice to add // !defined(OS_ANDROID) be
tzik
2016/02/10 21:12:14
Done. (here and elsewhere)
| |
311 | 315 |
312 void NotifyAppTerminating() { | 316 void NotifyAppTerminating() { |
313 static bool notified = false; | 317 static bool notified = false; |
314 if (notified) | 318 if (notified) |
315 return; | 319 return; |
316 notified = true; | 320 notified = true; |
317 content::NotificationService::current()->Notify( | 321 content::NotificationService::current()->Notify( |
318 chrome::NOTIFICATION_APP_TERMINATING, | 322 chrome::NOTIFICATION_APP_TERMINATING, |
319 content::NotificationService::AllSources(), | 323 content::NotificationService::AllSources(), |
320 content::NotificationService::NoDetails()); | 324 content::NotificationService::NoDetails()); |
(...skipping 30 matching lines...) Expand all Loading... | |
351 if (g_send_stop_request_to_session_manager) { | 355 if (g_send_stop_request_to_session_manager) { |
352 // If running the Chrome OS build, but we're not on the device, act | 356 // If running the Chrome OS build, but we're not on the device, act |
353 // as if we received signal from SessionManager. | 357 // as if we received signal from SessionManager. |
354 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 358 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
355 base::Bind(&ExitCleanly)); | 359 base::Bind(&ExitCleanly)); |
356 } | 360 } |
357 } | 361 } |
358 #endif | 362 #endif |
359 } | 363 } |
360 | 364 |
365 #if !defined(OS_ANDROID) | |
361 void OnAppExiting() { | 366 void OnAppExiting() { |
362 static bool notified = false; | 367 static bool notified = false; |
363 if (notified) | 368 if (notified) |
364 return; | 369 return; |
365 notified = true; | 370 notified = true; |
366 HandleAppExitingForPlatform(); | 371 HandleAppExitingForPlatform(); |
367 } | 372 } |
368 | 373 |
369 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { | 374 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { |
370 g_disable_shutdown_for_testing = disable_shutdown_for_testing; | 375 g_disable_shutdown_for_testing = disable_shutdown_for_testing; |
371 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) | 376 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) |
372 CloseAllBrowsersIfNeeded(); | 377 CloseAllBrowsersIfNeeded(); |
373 } | 378 } |
379 #endif | |
374 | 380 |
375 } // namespace chrome | 381 } // namespace chrome |
OLD | NEW |