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 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "chrome/browser/background/background_application_list_model.h" | 12 #include "chrome/browser/background/background_application_list_model.h" |
13 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 13 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
14 #include "chrome/browser/status_icons/status_icon.h" | 14 #include "chrome/browser/status_icons/status_icon.h" |
15 #include "chrome/browser/status_icons/status_icon_menu_model.h" | 15 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
| 16 #include "chrome/browser/ui/browser_list_observer.h" |
16 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
19 | 20 |
20 class Browser; | 21 class Browser; |
21 class CommandLine; | 22 class CommandLine; |
22 class PrefRegistrySimple; | 23 class PrefRegistrySimple; |
23 class Profile; | 24 class Profile; |
24 class ProfileInfoCache; | 25 class ProfileInfoCache; |
25 class StatusIcon; | 26 class StatusIcon; |
(...skipping 12 matching lines...) Expand all Loading... |
38 // installed/loaded extensions to ensure that Chrome enters/exits background | 39 // installed/loaded extensions to ensure that Chrome enters/exits background |
39 // mode at the appropriate time. | 40 // mode at the appropriate time. |
40 // | 41 // |
41 // When Chrome is in background mode, it will continue running even after the | 42 // When Chrome is in background mode, it will continue running even after the |
42 // last browser window is closed, until the user explicitly exits the app. | 43 // last browser window is closed, until the user explicitly exits the app. |
43 // Additionally, when in background mode, Chrome will launch on OS login with | 44 // Additionally, when in background mode, Chrome will launch on OS login with |
44 // no open windows to allow apps with the "background" permission to run in the | 45 // no open windows to allow apps with the "background" permission to run in the |
45 // background. | 46 // background. |
46 class BackgroundModeManager | 47 class BackgroundModeManager |
47 : public content::NotificationObserver, | 48 : public content::NotificationObserver, |
| 49 public chrome::BrowserListObserver, |
48 public BackgroundApplicationListModel::Observer, | 50 public BackgroundApplicationListModel::Observer, |
49 public ProfileInfoCacheObserver, | 51 public ProfileInfoCacheObserver, |
50 public StatusIconMenuModel::Delegate { | 52 public StatusIconMenuModel::Delegate { |
51 public: | 53 public: |
52 BackgroundModeManager(CommandLine* command_line, | 54 BackgroundModeManager(CommandLine* command_line, |
53 ProfileInfoCache* profile_cache); | 55 ProfileInfoCache* profile_cache); |
54 virtual ~BackgroundModeManager(); | 56 virtual ~BackgroundModeManager(); |
55 | 57 |
56 static void RegisterPrefs(PrefRegistrySimple* registry); | 58 static void RegisterPrefs(PrefRegistrySimple* registry); |
57 | 59 |
58 virtual void RegisterProfile(Profile* profile); | 60 virtual void RegisterProfile(Profile* profile); |
59 | 61 |
60 static void LaunchBackgroundApplication(Profile* profile, | 62 static void LaunchBackgroundApplication(Profile* profile, |
61 const extensions::Extension* extension); | 63 const extensions::Extension* extension); |
62 | 64 |
63 // Returns true if background mode is active. | 65 // Returns true if background mode is active. |
64 virtual bool IsBackgroundModeActive(); | 66 virtual bool IsBackgroundModeActive(); |
65 | 67 |
| 68 // Suspends background mode until either ResumeBackgroundMode is called or |
| 69 // Chrome is restarted. This has the same effect as ending background mode |
| 70 // for the current browser session. |
| 71 virtual void SuspendBackgroundMode(); |
| 72 |
| 73 // Resumes background mode. This ends a suspension of background mode, but |
| 74 // will not start it if it is not enabled. |
| 75 virtual void ResumeBackgroundMode(); |
| 76 |
66 // For testing purposes. | 77 // For testing purposes. |
67 int NumberOfBackgroundModeData(); | 78 int NumberOfBackgroundModeData(); |
68 | 79 |
69 private: | 80 private: |
70 friend class AppBackgroundPageApiTest; | 81 friend class AppBackgroundPageApiTest; |
71 friend class BackgroundModeManagerTest; | 82 friend class BackgroundModeManagerTest; |
72 friend class TestBackgroundModeManager; | 83 friend class TestBackgroundModeManager; |
73 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 84 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
74 BackgroundAppLoadUnload); | 85 BackgroundAppLoadUnload); |
75 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 86 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Overrides from ProfileInfoCacheObserver | 180 // Overrides from ProfileInfoCacheObserver |
170 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE; | 181 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE; |
171 virtual void OnProfileWillBeRemoved( | 182 virtual void OnProfileWillBeRemoved( |
172 const base::FilePath& profile_path) OVERRIDE; | 183 const base::FilePath& profile_path) OVERRIDE; |
173 virtual void OnProfileNameChanged(const base::FilePath& profile_path, | 184 virtual void OnProfileNameChanged(const base::FilePath& profile_path, |
174 const string16& old_profile_name) OVERRIDE; | 185 const string16& old_profile_name) OVERRIDE; |
175 | 186 |
176 // Overrides from StatusIconMenuModel::Delegate implementation. | 187 // Overrides from StatusIconMenuModel::Delegate implementation. |
177 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 188 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
178 | 189 |
| 190 // chrome::BrowserListObserver implementation. |
| 191 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 192 |
179 // Invoked when an extension is installed so we can ensure that | 193 // Invoked when an extension is installed so we can ensure that |
180 // launch-on-startup is enabled if appropriate. |extension| can be NULL when | 194 // launch-on-startup is enabled if appropriate. |extension| can be NULL when |
181 // called from unit tests. | 195 // called from unit tests. |
182 void OnBackgroundAppInstalled( | 196 void OnBackgroundAppInstalled( |
183 const extensions::Extension* extension); | 197 const extensions::Extension* extension); |
184 | 198 |
185 // Walk the list of profiles and see if an extension or app is being | 199 // Walk the list of profiles and see if an extension or app is being |
186 // currently upgraded or reloaded by any profile. If so, update the | 200 // currently upgraded or reloaded by any profile. If so, update the |
187 // output variables appropriately. | 201 // output variables appropriately. |
188 void CheckReloadStatus( | 202 void CheckReloadStatus( |
189 const extensions::Extension* extension, | 203 const extensions::Extension* extension, |
190 bool* is_being_reloaded); | 204 bool* is_being_reloaded); |
191 | 205 |
192 // Called to make sure that our launch-on-startup mode is properly set. | 206 // Called to make sure that our launch-on-startup mode is properly set. |
193 // (virtual so we can override for tests). | 207 // (virtual so we can override for tests). |
194 virtual void EnableLaunchOnStartup(bool should_launch); | 208 virtual void EnableLaunchOnStartup(bool should_launch); |
195 | 209 |
196 // Invoked when a background app is installed so we can display a | 210 // Invoked when a background app is installed so we can display a |
197 // platform-specific notification to the user. | 211 // platform-specific notification to the user. |
198 virtual void DisplayAppInstalledNotification( | 212 virtual void DisplayAppInstalledNotification( |
199 const extensions::Extension* extension); | 213 const extensions::Extension* extension); |
200 | 214 |
201 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background | 215 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background |
202 // and has a status bar icon. | 216 // and has a status bar icon. |
203 void StartBackgroundMode(); | 217 void StartBackgroundMode(); |
204 | 218 |
205 // Invoked to create the status icon if any profiles currently running | |
206 // background apps so that there is a way to exit Chrome. | |
207 void InitStatusTrayIcon(); | |
208 | |
209 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in | 219 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in |
210 // the background and removes its status bar icon. | 220 // the background and removes its status bar icon. |
211 void EndBackgroundMode(); | 221 void EndBackgroundMode(); |
212 | 222 |
| 223 // Enables keep alive and the status tray icon if and only if background mode |
| 224 // is active and not suspended. |
| 225 void UpdateKeepAliveAndTrayIcon(); |
| 226 |
213 // If --no-startup-window is passed, BackgroundModeManager will manually keep | 227 // If --no-startup-window is passed, BackgroundModeManager will manually keep |
214 // chrome running while waiting for apps to load. This is called when we no | 228 // chrome running while waiting for apps to load. This is called when we no |
215 // longer need to do this (either because the user has chosen to exit chrome | 229 // longer need to do this (either because the user has chosen to exit chrome |
216 // manually, or all apps have been loaded). | 230 // manually, or all apps have been loaded). |
217 void EndKeepAliveForStartup(); | 231 void EndKeepAliveForStartup(); |
218 | 232 |
219 // Return an appropriate name for a Preferences menu entry. Preferences is | 233 // Return an appropriate name for a Preferences menu entry. Preferences is |
220 // sometimes called Options or Settings. | 234 // sometimes called Options or Settings. |
221 string16 GetPreferencesMenuLabel(); | 235 string16 GetPreferencesMenuLabel(); |
222 | 236 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Set when we are keeping chrome running during the startup process - this | 309 // Set when we are keeping chrome running during the startup process - this |
296 // is required when running with the --no-startup-window flag, as otherwise | 310 // is required when running with the --no-startup-window flag, as otherwise |
297 // chrome would immediately exit due to having no open windows. | 311 // chrome would immediately exit due to having no open windows. |
298 bool keep_alive_for_startup_; | 312 bool keep_alive_for_startup_; |
299 | 313 |
300 // Set to true when Chrome is running with the --keep-alive-for-test flag | 314 // Set to true when Chrome is running with the --keep-alive-for-test flag |
301 // (used for testing background mode without having to install a background | 315 // (used for testing background mode without having to install a background |
302 // app). | 316 // app). |
303 bool keep_alive_for_test_; | 317 bool keep_alive_for_test_; |
304 | 318 |
| 319 // Set to true when background mode is suspended. |
| 320 bool background_mode_suspended_; |
| 321 |
| 322 // Set to true when background mode is keeping Chrome alive. |
| 323 bool keeping_alive_; |
| 324 |
305 // Provides a command id for each profile as they are created. | 325 // Provides a command id for each profile as they are created. |
306 int current_command_id_; | 326 int current_command_id_; |
307 | 327 |
308 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); | 328 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
309 }; | 329 }; |
310 | 330 |
311 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 331 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
OLD | NEW |