Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Unified Diff: chrome/browser/extensions/extension_processes_api.h

Issue 10175008: Improving the process model extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_processes_api.h
diff --git a/chrome/browser/extensions/extension_processes_api.h b/chrome/browser/extensions/extension_processes_api.h
index c77099e359cc92b7e277578501448d91d15cd33d..c0a6daa071fa6cf9b4f22cbcec62b43b8492ef6c 100644
--- a/chrome/browser/extensions/extension_processes_api.h
+++ b/chrome/browser/extensions/extension_processes_api.h
@@ -12,10 +12,13 @@
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_widget_host.h"
// Observes the Task Manager and routes the notifications as events to the
// extension system.
-class ExtensionProcessesEventRouter : public TaskManagerModelObserver {
+class ExtensionProcessesEventRouter : public TaskManagerModelObserver,
+ public content::NotificationObserver {
public:
// Single instance of the event router.
static ExtensionProcessesEventRouter* GetInstance();
@@ -38,13 +41,31 @@ class ExtensionProcessesEventRouter : public TaskManagerModelObserver {
// TaskManagerModelObserver methods.
virtual void OnModelChanged() OVERRIDE {}
virtual void OnItemsChanged(int start, int length) OVERRIDE;
- virtual void OnItemsAdded(int start, int length) OVERRIDE {}
+ virtual void OnItemsAdded(int start, int length) OVERRIDE;
+ virtual void OnItemsToBeRemoved(int start, int length) OVERRIDE;
virtual void OnItemsRemoved(int start, int length) OVERRIDE {}
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ private:
+ void NotifyProfiles(const char* event_name, std::string json_args);
+
void DispatchEvent(Profile* profile,
const char* event_name,
const std::string& json_args);
+ // Determines whether there is a registered listener for the specified event.
+ // 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.
+ bool HasEventListeners(std::string& event_name);
+
+ void ProcessHangEvent(content::RenderWidgetHost* widget);
+ void ProcessClosedEvent(
+ content::RenderProcessHost* rph,
+ content::RenderProcessHost::RendererClosedDetails* details);
+
// Used for tracking registrations to process related notifications.
content::NotificationRegistrar registrar_;
@@ -55,6 +76,9 @@ class ExtensionProcessesEventRouter : public TaskManagerModelObserver {
// TaskManager to observe for updates.
TaskManagerModel* model_;
+ // Count of listeners, so we avoid sending updates if noone is interested.
+ int listeners_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionProcessesEventRouter);
};
@@ -67,4 +91,23 @@ class GetProcessIdForTabFunction : public SyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessIdForTab")
};
+// Extension function that allows terminating Chrome subprocesses, by supplying
+// the unique ID for the process coming from the ChildProcess ID pool.
+// Using unique IDs instead of OS process IDs allows two advantages:
+// * guaranteed uniqueness, since OS process IDs can be reused
+// * guards against killing non-Chrome processes
Charlie Reis 2012/04/23 22:19:51 Nice.
nasko 2012/04/24 18:14:29 Done.
+class TerminateFunction : public SyncExtensionFunction {
+ virtual ~TerminateFunction() {}
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.terminate")
+};
+
+// Extension function which returns a set of Process objects, containing the
+// details corresponding to the process IDs supplied as input.
+class GetProcessInfoFunction : public SyncExtensionFunction {
+ virtual ~GetProcessInfoFunction() {}
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo")
+};
+
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESSES_API_H__

Powered by Google App Engine
This is Rietveld 408576698