#ifndef CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__
#define CHROME_BROWSER_EXTENSIONS_API_PROCESSES_PROCESSES_API_H__
#include <set>
#include <string>
#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"
namespace base {
class ListValue;
}
namespace extensions {
class ProcessesEventRouter : public TaskManagerModelObserver,
public content::NotificationObserver {
public:
static ProcessesEventRouter* GetInstance();
void ObserveProfile(Profile* profile);
void ListenerAdded();
void ListenerRemoved();
void StartTaskManagerListening();
bool is_task_manager_listening() { return task_manager_listening_; }
int num_listeners() { return listeners_; }
private:
friend struct DefaultSingletonTraits<ProcessesEventRouter>;
ProcessesEventRouter();
virtual ~ProcessesEventRouter();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
virtual void OnItemsAdded(int start, int length) OVERRIDE;
virtual void OnModelChanged() OVERRIDE {}
virtual void OnItemsChanged(int start, int length) OVERRIDE;
virtual void OnItemsRemoved(int start, int length) OVERRIDE {}
virtual void OnItemsToBeRemoved(int start, int length) OVERRIDE;
void ProcessHangEvent(content::RenderWidgetHost* widget);
void ProcessClosedEvent(
content::RenderProcessHost* rph,
content::RenderProcessHost::RendererClosedDetails* details);
void NotifyProfiles(const char* event_name,
scoped_ptr<base::ListValue> event_args);
void DispatchEvent(Profile* profile,
const char* event_name,
scoped_ptr<base::ListValue> event_args);
bool HasEventListeners(std::string& event_name);
content::NotificationRegistrar registrar_;
typedef std::set<Profile*> ProfileSet;
ProfileSet profiles_;
TaskManagerModel* model_;
int listeners_;
bool task_manager_listening_;
DISALLOW_COPY_AND_ASSIGN(ProcessesEventRouter);
};
class GetProcessIdForTabFunction : public AsyncExtensionFunction,
public content::NotificationObserver {
private:
virtual ~GetProcessIdForTabFunction() {}
virtual bool RunImpl() OVERRIDE;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void GetProcessIdForTab();
content::NotificationRegistrar registrar_;
int tab_id_;
DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessIdForTab")
};
class TerminateFunction : public AsyncExtensionFunction,
public content::NotificationObserver {
private:
virtual ~TerminateFunction() {}
virtual bool RunImpl() OVERRIDE;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void TerminateProcess();
content::NotificationRegistrar registrar_;
int process_id_;
DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.terminate")
};
class GetProcessInfoFunction : public AsyncExtensionFunction,
public content::NotificationObserver {
public:
GetProcessInfoFunction();
private:
virtual ~GetProcessInfoFunction();
virtual bool RunImpl() OVERRIDE;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void GatherProcessInfo();
content::NotificationRegistrar registrar_;
std::vector<int> process_ids_;
#if defined(ENABLE_TASK_MANAGER)
bool memory_;
#endif
DECLARE_EXTENSION_FUNCTION_NAME("experimental.processes.getProcessInfo")
};
}
#endif