#ifndef APPS_APP_WINDOW_REGISTRY_H_
#define APPS_APP_WINDOW_REGISTRY_H_
#include <list>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "ui/gfx/native_widget_types.h"
namespace content {
class BrowserContext;
class DevToolsAgentHost;
class RenderViewHost;
}
namespace apps {
class AppWindow;
class AppWindowRegistry : public KeyedService {
public:
class Observer {
public:
virtual void OnAppWindowAdded(apps::AppWindow* app_window) = 0;
virtual void OnAppWindowIconChanged(apps::AppWindow* app_window) = 0;
virtual void OnAppWindowRemoved(apps::AppWindow* app_window) = 0;
protected:
virtual ~Observer() {}
};
typedef std::list<apps::AppWindow*> AppWindowList;
typedef AppWindowList::const_iterator const_iterator;
typedef std::set<std::string> InspectedWindowSet;
explicit AppWindowRegistry(content::BrowserContext* context);
virtual ~AppWindowRegistry();
static AppWindowRegistry* Get(content::BrowserContext* context);
void AddAppWindow(apps::AppWindow* app_window);
void AppWindowIconChanged(apps::AppWindow* app_window);
void AppWindowActivated(apps::AppWindow* app_window);
void RemoveAppWindow(apps::AppWindow* app_window);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
AppWindowList GetAppWindowsForApp(const std::string& app_id) const;
const AppWindowList& app_windows() const { return app_windows_; }
void CloseAllAppWindowsForApp(const std::string& app_id);
apps::AppWindow* GetAppWindowForRenderViewHost(
content::RenderViewHost* render_view_host) const;
apps::AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const;
apps::AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const;
apps::AppWindow* GetAppWindowForAppAndKey(const std::string& app_id,
const std::string& window_key)
const;
bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const;
static apps::AppWindow* GetAppWindowForNativeWindowAnyProfile(
gfx::NativeWindow window);
static bool IsAppWindowRegisteredInAnyProfile(int window_type_mask);
class Factory : public BrowserContextKeyedServiceFactory {
public:
static AppWindowRegistry* GetForBrowserContext(
content::BrowserContext* context,
bool create);
static Factory* GetInstance();
private:
friend struct DefaultSingletonTraits<Factory>;
Factory();
virtual ~Factory();
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const OVERRIDE;
virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
virtual content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const OVERRIDE;
};
protected:
void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
private:
void AddAppWindowToList(apps::AppWindow* app_window);
void BringToFront(apps::AppWindow* app_window);
content::BrowserContext* context_;
AppWindowList app_windows_;
InspectedWindowSet inspected_windows_;
ObserverList<Observer> observers_;
base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
};
}
#endif