#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
#include <map>
#include <set>
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "chrome/common/view_type.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Browser;
class GURL;
class Profile;
namespace content {
class RenderViewHost;
class SiteInstance;
};
namespace extensions {
class Extension;
class ExtensionHost;
}
class ExtensionProcessManager : public content::NotificationObserver {
public:
typedef std::set<extensions::ExtensionHost*> ExtensionHostSet;
typedef ExtensionHostSet::const_iterator const_iterator;
static ExtensionProcessManager* Create(Profile* profile);
virtual ~ExtensionProcessManager();
const ExtensionHostSet& background_hosts() const {
return background_hosts_;
}
typedef std::set<content::RenderViewHost*> ViewSet;
const ViewSet GetAllViews() const;
virtual extensions::ExtensionHost* CreateViewHost(
const extensions::Extension* extension,
const GURL& url,
Browser* browser,
chrome::ViewType view_type);
extensions::ExtensionHost* CreateViewHost(const GURL& url,
Browser* browser,
chrome::ViewType view_type);
extensions::ExtensionHost* CreatePopupHost(
const extensions::Extension* extension,
const GURL& url,
Browser* browser);
extensions::ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser);
extensions::ExtensionHost* CreateDialogHost(const GURL& url);
extensions::ExtensionHost* CreateInfobarHost(
const extensions::Extension* extension,
const GURL& url,
Browser* browser);
extensions::ExtensionHost* CreateInfobarHost(const GURL& url,
Browser* browser);
void OpenOptionsPage(const extensions::Extension* extension,
Browser* browser);
virtual void CreateBackgroundHost(const extensions::Extension* extension,
const GURL& url);
extensions::ExtensionHost* GetBackgroundHostForExtension(
const std::string& extension_id);
virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url);
void RegisterRenderViewHost(content::RenderViewHost* render_view_host,
const extensions::Extension* extension);
void UnregisterRenderViewHost(content::RenderViewHost* render_view_host);
std::set<content::RenderViewHost*> GetRenderViewHostsForExtension(
const std::string& extension_id);
const extensions::Extension* GetExtensionForRenderViewHost(
content::RenderViewHost* render_view_host);
bool IsBackgroundHostClosing(const std::string& extension_id);
int GetLazyKeepaliveCount(const extensions::Extension* extension);
int IncrementLazyKeepaliveCount(const extensions::Extension* extension);
int DecrementLazyKeepaliveCount(const extensions::Extension* extension);
void IncrementLazyKeepaliveCountForView(
content::RenderViewHost* render_view_host);
void OnShouldUnloadAck(const std::string& extension_id, int sequence_id);
void OnUnloadAck(const std::string& extension_id);
void OnNetworkRequestStarted(content::RenderViewHost* render_view_host);
void OnNetworkRequestDone(content::RenderViewHost* render_view_host);
void CancelSuspend(const extensions::Extension* extension);
protected:
explicit ExtensionProcessManager(Profile* profile);
void OnExtensionHostCreated(extensions::ExtensionHost* host,
bool is_background);
void CloseBackgroundHosts();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
Profile* GetProfile() const;
content::NotificationRegistrar registrar_;
ExtensionHostSet background_hosts_;
scoped_refptr<content::SiteInstance> site_instance_;
private:
struct BackgroundPageData;
typedef std::string ExtensionId;
typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap;
typedef std::map<content::RenderViewHost*,
chrome::ViewType> ExtensionRenderViews;
ExtensionRenderViews all_extension_views_;
void CloseBackgroundHost(extensions::ExtensionHost* host);
void EnsureBrowserWhenRequired(Browser* browser,
chrome::ViewType view_type);
void OnLazyBackgroundPageIdle(const std::string& extension_id,
int sequence_id);
void OnLazyBackgroundPageActive(const std::string& extension_id);
void CloseLazyBackgroundPageNow(const std::string& extension_id,
int sequence_id);
void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host);
void ClearBackgroundPageData(const std::string& extension_id);
BackgroundPageDataMap background_page_data_;
base::TimeDelta event_page_idle_time_;
base::TimeDelta event_page_unloading_time_;
base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
};
#endif