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