OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_MODE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ |
6 #define CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ | 6 #define CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "chrome/browser/background_application_list_model.h" | 10 #include "chrome/browser/background_application_list_model.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // background. | 39 // background. |
40 class BackgroundModeManager | 40 class BackgroundModeManager |
41 : public NotificationObserver, | 41 : public NotificationObserver, |
42 public ui::SimpleMenuModel::Delegate, | 42 public ui::SimpleMenuModel::Delegate, |
43 public BackgroundApplicationListModel::Observer, | 43 public BackgroundApplicationListModel::Observer, |
44 public ProfileKeyedService { | 44 public ProfileKeyedService { |
45 public: | 45 public: |
46 BackgroundModeManager(Profile* profile, CommandLine* command_line); | 46 BackgroundModeManager(Profile* profile, CommandLine* command_line); |
47 virtual ~BackgroundModeManager(); | 47 virtual ~BackgroundModeManager(); |
48 | 48 |
49 static bool IsBackgroundModeEnabled(const CommandLine* command_line); | |
50 static void RegisterPrefs(PrefService* prefs); | 49 static void RegisterPrefs(PrefService* prefs); |
51 | 50 |
52 private: | 51 private: |
53 friend class TestBackgroundModeManager; | 52 friend class TestBackgroundModeManager; |
54 friend class BackgroundModeManagerTest; | 53 friend class BackgroundModeManagerTest; |
55 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 54 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
56 BackgroundAppLoadUnload); | 55 BackgroundAppLoadUnload); |
57 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 56 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
58 BackgroundAppInstallUninstall); | 57 BackgroundAppInstallUninstall); |
59 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 58 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
60 BackgroundPrefDisabled); | 59 BackgroundAppInstallUninstallWhileDisabled); |
61 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 60 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
62 BackgroundPrefDynamicDisable); | 61 EnableAfterBackgroundAppInstall); |
63 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | |
64 BackgroundPrefDynamicEnable); | |
65 | 62 |
66 // NotificationObserver implementation. | 63 // NotificationObserver implementation. |
67 virtual void Observe(NotificationType type, | 64 virtual void Observe(NotificationType type, |
68 const NotificationSource& source, | 65 const NotificationSource& source, |
69 const NotificationDetails& details); | 66 const NotificationDetails& details); |
70 | 67 |
71 // SimpleMenuModel::Delegate implementation. | 68 // SimpleMenuModel::Delegate implementation. |
72 virtual bool IsCommandIdChecked(int command_id) const; | 69 virtual bool IsCommandIdChecked(int command_id) const; |
73 virtual bool IsCommandIdEnabled(int command_id) const; | 70 virtual bool IsCommandIdEnabled(int command_id) const; |
74 virtual bool GetAcceleratorForCommandId(int command_id, | 71 virtual bool GetAcceleratorForCommandId(int command_id, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Create a context menu, or replace/update an existing context menu, for the | 136 // Create a context menu, or replace/update an existing context menu, for the |
140 // status tray icon which, among other things, allows the user to shutdown | 137 // status tray icon which, among other things, allows the user to shutdown |
141 // Chrome when running in background mode. | 138 // Chrome when running in background mode. |
142 virtual void UpdateStatusTrayIconContextMenu(); | 139 virtual void UpdateStatusTrayIconContextMenu(); |
143 | 140 |
144 // Returns a browser window, or creates one if none are open. Used by | 141 // Returns a browser window, or creates one if none are open. Used by |
145 // operations (like displaying the preferences dialog) that require a Browser | 142 // operations (like displaying the preferences dialog) that require a Browser |
146 // window. | 143 // window. |
147 Browser* GetBrowserWindow(); | 144 Browser* GetBrowserWindow(); |
148 | 145 |
| 146 // Returns true if the "Let chrome run in the background" pref is checked. |
| 147 // (virtual to allow overriding in tests). |
| 148 virtual bool IsBackgroundModePrefEnabled(); |
| 149 |
| 150 // Turns off background mode if it's currently enabled. |
| 151 void DisableBackgroundMode(); |
| 152 |
| 153 // Turns on background mode if it's currently disabled. |
| 154 void EnableBackgroundMode(); |
| 155 |
| 156 // Returns true if background mode is permanently disabled for this chrome |
| 157 // session. |
| 158 static bool IsBackgroundModePermanentlyDisabled( |
| 159 const CommandLine* command_line); |
| 160 |
| 161 // Registrars for managing our change observers. |
149 NotificationRegistrar registrar_; | 162 NotificationRegistrar registrar_; |
| 163 PrefChangeRegistrar pref_registrar_; |
150 | 164 |
151 // The parent profile for this object. | 165 // The parent profile for this object. |
152 Profile* profile_; | 166 Profile* profile_; |
153 | 167 |
154 // The cached list of BackgroundApplications. | 168 // The cached list of BackgroundApplications. |
155 BackgroundApplicationListModel applications_; | 169 BackgroundApplicationListModel applications_; |
156 | 170 |
157 // The number of background apps currently loaded. | 171 // The number of background apps currently loaded. |
158 int background_app_count_; | 172 int background_app_count_; |
159 | 173 |
(...skipping 19 matching lines...) Expand all Loading... |
179 // platform doesn't support status icons. | 193 // platform doesn't support status icons. |
180 StatusTray* status_tray_; | 194 StatusTray* status_tray_; |
181 | 195 |
182 // Reference to our status icon (if any) - owned by the StatusTray. | 196 // Reference to our status icon (if any) - owned by the StatusTray. |
183 StatusIcon* status_icon_; | 197 StatusIcon* status_icon_; |
184 | 198 |
185 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); | 199 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
186 }; | 200 }; |
187 | 201 |
188 #endif // CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ | 202 #endif // CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ |
OLD | NEW |