| 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_EXTENSION_PROCESSES_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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 "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "chrome/browser/task_manager/task_manager.h" | 12 #include "chrome/browser/task_manager/task_manager.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_widget_host.h" | 15 #include "content/public/browser/render_widget_host.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class ListValue; | 18 class ListValue; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace extensions { |
| 22 |
| 21 // Observes the Task Manager and routes the notifications as events to the | 23 // Observes the Task Manager and routes the notifications as events to the |
| 22 // extension system. | 24 // extension system. |
| 23 class ExtensionProcessesEventRouter : public TaskManagerModelObserver, | 25 class ProcessesEventRouter : public TaskManagerModelObserver, |
| 24 public content::NotificationObserver { | 26 public content::NotificationObserver { |
| 25 public: | 27 public: |
| 26 // Single instance of the event router. | 28 // Single instance of the event router. |
| 27 static ExtensionProcessesEventRouter* GetInstance(); | 29 static ProcessesEventRouter* GetInstance(); |
| 28 | 30 |
| 29 // Safe to call multiple times. | 31 // Safe to call multiple times. |
| 30 void ObserveProfile(Profile* profile); | 32 void ObserveProfile(Profile* profile); |
| 31 | 33 |
| 32 // Called when an extension process wants to listen to process events. | 34 // Called when an extension process wants to listen to process events. |
| 33 void ListenerAdded(); | 35 void ListenerAdded(); |
| 34 | 36 |
| 35 // Called when an extension process with a listener exits or removes it. | 37 // Called when an extension process with a listener exits or removes it. |
| 36 void ListenerRemoved(); | 38 void ListenerRemoved(); |
| 37 | 39 |
| 38 // Called on the first invocation of extension API function. This will call | 40 // Called on the first invocation of extension API function. This will call |
| 39 // out to the Task Manager to start listening for notifications. Returns | 41 // out to the Task Manager to start listening for notifications. Returns |
| 40 // true if this was the first call and false if this has already been called. | 42 // true if this was the first call and false if this has already been called. |
| 41 void StartTaskManagerListening(); | 43 void StartTaskManagerListening(); |
| 42 | 44 |
| 43 bool is_task_manager_listening() { return task_manager_listening_; } | 45 bool is_task_manager_listening() { return task_manager_listening_; } |
| 44 int num_listeners() { return listeners_; } | 46 int num_listeners() { return listeners_; } |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 friend struct DefaultSingletonTraits<ExtensionProcessesEventRouter>; | 49 friend struct DefaultSingletonTraits<ProcessesEventRouter>; |
| 48 | 50 |
| 49 ExtensionProcessesEventRouter(); | 51 ProcessesEventRouter(); |
| 50 virtual ~ExtensionProcessesEventRouter(); | 52 virtual ~ProcessesEventRouter(); |
| 51 | 53 |
| 52 // content::NotificationObserver implementation. | 54 // content::NotificationObserver implementation. |
| 53 virtual void Observe(int type, | 55 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; | 57 const content::NotificationDetails& details) OVERRIDE; |
| 56 | 58 |
| 57 // TaskManagerModelObserver methods. | 59 // TaskManagerModelObserver methods. |
| 58 virtual void OnItemsAdded(int start, int length) OVERRIDE; | 60 virtual void OnItemsAdded(int start, int length) OVERRIDE; |
| 59 virtual void OnModelChanged() OVERRIDE {} | 61 virtual void OnModelChanged() OVERRIDE {} |
| 60 virtual void OnItemsChanged(int start, int length) OVERRIDE; | 62 virtual void OnItemsChanged(int start, int length) OVERRIDE; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 88 // TaskManager to observe for updates. | 90 // TaskManager to observe for updates. |
| 89 TaskManagerModel* model_; | 91 TaskManagerModel* model_; |
| 90 | 92 |
| 91 // Count of listeners, so we avoid sending updates if no one is interested. | 93 // Count of listeners, so we avoid sending updates if no one is interested. |
| 92 int listeners_; | 94 int listeners_; |
| 93 | 95 |
| 94 // Indicator whether we've initialized the Task Manager listeners. This is | 96 // Indicator whether we've initialized the Task Manager listeners. This is |
| 95 // done once for the lifetime of this object. | 97 // done once for the lifetime of this object. |
| 96 bool task_manager_listening_; | 98 bool task_manager_listening_; |
| 97 | 99 |
| 98 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessesEventRouter); | 100 DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter); |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 | 103 |
| 102 // This extension function returns the Process object for the renderer process | 104 // This extension function returns the Process object for the renderer process |
| 103 // currently in use by the specified Tab. | 105 // currently in use by the specified Tab. |
| 104 class GetProcessIdForTabFunction : public AsyncExtensionFunction, | 106 class GetProcessIdForTabFunction : public AsyncExtensionFunction, |
| 105 public content::NotificationObserver { | 107 public content::NotificationObserver { |
| 106 private: | 108 private: |
| 107 virtual ~GetProcessIdForTabFunction() {} | 109 virtual ~GetProcessIdForTabFunction() {} |
| 108 virtual bool RunImpl() OVERRIDE; | 110 virtual bool RunImpl() OVERRIDE; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 170 |
| 169 content::NotificationRegistrar registrar_; | 171 content::NotificationRegistrar registrar_; |
| 170 | 172 |
| 171 // Member variables to store the function parameters | 173 // Member variables to store the function parameters |
| 172 std::vector<int> process_ids_; | 174 std::vector<int> process_ids_; |
| 173 bool memory_; | 175 bool memory_; |
| 174 | 176 |
| 175 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo") | 177 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo") |
| 176 }; | 178 }; |
| 177 | 179 |
| 178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ | 180 } // namespace extensions |
| 181 |
| 182 #endif // CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__ |
| OLD | NEW |