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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
13 #include "chrome/browser/download/download_service.h" | 13 #include "chrome/browser/download/download_service.h" |
14 #include "chrome/browser/metrics/thread_watcher.h" | 14 #include "chrome/browser/metrics/thread_watcher.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_iterator.h" |
19 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "content/public/browser/browser_shutdown.h" | 27 #include "content/public/browser/browser_shutdown.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
(...skipping 16 matching lines...) Expand all Loading... |
45 #include "chromeos/dbus/update_engine_client.h" | 46 #include "chromeos/dbus/update_engine_client.h" |
46 #endif | 47 #endif |
47 | 48 |
48 namespace browser { | 49 namespace browser { |
49 namespace { | 50 namespace { |
50 | 51 |
51 // Returns true if all browsers can be closed without user interaction. | 52 // Returns true if all browsers can be closed without user interaction. |
52 // This currently checks if there is pending download, or if it needs to | 53 // This currently checks if there is pending download, or if it needs to |
53 // handle unload handler. | 54 // handle unload handler. |
54 bool AreAllBrowsersCloseable() { | 55 bool AreAllBrowsersCloseable() { |
55 BrowserList::const_iterator browser_it = BrowserList::begin(); | 56 chrome::BrowserIterator browser_it; |
56 if (browser_it == BrowserList::end()) | 57 if (browser_it.done()) |
57 return true; | 58 return true; |
58 | 59 |
59 // If there are any downloads active, all browsers are not closeable. | 60 // If there are any downloads active, all browsers are not closeable. |
60 if (DownloadService::DownloadCountAllProfiles() > 0) | 61 if (DownloadService::DownloadCountAllProfiles() > 0) |
61 return false; | 62 return false; |
62 | 63 |
63 // Check TabsNeedBeforeUnloadFired(). | 64 // Check TabsNeedBeforeUnloadFired(). |
64 for (; browser_it != BrowserList::end(); ++browser_it) { | 65 for (; !browser_it.done(); browser_it.Next()) { |
65 if ((*browser_it)->TabsNeedBeforeUnloadFired()) | 66 if (browser_it->TabsNeedBeforeUnloadFired()) |
66 return false; | 67 return false; |
67 } | 68 } |
68 return true; | 69 return true; |
69 } | 70 } |
70 | 71 |
71 int g_keep_alive_count = 0; | 72 int g_keep_alive_count = 0; |
72 | 73 |
73 #if defined(OS_CHROMEOS) | 74 #if defined(OS_CHROMEOS) |
74 // Whether a session manager requested to shutdown. | 75 // Whether a session manager requested to shutdown. |
75 bool g_session_manager_requested_shutdown = true; | 76 bool g_session_manager_requested_shutdown = true; |
76 #endif | 77 #endif |
77 | 78 |
78 } // namespace | 79 } // namespace |
79 | 80 |
80 void MarkAsCleanShutdown() { | 81 void MarkAsCleanShutdown() { |
81 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? | 82 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? |
82 for (BrowserList::const_iterator i = BrowserList::begin(); | 83 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
83 i != BrowserList::end(); ++i) { | 84 it->profile()->SetExitType(Profile::EXIT_NORMAL); |
84 (*i)->profile()->SetExitType(Profile::EXIT_NORMAL); | |
85 } | |
86 } | 85 } |
87 | 86 |
88 void AttemptExitInternal() { | 87 void AttemptExitInternal() { |
89 content::NotificationService::current()->Notify( | 88 content::NotificationService::current()->Notify( |
90 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 89 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
91 content::NotificationService::AllSources(), | 90 content::NotificationService::AllSources(), |
92 content::NotificationService::NoDetails()); | 91 content::NotificationService::NoDetails()); |
93 | 92 |
94 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
95 // Tell the Java code to finish() the Activity. | 94 // Tell the Java code to finish() the Activity. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 PrefService* pref_service = g_browser_process->local_state(); | 185 PrefService* pref_service = g_browser_process->local_state(); |
187 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 186 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
188 AttemptExitInternal(); | 187 AttemptExitInternal(); |
189 #endif | 188 #endif |
190 } | 189 } |
191 | 190 |
192 // The Android implementation is in application_lifetime_android.cc | 191 // The Android implementation is in application_lifetime_android.cc |
193 #if !defined(OS_ANDROID) | 192 #if !defined(OS_ANDROID) |
194 void AttemptRestart() { | 193 void AttemptRestart() { |
195 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 194 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
196 BrowserList::const_iterator it; | 195 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
197 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) | 196 content::BrowserContext::SaveSessionState(it->profile()); |
198 content::BrowserContext::SaveSessionState((*it)->profile()); | |
199 | 197 |
200 PrefService* pref_service = g_browser_process->local_state(); | 198 PrefService* pref_service = g_browser_process->local_state(); |
201 pref_service->SetBoolean(prefs::kWasRestarted, true); | 199 pref_service->SetBoolean(prefs::kWasRestarted, true); |
202 | 200 |
203 #if defined(OS_CHROMEOS) | 201 #if defined(OS_CHROMEOS) |
204 // For CrOS instead of browser restart (which is not supported) perform a full | 202 // For CrOS instead of browser restart (which is not supported) perform a full |
205 // sign out. Session will be only restored if user has that setting set. | 203 // sign out. Session will be only restored if user has that setting set. |
206 // Same session restore behavior happens in case of full restart after update. | 204 // Same session restore behavior happens in case of full restart after update. |
207 AttemptUserExit(); | 205 AttemptUserExit(); |
208 #else | 206 #else |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 378 |
381 void OnAppExiting() { | 379 void OnAppExiting() { |
382 static bool notified = false; | 380 static bool notified = false; |
383 if (notified) | 381 if (notified) |
384 return; | 382 return; |
385 notified = true; | 383 notified = true; |
386 HandleAppExitingForPlatform(); | 384 HandleAppExitingForPlatform(); |
387 } | 385 } |
388 | 386 |
389 } // namespace chrome | 387 } // namespace chrome |
OLD | NEW |