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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 // | 38 // |
39 // When Chrome is in background mode, it will continue running even after the | 39 // When Chrome is in background mode, it will continue running even after the |
40 // last browser window is closed, until the user explicitly exits the app. | 40 // last browser window is closed, until the user explicitly exits the app. |
41 // Additionally, when in background mode, Chrome will launch on OS login with | 41 // Additionally, when in background mode, Chrome will launch on OS login with |
42 // no open windows to allow apps with the "background" permission to run in the | 42 // no open windows to allow apps with the "background" permission to run in the |
43 // background. | 43 // background. |
44 class BackgroundModeManager | 44 class BackgroundModeManager |
45 : public content::NotificationObserver, | 45 : public content::NotificationObserver, |
46 public BackgroundApplicationListModel::Observer, | 46 public BackgroundApplicationListModel::Observer, |
47 public ProfileInfoCacheObserver, | 47 public ProfileInfoCacheObserver, |
48 public ProfileKeyedService, | |
49 public ui::SimpleMenuModel::Delegate { | 48 public ui::SimpleMenuModel::Delegate { |
50 public: | 49 public: |
51 BackgroundModeManager(CommandLine* command_line, | 50 BackgroundModeManager(CommandLine* command_line, |
52 ProfileInfoCache* profile_cache); | 51 ProfileInfoCache* profile_cache); |
53 virtual ~BackgroundModeManager(); | 52 virtual ~BackgroundModeManager(); |
54 | 53 |
55 static void RegisterPrefs(PrefService* prefs); | 54 static void RegisterPrefs(PrefService* prefs); |
56 | 55 |
57 virtual void RegisterProfile(Profile* profile); | 56 virtual void RegisterProfile(Profile* profile); |
58 | 57 |
59 static void LaunchBackgroundApplication(Profile* profile, | 58 static void LaunchBackgroundApplication(Profile* profile, |
60 const Extension* extension); | 59 const Extension* extension); |
61 | 60 |
62 // For testing purposes. | 61 // For testing purposes. |
63 int NumberOfBackgroundModeData(); | 62 int NumberOfBackgroundModeData(); |
64 | 63 |
65 private: | 64 private: |
| 65 friend class AppBackgroundPageApiTest; |
| 66 friend class BackgroundModeManagerTest; |
66 friend class TestBackgroundModeManager; | 67 friend class TestBackgroundModeManager; |
67 friend class BackgroundModeManagerTest; | |
68 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 68 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
69 BackgroundAppLoadUnload); | 69 BackgroundAppLoadUnload); |
70 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 70 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
71 BackgroundLaunchOnStartup); | 71 BackgroundLaunchOnStartup); |
72 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 72 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
73 BackgroundAppInstallUninstallWhileDisabled); | 73 BackgroundAppInstallUninstallWhileDisabled); |
74 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 74 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
75 EnableAfterBackgroundAppInstall); | 75 EnableAfterBackgroundAppInstall); |
76 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 76 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
77 MultiProfile); | 77 MultiProfile); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // Returns the iterator associated with a particular profile name. | 231 // Returns the iterator associated with a particular profile name. |
232 // This should not be used to iterate over the background mode data. It is | 232 // This should not be used to iterate over the background mode data. It is |
233 // used to efficiently delete an item from the background mode data map. | 233 // used to efficiently delete an item from the background mode data map. |
234 BackgroundModeInfoMap::iterator GetBackgroundModeIterator( | 234 BackgroundModeInfoMap::iterator GetBackgroundModeIterator( |
235 const string16& profile_name); | 235 const string16& profile_name); |
236 | 236 |
237 // Returns true if the "Let chrome run in the background" pref is checked. | 237 // Returns true if the "Let chrome run in the background" pref is checked. |
238 // (virtual to allow overriding in tests). | 238 // (virtual to allow overriding in tests). |
239 virtual bool IsBackgroundModePrefEnabled() const; | 239 virtual bool IsBackgroundModePrefEnabled() const; |
240 | 240 |
| 241 // Returns true if background mode is active. Used only by tests. |
| 242 bool IsBackgroundModeActiveForTest(); |
| 243 |
241 // Turns off background mode if it's currently enabled. | 244 // Turns off background mode if it's currently enabled. |
242 void DisableBackgroundMode(); | 245 void DisableBackgroundMode(); |
243 | 246 |
244 // Turns on background mode if it's currently disabled. | 247 // Turns on background mode if it's currently disabled. |
245 void EnableBackgroundMode(); | 248 void EnableBackgroundMode(); |
246 | 249 |
247 // Returns the number of background apps in the system (virtual to allow | 250 // Returns the number of background apps in the system (virtual to allow |
248 // overriding in unit tests). | 251 // overriding in unit tests). |
249 virtual int GetBackgroundAppCount() const; | 252 virtual int GetBackgroundAppCount() const; |
250 | 253 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // app). | 291 // app). |
289 bool keep_alive_for_test_; | 292 bool keep_alive_for_test_; |
290 | 293 |
291 // Provides a command id for each profile as they are created. | 294 // Provides a command id for each profile as they are created. |
292 int current_command_id_; | 295 int current_command_id_; |
293 | 296 |
294 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); | 297 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
295 }; | 298 }; |
296 | 299 |
297 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 300 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
OLD | NEW |