| 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_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/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 13 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
| 14 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 15 #include "chrome/browser/task_manager/task_manager.h" | 16 #include "chrome/browser/task_manager/task_manager.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/render_widget_host.h" | 19 #include "content/public/browser/render_widget_host.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 int listeners_; | 85 int listeners_; |
| 85 | 86 |
| 86 // Indicator whether we've initialized the Task Manager listeners. This is | 87 // Indicator whether we've initialized the Task Manager listeners. This is |
| 87 // done once for the lifetime of this object. | 88 // done once for the lifetime of this object. |
| 88 bool task_manager_listening_; | 89 bool task_manager_listening_; |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter); | 91 DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // The profile-keyed service that manages the processes extension API. | 94 // The profile-keyed service that manages the processes extension API. |
| 94 class ProcessesAPI : public ProfileKeyedService, | 95 class ProcessesAPI : public ProfileKeyedAPI, |
| 95 public EventRouter::Observer { | 96 public EventRouter::Observer { |
| 96 public: | 97 public: |
| 97 explicit ProcessesAPI(Profile* profile); | 98 explicit ProcessesAPI(Profile* profile); |
| 98 virtual ~ProcessesAPI(); | 99 virtual ~ProcessesAPI(); |
| 99 | 100 |
| 100 // ProfileKeyedService implementation. | 101 // ProfileKeyedService implementation. |
| 101 virtual void Shutdown() OVERRIDE; | 102 virtual void Shutdown() OVERRIDE; |
| 102 | 103 |
| 103 // Convenience method to get the ProcessesAPI for a profile. | 104 // Convenience method to get the ProcessesAPI for a profile. |
| 104 static ProcessesAPI* Get(Profile* profile); | 105 static ProcessesAPI* Get(Profile* profile); |
| 105 | 106 |
| 106 ProcessesEventRouter* processes_event_router(); | 107 ProcessesEventRouter* processes_event_router(); |
| 107 | 108 |
| 108 // EventRouter::Observer implementation. | 109 // EventRouter::Observer implementation. |
| 109 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 110 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 110 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; | 111 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; |
| 111 | 112 |
| 112 private: | 113 private: |
| 114 friend class ProfileKeyedAPIFactory<ProcessesAPI>; |
| 115 |
| 113 Profile* profile_; | 116 Profile* profile_; |
| 114 | 117 |
| 118 // ProfileKeyedAPI implementation. |
| 119 static const char* service_name() { |
| 120 return "ProcessesAPI"; |
| 121 } |
| 122 static const bool kServiceRedirectedInIncognito = true; |
| 123 static const bool kServiceIsNULLWhileTesting = true; |
| 124 |
| 115 // Created lazily on first access. | 125 // Created lazily on first access. |
| 116 scoped_ptr<ProcessesEventRouter> processes_event_router_; | 126 scoped_ptr<ProcessesEventRouter> processes_event_router_; |
| 117 }; | 127 }; |
| 118 | 128 |
| 129 template <> |
| 130 ProfileKeyedAPIFactory<ProcessesAPI>* |
| 131 ProfileKeyedAPIFactory<ProcessesAPI>::GetInstance(); |
| 132 |
| 119 // This extension function returns the Process object for the renderer process | 133 // This extension function returns the Process object for the renderer process |
| 120 // currently in use by the specified Tab. | 134 // currently in use by the specified Tab. |
| 121 class GetProcessIdForTabFunction : public AsyncExtensionFunction, | 135 class GetProcessIdForTabFunction : public AsyncExtensionFunction, |
| 122 public content::NotificationObserver { | 136 public content::NotificationObserver { |
| 123 public: | 137 public: |
| 124 GetProcessIdForTabFunction(); | 138 GetProcessIdForTabFunction(); |
| 125 | 139 |
| 126 private: | 140 private: |
| 127 virtual ~GetProcessIdForTabFunction() {} | 141 virtual ~GetProcessIdForTabFunction() {} |
| 128 virtual bool RunImpl() OVERRIDE; | 142 virtual bool RunImpl() OVERRIDE; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 #if defined(ENABLE_TASK_MANAGER) | 210 #if defined(ENABLE_TASK_MANAGER) |
| 197 bool memory_; | 211 bool memory_; |
| 198 #endif | 212 #endif |
| 199 | 213 |
| 200 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo") | 214 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo") |
| 201 }; | 215 }; |
| 202 | 216 |
| 203 } // namespace extensions | 217 } // namespace extensions |
| 204 | 218 |
| 205 #endif // CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ | 219 #endif // CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ |
| OLD | NEW |