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/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 #include "content/public/browser/render_process_host.h" | |
16 #include "content/public/browser/render_widget_host.h" | |
15 | 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, |
21 public content::NotificationObserver { | |
19 public: | 22 public: |
20 // Single instance of the event router. | 23 // Single instance of the event router. |
21 static ExtensionProcessesEventRouter* GetInstance(); | 24 static ExtensionProcessesEventRouter* GetInstance(); |
22 | 25 |
23 // Safe to call multiple times. | 26 // Safe to call multiple times. |
24 void ObserveProfile(Profile* profile); | 27 void ObserveProfile(Profile* profile); |
25 | 28 |
26 // Called when an extension process wants to listen to process events. | 29 // Called when an extension process wants to listen to process events. |
27 void ListenerAdded(); | 30 void ListenerAdded(); |
28 | 31 |
29 // Called when an extension process with a listener exits or removes it. | 32 // Called when an extension process with a listener exits or removes it. |
30 void ListenerRemoved(); | 33 void ListenerRemoved(); |
31 | 34 |
32 private: | 35 private: |
33 friend struct DefaultSingletonTraits<ExtensionProcessesEventRouter>; | 36 friend struct DefaultSingletonTraits<ExtensionProcessesEventRouter>; |
34 | 37 |
35 ExtensionProcessesEventRouter(); | 38 ExtensionProcessesEventRouter(); |
36 virtual ~ExtensionProcessesEventRouter(); | 39 virtual ~ExtensionProcessesEventRouter(); |
37 | 40 |
38 // TaskManagerModelObserver methods. | 41 // TaskManagerModelObserver methods. |
39 virtual void OnModelChanged() OVERRIDE {} | 42 virtual void OnModelChanged() OVERRIDE {} |
40 virtual void OnItemsChanged(int start, int length) OVERRIDE; | 43 virtual void OnItemsChanged(int start, int length) OVERRIDE; |
41 virtual void OnItemsAdded(int start, int length) OVERRIDE {} | 44 virtual void OnItemsAdded(int start, int length) OVERRIDE; |
45 virtual void OnItemsToBeRemoved(int start, int length) OVERRIDE; | |
42 virtual void OnItemsRemoved(int start, int length) OVERRIDE {} | 46 virtual void OnItemsRemoved(int start, int length) OVERRIDE {} |
43 | 47 |
48 // content::NotificationObserver implementation. | |
49 virtual void Observe(int type, | |
50 const content::NotificationSource& source, | |
51 const content::NotificationDetails& details) OVERRIDE; | |
52 | |
53 private: | |
54 void NotifyProfiles(const char* event_name, std::string json_args); | |
55 | |
44 void DispatchEvent(Profile* profile, | 56 void DispatchEvent(Profile* profile, |
45 const char* event_name, | 57 const char* event_name, |
46 const std::string& json_args); | 58 const std::string& json_args); |
47 | 59 |
60 // Determines whether there is a registered listener for the specified event. | |
61 // It helps to avoid collecing data if noone is interested in it. | |
Charlie Reis
2012/04/23 22:19:51
Nit: noone -> no one (here and below)
nasko
2012/04/24 18:14:29
Done.
| |
62 bool HasEventListeners(std::string& event_name); | |
63 | |
64 void ProcessHangEvent(content::RenderWidgetHost* widget); | |
65 void ProcessClosedEvent( | |
66 content::RenderProcessHost* rph, | |
67 content::RenderProcessHost::RendererClosedDetails* details); | |
68 | |
48 // Used for tracking registrations to process related notifications. | 69 // Used for tracking registrations to process related notifications. |
49 content::NotificationRegistrar registrar_; | 70 content::NotificationRegistrar registrar_; |
50 | 71 |
51 // Registered profiles. | 72 // Registered profiles. |
52 typedef std::set<Profile*> ProfileSet; | 73 typedef std::set<Profile*> ProfileSet; |
53 ProfileSet profiles_; | 74 ProfileSet profiles_; |
54 | 75 |
55 // TaskManager to observe for updates. | 76 // TaskManager to observe for updates. |
56 TaskManagerModel* model_; | 77 TaskManagerModel* model_; |
57 | 78 |
79 // Count of listeners, so we avoid sending updates if noone is interested. | |
80 int listeners_; | |
81 | |
58 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessesEventRouter); | 82 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessesEventRouter); |
59 }; | 83 }; |
60 | 84 |
61 | 85 |
62 // This extension function returns the Process object for the renderer process | 86 // This extension function returns the Process object for the renderer process |
63 // currently in use by the specified Tab. | 87 // currently in use by the specified Tab. |
64 class GetProcessIdForTabFunction : public SyncExtensionFunction { | 88 class GetProcessIdForTabFunction : public SyncExtensionFunction { |
65 virtual ~GetProcessIdForTabFunction() {} | 89 virtual ~GetProcessIdForTabFunction() {} |
66 virtual bool RunImpl() OVERRIDE; | 90 virtual bool RunImpl() OVERRIDE; |
67 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessIdForTab") | 91 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessIdForTab") |
68 }; | 92 }; |
69 | 93 |
94 // Extension function that allows terminating Chrome subprocesses, by supplying | |
95 // the unique ID for the process coming from the ChildProcess ID pool. | |
96 // Using unique IDs instead of OS process IDs allows two advantages: | |
97 // * guaranteed uniqueness, since OS process IDs can be reused | |
98 // * guards against killing non-Chrome processes | |
Charlie Reis
2012/04/23 22:19:51
Nice.
nasko
2012/04/24 18:14:29
Done.
| |
99 class TerminateFunction : public SyncExtensionFunction { | |
100 virtual ~TerminateFunction() {} | |
101 virtual bool RunImpl() OVERRIDE; | |
102 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.terminate") | |
103 }; | |
104 | |
105 // Extension function which returns a set of Process objects, containing the | |
106 // details corresponding to the process IDs supplied as input. | |
107 class GetProcessInfoFunction : public SyncExtensionFunction { | |
108 virtual ~GetProcessInfoFunction() {} | |
109 virtual bool RunImpl() OVERRIDE; | |
110 DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo") | |
111 }; | |
112 | |
70 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ | 113 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__ |
OLD | NEW |