#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
#define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
#include <map>
#include <string>
#include "ash/shelf/scoped_observer_with_duplicated_sources.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/scoped_observer.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/display_observer.h"
#include "ui/wm/public/activation_change_observer.h"
namespace aura {
class Window;
namespace client {
class ActivationClient;
}
}
class Browser;
class BrowserStatusMonitor : public aura::client::ActivationChangeObserver,
public aura::WindowObserver,
public chrome::BrowserListObserver,
public gfx::DisplayObserver,
public TabStripModelObserver {
public:
explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller);
virtual ~BrowserStatusMonitor();
virtual void ActiveUserChanged(const std::string& user_email) {}
void UpdateAppItemState(content::WebContents* contents,
ChromeLauncherController::AppState app_state);
void UpdateBrowserItemState();
virtual void OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
virtual void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) OVERRIDE;
virtual void TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) OVERRIDE;
virtual void TabInsertedAt(content::WebContents* contents,
int index,
bool foreground) OVERRIDE;
virtual void TabClosingAt(TabStripModel* tab_strip_mode,
content::WebContents* contents,
int index) OVERRIDE;
void WebContentsDestroyed(content::WebContents* web_contents);
protected:
virtual void AddV1AppToShelf(Browser* browser);
virtual void RemoveV1AppFromShelf(Browser* browser);
bool IsV1AppInShelf(Browser* browser);
private:
class LocalWebContentsObserver : public content::WebContentsObserver {
public:
LocalWebContentsObserver(content::WebContents* contents,
BrowserStatusMonitor* monitor);
virtual ~LocalWebContentsObserver();
virtual void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
virtual void WebContentsDestroyed(
content::WebContents* web_contents) OVERRIDE;
private:
BrowserStatusMonitor* monitor_;
DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver);
};
typedef std::map<Browser*, std::string> BrowserToAppIDMap;
typedef std::map<content::WebContents*, LocalWebContentsObserver*>
WebContentsToObserverMap;
void AddWebContentsObserver(content::WebContents* contents);
void RemoveWebContentsObserver(content::WebContents* contents);
ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents);
ChromeLauncherController* launcher_controller_;
ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
aura::client::ActivationChangeObserver> observed_activation_clients_;
ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
BrowserToAppIDMap browser_to_app_id_map_;
WebContentsToObserverMap webcontents_to_observer_map_;
DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
};
#endif