Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: chrome/browser/extensions/api/processes/processes_api.h

Issue 166053003: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: | Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
13 #include "chrome/browser/extensions/chrome_extension_function.h" 13 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/task_manager/task_manager.h" 14 #include "chrome/browser/task_manager/task_manager.h"
15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_widget_host.h" 18 #include "content/public/browser/render_widget_host.h"
19 #include "extensions/browser/event_router.h" 19 #include "extensions/browser/event_router.h"
20 20
21 class Profile;
22
23 namespace base { 21 namespace base {
24 class ListValue; 22 class ListValue;
25 } 23 }
26 24
25 namespace content {
26 class BrowserContext;
27 }
28
27 namespace extensions { 29 namespace extensions {
28 30
29 // Observes the Task Manager and routes the notifications as events to the 31 // Observes the Task Manager and routes the notifications as events to the
30 // extension system. 32 // extension system.
31 class ProcessesEventRouter : public TaskManagerModelObserver, 33 class ProcessesEventRouter : public TaskManagerModelObserver,
32 public content::NotificationObserver { 34 public content::NotificationObserver {
33 public: 35 public:
34 explicit ProcessesEventRouter(Profile* profile); 36 explicit ProcessesEventRouter(content::BrowserContext* context);
35 virtual ~ProcessesEventRouter(); 37 virtual ~ProcessesEventRouter();
36 38
37 // Called when an extension process wants to listen to process events. 39 // Called when an extension process wants to listen to process events.
38 void ListenerAdded(); 40 void ListenerAdded();
39 41
40 // Called when an extension process with a listener exits or removes it. 42 // Called when an extension process with a listener exits or removes it.
41 void ListenerRemoved(); 43 void ListenerRemoved();
42 44
43 // Called on the first invocation of extension API function. This will call 45 // Called on the first invocation of extension API function. This will call
44 // out to the Task Manager to start listening for notifications. Returns 46 // out to the Task Manager to start listening for notifications. Returns
(...skipping 24 matching lines...) Expand all
69 void DispatchEvent(const std::string& event_name, 71 void DispatchEvent(const std::string& event_name,
70 scoped_ptr<base::ListValue> event_args); 72 scoped_ptr<base::ListValue> event_args);
71 73
72 // Determines whether there is a registered listener for the specified event. 74 // Determines whether there is a registered listener for the specified event.
73 // It helps to avoid collecing data if no one is interested in it. 75 // It helps to avoid collecing data if no one is interested in it.
74 bool HasEventListeners(const std::string& event_name); 76 bool HasEventListeners(const std::string& event_name);
75 77
76 // Used for tracking registrations to process related notifications. 78 // Used for tracking registrations to process related notifications.
77 content::NotificationRegistrar registrar_; 79 content::NotificationRegistrar registrar_;
78 80
79 Profile* profile_; 81 content::BrowserContext* browser_context_;
80 82
81 // TaskManager to observe for updates. 83 // TaskManager to observe for updates.
82 TaskManagerModel* model_; 84 TaskManagerModel* model_;
83 85
84 // Count of listeners, so we avoid sending updates if no one is interested. 86 // Count of listeners, so we avoid sending updates if no one is interested.
85 int listeners_; 87 int listeners_;
86 88
87 // Indicator whether we've initialized the Task Manager listeners. This is 89 // Indicator whether we've initialized the Task Manager listeners. This is
88 // done once for the lifetime of this object. 90 // done once for the lifetime of this object.
89 bool task_manager_listening_; 91 bool task_manager_listening_;
90 92
91 DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter); 93 DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter);
92 }; 94 };
93 95
94 // The profile-keyed service that manages the processes extension API. 96 // The profile-keyed service that manages the processes extension API.
95 class ProcessesAPI : public ProfileKeyedAPI, 97 class ProcessesAPI : public ProfileKeyedAPI,
96 public EventRouter::Observer { 98 public EventRouter::Observer {
97 public: 99 public:
98 explicit ProcessesAPI(Profile* profile); 100 explicit ProcessesAPI(content::BrowserContext* context);
99 virtual ~ProcessesAPI(); 101 virtual ~ProcessesAPI();
100 102
101 // BrowserContextKeyedService implementation. 103 // BrowserContextKeyedService implementation.
102 virtual void Shutdown() OVERRIDE; 104 virtual void Shutdown() OVERRIDE;
103 105
104 // ProfileKeyedAPI implementation. 106 // ProfileKeyedAPI implementation.
105 static ProfileKeyedAPIFactory<ProcessesAPI>* GetFactoryInstance(); 107 static ProfileKeyedAPIFactory<ProcessesAPI>* GetFactoryInstance();
106 108
107 // Convenience method to get the ProcessesAPI for a profile. 109 // Convenience method to get the ProcessesAPI for a profile.
108 static ProcessesAPI* Get(Profile* profile); 110 static ProcessesAPI* Get(content::BrowserContext* context);
109 111
110 ProcessesEventRouter* processes_event_router(); 112 ProcessesEventRouter* processes_event_router();
111 113
112 // EventRouter::Observer implementation. 114 // EventRouter::Observer implementation.
113 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 115 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
114 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; 116 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
115 117
116 private: 118 private:
117 friend class ProfileKeyedAPIFactory<ProcessesAPI>; 119 friend class ProfileKeyedAPIFactory<ProcessesAPI>;
118 120
119 Profile* profile_; 121 content::BrowserContext* browser_context_;
120 122
121 // ProfileKeyedAPI implementation. 123 // ProfileKeyedAPI implementation.
122 static const char* service_name() { 124 static const char* service_name() {
123 return "ProcessesAPI"; 125 return "ProcessesAPI";
124 } 126 }
125 static const bool kServiceRedirectedInIncognito = true; 127 static const bool kServiceRedirectedInIncognito = true;
126 static const bool kServiceIsNULLWhileTesting = true; 128 static const bool kServiceIsNULLWhileTesting = true;
127 129
128 // Created lazily on first access. 130 // Created lazily on first access.
129 scoped_ptr<ProcessesEventRouter> processes_event_router_; 131 scoped_ptr<ProcessesEventRouter> processes_event_router_;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool memory_; 191 bool memory_;
190 #endif 192 #endif
191 193
192 DECLARE_EXTENSION_FUNCTION("processes.getProcessInfo", 194 DECLARE_EXTENSION_FUNCTION("processes.getProcessInfo",
193 PROCESSES_GETPROCESSINFO) 195 PROCESSES_GETPROCESSINFO)
194 }; 196 };
195 197
196 } // namespace extensions 198 } // namespace extensions
197 199
198 #endif // CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ 200 #endif // CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/preference/preference_api.cc ('k') | chrome/browser/extensions/api/processes/processes_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698