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 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.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/prefs/pref_change_registrar.h" | 13 #include "chrome/browser/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 14 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "chrome/browser/status_icons/status_icon.h" | 16 #include "chrome/browser/status_icons/status_icon.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
20 | 20 |
21 class Browser; | 21 class Browser; |
22 class CommandLine; | 22 class CommandLine; |
23 class Extension; | |
24 class PrefService; | 23 class PrefService; |
25 class Profile; | 24 class Profile; |
26 class ProfileInfoCache; | 25 class ProfileInfoCache; |
27 class StatusIcon; | 26 class StatusIcon; |
28 class StatusTray; | 27 class StatusTray; |
29 | 28 |
| 29 namespace extensions { |
| 30 class Extension; |
| 31 } |
| 32 |
30 // BackgroundModeManager is responsible for switching Chrome into and out of | 33 // BackgroundModeManager is responsible for switching Chrome into and out of |
31 // "background mode" and for providing UI for the user to exit Chrome when there | 34 // "background mode" and for providing UI for the user to exit Chrome when there |
32 // are no open browser windows. | 35 // are no open browser windows. |
33 // | 36 // |
34 // Chrome enters background mode whenever there is an application with the | 37 // Chrome enters background mode whenever there is an application with the |
35 // "background" permission installed. This class monitors the set of | 38 // "background" permission installed. This class monitors the set of |
36 // installed/loaded extensions to ensure that Chrome enters/exits background | 39 // installed/loaded extensions to ensure that Chrome enters/exits background |
37 // mode at the appropriate time. | 40 // mode at the appropriate time. |
38 // | 41 // |
39 // 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 |
40 // 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. |
41 // 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 |
42 // 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 |
43 // background. | 46 // background. |
44 class BackgroundModeManager | 47 class BackgroundModeManager |
45 : public content::NotificationObserver, | 48 : public content::NotificationObserver, |
46 public BackgroundApplicationListModel::Observer, | 49 public BackgroundApplicationListModel::Observer, |
47 public ProfileInfoCacheObserver, | 50 public ProfileInfoCacheObserver, |
48 public ui::SimpleMenuModel::Delegate { | 51 public ui::SimpleMenuModel::Delegate { |
49 public: | 52 public: |
50 BackgroundModeManager(CommandLine* command_line, | 53 BackgroundModeManager(CommandLine* command_line, |
51 ProfileInfoCache* profile_cache); | 54 ProfileInfoCache* profile_cache); |
52 virtual ~BackgroundModeManager(); | 55 virtual ~BackgroundModeManager(); |
53 | 56 |
54 static void RegisterPrefs(PrefService* prefs); | 57 static void RegisterPrefs(PrefService* prefs); |
55 | 58 |
56 virtual void RegisterProfile(Profile* profile); | 59 virtual void RegisterProfile(Profile* profile); |
57 | 60 |
58 static void LaunchBackgroundApplication(Profile* profile, | 61 static void LaunchBackgroundApplication(Profile* profile, |
59 const Extension* extension); | 62 const extensions::Extension* extension); |
60 | 63 |
61 // For testing purposes. | 64 // For testing purposes. |
62 int NumberOfBackgroundModeData(); | 65 int NumberOfBackgroundModeData(); |
63 | 66 |
64 private: | 67 private: |
65 friend class AppBackgroundPageApiTest; | 68 friend class AppBackgroundPageApiTest; |
66 friend class BackgroundModeManagerTest; | 69 friend class BackgroundModeManagerTest; |
67 friend class TestBackgroundModeManager; | 70 friend class TestBackgroundModeManager; |
68 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, | 71 FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
69 BackgroundAppLoadUnload); | 72 BackgroundAppLoadUnload); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 typedef linked_ptr<BackgroundModeData> BackgroundModeInfo; | 149 typedef linked_ptr<BackgroundModeData> BackgroundModeInfo; |
147 | 150 |
148 typedef std::map<Profile*, BackgroundModeInfo> BackgroundModeInfoMap; | 151 typedef std::map<Profile*, BackgroundModeInfo> BackgroundModeInfoMap; |
149 | 152 |
150 // content::NotificationObserver implementation. | 153 // content::NotificationObserver implementation. |
151 virtual void Observe(int type, | 154 virtual void Observe(int type, |
152 const content::NotificationSource& source, | 155 const content::NotificationSource& source, |
153 const content::NotificationDetails& details) OVERRIDE; | 156 const content::NotificationDetails& details) OVERRIDE; |
154 | 157 |
155 // BackgroundApplicationListModel::Observer implementation. | 158 // BackgroundApplicationListModel::Observer implementation. |
156 virtual void OnApplicationDataChanged(const Extension* extension, | 159 virtual void OnApplicationDataChanged(const extensions::Extension* extension, |
157 Profile* profile) OVERRIDE; | 160 Profile* profile) OVERRIDE; |
158 virtual void OnApplicationListChanged(Profile* profile) OVERRIDE; | 161 virtual void OnApplicationListChanged(Profile* profile) OVERRIDE; |
159 | 162 |
160 // Overrides from ProfileInfoCacheObserver | 163 // Overrides from ProfileInfoCacheObserver |
161 virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE; | 164 virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE; |
162 virtual void OnProfileWillBeRemoved(const FilePath& profile_path) OVERRIDE; | 165 virtual void OnProfileWillBeRemoved(const FilePath& profile_path) OVERRIDE; |
163 virtual void OnProfileWasRemoved(const FilePath& profile_path, | 166 virtual void OnProfileWasRemoved(const FilePath& profile_path, |
164 const string16& profile_name) OVERRIDE; | 167 const string16& profile_name) OVERRIDE; |
165 virtual void OnProfileNameChanged(const FilePath& profile_path, | 168 virtual void OnProfileNameChanged(const FilePath& profile_path, |
166 const string16& old_profile_name) OVERRIDE; | 169 const string16& old_profile_name) OVERRIDE; |
167 virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE; | 170 virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE; |
168 | 171 |
169 // Overrides from SimpleMenuModel::Delegate implementation. | 172 // Overrides from SimpleMenuModel::Delegate implementation. |
170 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 173 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
171 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 174 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
172 virtual bool GetAcceleratorForCommandId(int command_id, | 175 virtual bool GetAcceleratorForCommandId(int command_id, |
173 ui::Accelerator* accelerator) | 176 ui::Accelerator* accelerator) |
174 OVERRIDE; | 177 OVERRIDE; |
175 virtual void ExecuteCommand(int command_id) OVERRIDE; | 178 virtual void ExecuteCommand(int command_id) OVERRIDE; |
176 | 179 |
177 // Invoked when an extension is installed so we can ensure that | 180 // Invoked when an extension is installed so we can ensure that |
178 // launch-on-startup is enabled if appropriate. |extension| can be NULL when | 181 // launch-on-startup is enabled if appropriate. |extension| can be NULL when |
179 // called from unit tests. | 182 // called from unit tests. |
180 void OnBackgroundAppInstalled(const Extension* extension); | 183 void OnBackgroundAppInstalled(const extensions::Extension* extension); |
181 | 184 |
182 // Called to make sure that our launch-on-startup mode is properly set. | 185 // Called to make sure that our launch-on-startup mode is properly set. |
183 // (virtual so we can override for tests). | 186 // (virtual so we can override for tests). |
184 virtual void EnableLaunchOnStartup(bool should_launch); | 187 virtual void EnableLaunchOnStartup(bool should_launch); |
185 | 188 |
186 // Invoked when a background app is installed so we can display a | 189 // Invoked when a background app is installed so we can display a |
187 // platform-specific notification to the user. | 190 // platform-specific notification to the user. |
188 void DisplayAppInstalledNotification(const Extension* extension); | 191 void DisplayAppInstalledNotification(const extensions::Extension* extension); |
189 | 192 |
190 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background | 193 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background |
191 // and has a status bar icon. | 194 // and has a status bar icon. |
192 void StartBackgroundMode(); | 195 void StartBackgroundMode(); |
193 | 196 |
194 // Invoked to create the status icon if any profiles currently running | 197 // Invoked to create the status icon if any profiles currently running |
195 // background apps so that there is a way to exit Chrome. | 198 // background apps so that there is a way to exit Chrome. |
196 void InitStatusTrayIcon(); | 199 void InitStatusTrayIcon(); |
197 | 200 |
198 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in | 201 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // app). | 294 // app). |
292 bool keep_alive_for_test_; | 295 bool keep_alive_for_test_; |
293 | 296 |
294 // Provides a command id for each profile as they are created. | 297 // Provides a command id for each profile as they are created. |
295 int current_command_id_; | 298 int current_command_id_; |
296 | 299 |
297 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); | 300 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
298 }; | 301 }; |
299 | 302 |
300 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 303 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
OLD | NEW |