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_CONTENTS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/scoped_observer.h" |
14 #include "chrome/browser/tab_contents/background_contents.h" | 15 #include "chrome/browser/tab_contents/background_contents.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/common/window_container_type.h" | 19 #include "content/public/common/window_container_type.h" |
| 20 #include "extensions/browser/extension_registry_observer.h" |
19 #include "ui/base/window_open_disposition.h" | 21 #include "ui/base/window_open_disposition.h" |
20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
21 | 23 |
22 class PrefService; | 24 class PrefService; |
23 class Profile; | 25 class Profile; |
24 | 26 |
25 namespace base { | 27 namespace base { |
26 class CommandLine; | 28 class CommandLine; |
27 class DictionaryValue; | 29 class DictionaryValue; |
28 } | 30 } |
29 | 31 |
30 namespace content { | 32 namespace content { |
31 class SessionStorageNamespace; | 33 class SessionStorageNamespace; |
32 } | 34 } |
33 | 35 |
34 namespace extensions { | 36 namespace extensions { |
35 class Extension; | 37 class Extension; |
| 38 class ExtensionRegistry; |
36 } | 39 } |
37 | 40 |
38 namespace gfx { | 41 namespace gfx { |
39 class Rect; | 42 class Rect; |
40 } | 43 } |
41 | 44 |
42 struct BackgroundContentsOpenedDetails; | 45 struct BackgroundContentsOpenedDetails; |
43 | 46 |
44 // BackgroundContentsService is owned by the profile, and is responsible for | 47 // BackgroundContentsService is owned by the profile, and is responsible for |
45 // managing the lifetime of BackgroundContents (tracking the set of background | 48 // managing the lifetime of BackgroundContents (tracking the set of background |
46 // urls, loading them at startup, and keeping the browser process alive as long | 49 // urls, loading them at startup, and keeping the browser process alive as long |
47 // as there are BackgroundContents loaded). | 50 // as there are BackgroundContents loaded). |
48 // | 51 // |
49 // It is also responsible for tracking the association between | 52 // It is also responsible for tracking the association between |
50 // BackgroundContents and their parent app, and shutting them down when the | 53 // BackgroundContents and their parent app, and shutting them down when the |
51 // parent app is unloaded. | 54 // parent app is unloaded. |
52 class BackgroundContentsService : private content::NotificationObserver, | 55 class BackgroundContentsService : private content::NotificationObserver, |
| 56 public extensions::ExtensionRegistryObserver, |
53 public BackgroundContents::Delegate, | 57 public BackgroundContents::Delegate, |
54 public KeyedService { | 58 public KeyedService { |
55 public: | 59 public: |
56 BackgroundContentsService(Profile* profile, | 60 BackgroundContentsService(Profile* profile, |
57 const base::CommandLine* command_line); | 61 const base::CommandLine* command_line); |
58 virtual ~BackgroundContentsService(); | 62 virtual ~BackgroundContentsService(); |
59 | 63 |
60 // Allows tests to reduce the time between a force-installed app/extension | 64 // Allows tests to reduce the time between a force-installed app/extension |
61 // crashing and when we reload it. | 65 // crashing and when we reload it. |
62 static void SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( | 66 static void SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 KillBGContents); | 137 KillBGContents); |
134 | 138 |
135 // Registers for various notifications. | 139 // Registers for various notifications. |
136 void StartObserving(Profile* profile); | 140 void StartObserving(Profile* profile); |
137 | 141 |
138 // content::NotificationObserver implementation. | 142 // content::NotificationObserver implementation. |
139 virtual void Observe(int type, | 143 virtual void Observe(int type, |
140 const content::NotificationSource& source, | 144 const content::NotificationSource& source, |
141 const content::NotificationDetails& details) OVERRIDE; | 145 const content::NotificationDetails& details) OVERRIDE; |
142 | 146 |
| 147 // extensions::ExtensionRegistryObserver implementation. |
| 148 virtual void OnExtensionLoaded( |
| 149 content::BrowserContext* browser_context, |
| 150 const extensions::Extension* extension) OVERRIDE; |
| 151 virtual void OnExtensionUnloaded( |
| 152 content::BrowserContext* browser_context, |
| 153 const extensions::Extension* extension, |
| 154 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 155 virtual void OnExtensionUninstalled( |
| 156 content::BrowserContext* browser_context, |
| 157 const extensions::Extension* extension, |
| 158 extensions::UninstallReason reason) OVERRIDE; |
| 159 |
143 // Restarts a force-installed app/extension after a crash. | 160 // Restarts a force-installed app/extension after a crash. |
144 void RestartForceInstalledExtensionOnCrash( | 161 void RestartForceInstalledExtensionOnCrash( |
145 const extensions::Extension* extension, | 162 const extensions::Extension* extension, |
146 Profile* profile); | 163 Profile* profile); |
147 | 164 |
148 // Loads all registered BackgroundContents at startup. | 165 // Loads all registered BackgroundContents at startup. |
149 void LoadBackgroundContentsFromPrefs(Profile* profile); | 166 void LoadBackgroundContentsFromPrefs(Profile* profile); |
150 | 167 |
151 // Load a BackgroundContent; the settings are read from the provided | 168 // Load a BackgroundContent; the settings are read from the provided |
152 // dictionary. | 169 // dictionary. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 }; | 228 }; |
212 | 229 |
213 // Map associating currently loaded BackgroundContents with their parent | 230 // Map associating currently loaded BackgroundContents with their parent |
214 // applications. | 231 // applications. |
215 // Key: application id | 232 // Key: application id |
216 // Value: BackgroundContentsInfo for the BC associated with that application | 233 // Value: BackgroundContentsInfo for the BC associated with that application |
217 typedef std::map<base::string16, BackgroundContentsInfo> | 234 typedef std::map<base::string16, BackgroundContentsInfo> |
218 BackgroundContentsMap; | 235 BackgroundContentsMap; |
219 BackgroundContentsMap contents_map_; | 236 BackgroundContentsMap contents_map_; |
220 | 237 |
| 238 ScopedObserver<extensions::ExtensionRegistry, |
| 239 extensions::ExtensionRegistryObserver> |
| 240 extension_registry_observer_; |
| 241 |
221 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); | 242 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); |
222 }; | 243 }; |
223 | 244 |
224 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 245 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
OLD | NEW |