OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EXTENSION_PROCESSES_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
9 #include "chrome/browser/extensions/extension_function.h" | 12 #include "chrome/browser/extensions/extension_function.h" |
| 13 #include "chrome/browser/task_manager/task_manager.h" |
| 14 #include "chrome/common/notification_observer.h" |
| 15 #include "chrome/common/notification_registrar.h" |
| 16 |
| 17 // Observes the Task Manager and routes the notifications as events to the |
| 18 // extension system. |
| 19 class ExtensionProcessesEventRouter : public TaskManagerModelObserver { |
| 20 public: |
| 21 // Single instance of the event router. |
| 22 static ExtensionProcessesEventRouter* GetInstance(); |
| 23 |
| 24 // Safe to call multiple times. |
| 25 void ObserveProfile(Profile* profile); |
| 26 |
| 27 // Called when an extension process wants to listen to process events. |
| 28 void ListenerAdded(); |
| 29 |
| 30 // Called when an extension process with a listener exits or removes it. |
| 31 void ListenerRemoved(); |
| 32 |
| 33 private: |
| 34 friend struct DefaultSingletonTraits<ExtensionProcessesEventRouter>; |
| 35 |
| 36 ExtensionProcessesEventRouter(); |
| 37 virtual ~ExtensionProcessesEventRouter(); |
| 38 |
| 39 // TaskManagerModelObserver::OnModelChanged. |
| 40 virtual void OnModelChanged() {} |
| 41 |
| 42 // TaskManagerModelObserver::OnItemsChanged. |
| 43 virtual void OnItemsChanged(int start, int length); |
| 44 |
| 45 // TaskManagerModelObserver::OnItemsAdded. |
| 46 virtual void OnItemsAdded(int start, int length) {} |
| 47 |
| 48 // TaskManagerModelObserver::OnItemsRemoved. |
| 49 virtual void OnItemsRemoved(int start, int length) {} |
| 50 |
| 51 void DispatchEvent(Profile* profile, |
| 52 const char* event_name, |
| 53 const std::string& json_args); |
| 54 |
| 55 // Used for tracking registrations to process related notifications. |
| 56 NotificationRegistrar registrar_; |
| 57 |
| 58 // Registered profiles. |
| 59 typedef std::set<Profile*> ProfileSet; |
| 60 ProfileSet profiles_; |
| 61 |
| 62 // TaskManager to observe for updates. |
| 63 TaskManagerModel* model_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessesEventRouter); |
| 66 }; |
| 67 |
10 | 68 |
11 // This extension function returns the Process object for the renderer process | 69 // This extension function returns the Process object for the renderer process |
12 // currently in use by the specified Tab. | 70 // currently in use by the specified Tab. |
13 class GetProcessForTabFunction : public SyncExtensionFunction { | 71 class GetProcessForTabFunction : public SyncExtensionFunction { |
14 virtual ~GetProcessForTabFunction() {} | 72 virtual ~GetProcessForTabFunction() {} |
15 virtual bool RunImpl(); | 73 virtual bool RunImpl(); |
16 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessForTab") | 74 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessIdForTab") |
17 }; | 75 }; |
18 | 76 |
19 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ | 77 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ |
OLD | NEW |