Chromium Code Reviews| Index: chrome/browser/extensions/api/processes/processes_api.h |
| diff --git a/chrome/browser/extensions/api/processes/processes_api.h b/chrome/browser/extensions/api/processes/processes_api.h |
| index c30169aed51717c69b3b54bb3fa9b01bad8fecc7..d4a6bade5d207705af1cba7559e8ec7059248877 100644 |
| --- a/chrome/browser/extensions/api/processes/processes_api.h |
| +++ b/chrome/browser/extensions/api/processes/processes_api.h |
| @@ -8,12 +8,17 @@ |
| #include <set> |
| #include <string> |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chrome/browser/extensions/event_router.h" |
| #include "chrome/browser/extensions/extension_function.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| #include "chrome/browser/task_manager/task_manager.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_widget_host.h" |
| +class Profile; |
| + |
| namespace base { |
| class ListValue; |
| } |
| @@ -25,11 +30,8 @@ namespace extensions { |
| class ProcessesEventRouter : public TaskManagerModelObserver, |
| public content::NotificationObserver { |
| public: |
| - // Single instance of the event router. |
| - static ProcessesEventRouter* GetInstance(); |
| - |
| - // Safe to call multiple times. |
| - void ObserveProfile(Profile* profile); |
| + explicit ProcessesEventRouter(Profile* profile); |
| + virtual ~ProcessesEventRouter(); |
| // Called when an extension process wants to listen to process events. |
| void ListenerAdded(); |
| @@ -46,11 +48,6 @@ class ProcessesEventRouter : public TaskManagerModelObserver, |
| int num_listeners() { return listeners_; } |
| private: |
| - friend struct DefaultSingletonTraits<ProcessesEventRouter>; |
| - |
| - ProcessesEventRouter(); |
| - virtual ~ProcessesEventRouter(); |
| - |
| // content::NotificationObserver implementation. |
| virtual void Observe(int type, |
| const content::NotificationSource& source, |
| @@ -69,11 +66,7 @@ class ProcessesEventRouter : public TaskManagerModelObserver, |
| content::RenderProcessHost* rph, |
| content::RenderProcessHost::RendererClosedDetails* details); |
| - void NotifyProfiles(const char* event_name, |
| - scoped_ptr<base::ListValue> event_args); |
| - |
| - void DispatchEvent(Profile* profile, |
| - const char* event_name, |
| + void DispatchEvent(const char* event_name, |
| scoped_ptr<base::ListValue> event_args); |
| // Determines whether there is a registered listener for the specified event. |
| @@ -83,9 +76,7 @@ class ProcessesEventRouter : public TaskManagerModelObserver, |
| // Used for tracking registrations to process related notifications. |
| content::NotificationRegistrar registrar_; |
| - // Registered profiles. |
| - typedef std::set<Profile*> ProfileSet; |
| - ProfileSet profiles_; |
| + Profile* profile_; |
| // TaskManager to observe for updates. |
| TaskManagerModel* model_; |
| @@ -100,6 +91,32 @@ class ProcessesEventRouter : public TaskManagerModelObserver, |
| DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter); |
| }; |
| +// The profile-keyed service that manages the processes extension API. |
| +class ProcessesAPI : public ProfileKeyedService, |
| + public EventRouter::Observer { |
| + public: |
| + explicit ProcessesAPI(Profile* profile); |
| + virtual ~ProcessesAPI(); |
| + |
| + // Convenience method to get the ProcessesAPI for a profile. |
| + static ProcessesAPI* Get(Profile* profile); |
| + |
| + ProcessesEventRouter* processes_event_router() { |
| + return processes_event_router_.get(); |
| + } |
| + |
| + // EventRouter::Observer implementation. |
| + virtual void OnListenerAdded(const std::string& event_name) OVERRIDE; |
| + virtual void OnListenerRemoved(const std::string& event_name) OVERRIDE; |
| + |
| + private: |
| + Profile* profile_; |
| + |
| + // TODO(yoz): Currently, the event router cannot be started lazily |
| + // because some API functions use it. It ought to be possible to fix |
| + // by moving some state to ProcessesAPI from the event router. |
|
Matt Perry
2012/11/09 00:23:34
Couldn't you have the accessor lazily create the e
Yoyo Zhou
2012/11/09 00:35:55
Duh. Thanks.
|
| + scoped_ptr<extensions::ProcessesEventRouter> processes_event_router_; |
| +}; |
| // This extension function returns the Process object for the renderer process |
| // currently in use by the specified Tab. |