OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.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 #include "extensions/common/view_type.h" | 20 #include "extensions/common/view_type.h" |
20 | 21 |
21 class GURL; | 22 class GURL; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class BrowserContext; | 25 class BrowserContext; |
25 class DevToolsAgentHost; | 26 class DevToolsAgentHost; |
26 class RenderViewHost; | 27 class RenderViewHost; |
27 class RenderFrameHost; | 28 class RenderFrameHost; |
28 class SiteInstance; | 29 class SiteInstance; |
29 }; | 30 }; |
30 | 31 |
31 namespace extensions { | 32 namespace extensions { |
32 | 33 |
33 class Extension; | 34 class Extension; |
34 class ExtensionHost; | 35 class ExtensionHost; |
| 36 class ProcessManagerObserver; |
35 | 37 |
36 // Manages dynamic state of running Chromium extensions. There is one instance | 38 // Manages dynamic state of running Chromium extensions. There is one instance |
37 // of this class per Profile. OTR Profiles have a separate instance that keeps | 39 // of this class per Profile. OTR Profiles have a separate instance that keeps |
38 // track of split-mode extensions only. | 40 // track of split-mode extensions only. |
39 class ProcessManager : public content::NotificationObserver { | 41 class ProcessManager : public content::NotificationObserver { |
40 public: | 42 public: |
41 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; | 43 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; |
42 typedef ExtensionHostSet::const_iterator const_iterator; | 44 typedef ExtensionHostSet::const_iterator const_iterator; |
43 | 45 |
44 static ProcessManager* Create(content::BrowserContext* context); | 46 static ProcessManager* Create(content::BrowserContext* context); |
45 virtual ~ProcessManager(); | 47 virtual ~ProcessManager(); |
46 | 48 |
47 const ExtensionHostSet& background_hosts() const { | 49 const ExtensionHostSet& background_hosts() const { |
48 return background_hosts_; | 50 return background_hosts_; |
49 } | 51 } |
50 | 52 |
51 typedef std::set<content::RenderViewHost*> ViewSet; | 53 typedef std::set<content::RenderViewHost*> ViewSet; |
52 const ViewSet GetAllViews() const; | 54 const ViewSet GetAllViews() const; |
53 | 55 |
| 56 // The typical observer interface. |
| 57 void AddObserver(ProcessManagerObserver* observer); |
| 58 void RemoveObserver(ProcessManagerObserver* observer); |
| 59 |
54 // Creates a new UI-less extension instance. Like CreateViewHost, but not | 60 // Creates a new UI-less extension instance. Like CreateViewHost, but not |
55 // displayed anywhere. Returns false if no background host can be created, | 61 // displayed anywhere. Returns false if no background host can be created, |
56 // for example for hosted apps and extensions that aren't enabled in | 62 // for example for hosted apps and extensions that aren't enabled in |
57 // Incognito. | 63 // Incognito. |
58 virtual bool CreateBackgroundHost(const Extension* extension, | 64 virtual bool CreateBackgroundHost(const Extension* extension, |
59 const GURL& url); | 65 const GURL& url); |
60 | 66 |
61 // Gets the ExtensionHost for the background page for an extension, or NULL if | 67 // Gets the ExtensionHost for the background page for an extension, or NULL if |
62 // the extension isn't running or doesn't have a background page. | 68 // the extension isn't running or doesn't have a background page. |
63 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); | 69 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 base::TimeDelta event_page_suspending_time_; | 237 base::TimeDelta event_page_suspending_time_; |
232 | 238 |
233 // True if we have created the startup set of background hosts. | 239 // True if we have created the startup set of background hosts. |
234 bool startup_background_hosts_created_; | 240 bool startup_background_hosts_created_; |
235 | 241 |
236 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 242 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
237 | 243 |
238 ImpulseCallbackForTesting keepalive_impulse_callback_for_testing_; | 244 ImpulseCallbackForTesting keepalive_impulse_callback_for_testing_; |
239 ImpulseCallbackForTesting keepalive_impulse_decrement_callback_for_testing_; | 245 ImpulseCallbackForTesting keepalive_impulse_decrement_callback_for_testing_; |
240 | 246 |
| 247 ObserverList<ProcessManagerObserver> observer_list_; |
| 248 |
241 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; | 249 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
242 | 250 |
243 DISALLOW_COPY_AND_ASSIGN(ProcessManager); | 251 DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
244 }; | 252 }; |
245 | 253 |
246 } // namespace extensions | 254 } // namespace extensions |
247 | 255 |
248 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 256 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
OLD | NEW |