Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / browser_status_monitor.h
blobe7671bae4dd48ff034194170376711dd0d3a4023
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
8 #include <map>
9 #include <string>
11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/scoped_observer.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/browser_list_observer.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
18 #include "ui/aura/window_observer.h"
19 #include "ui/gfx/display_observer.h"
20 #include "ui/wm/public/activation_change_observer.h"
22 namespace aura {
23 class Window;
25 namespace client {
26 class ActivationClient;
28 } // namespace aura
30 class Browser;
32 // BrowserStatusMonitor monitors creation/deletion of Browser and its
33 // TabStripModel to keep the launcher representation up to date as the
34 // active tab changes.
35 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver,
36 public aura::WindowObserver,
37 public chrome::BrowserListObserver,
38 public gfx::DisplayObserver,
39 public TabStripModelObserver {
40 public:
41 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller);
42 ~BrowserStatusMonitor() override;
44 // A function which gets called when the current user has changed.
45 // Note that this function is called by the ChromeLauncherController to be
46 // able to do the activation in a proper order - rather then setting an
47 // observer.
48 virtual void ActiveUserChanged(const std::string& user_email) {}
50 // A shortcut to call the ChromeLauncherController's UpdateAppState().
51 void UpdateAppItemState(content::WebContents* contents,
52 ChromeLauncherController::AppState app_state);
54 // A shortcut to call the BrowserShortcutLauncherItemController's
55 // UpdateBrowserItemState().
56 void UpdateBrowserItemState();
58 // aura::client::ActivationChangeObserver overrides:
59 void OnWindowActivated(
60 aura::client::ActivationChangeObserver::ActivationReason reason,
61 aura::Window* gained_active,
62 aura::Window* lost_active) override;
64 // aura::WindowObserver overrides:
65 void OnWindowDestroyed(aura::Window* window) override;
67 // chrome::BrowserListObserver overrides:
68 void OnBrowserAdded(Browser* browser) override;
69 void OnBrowserRemoved(Browser* browser) override;
71 // gfx::DisplayObserver overrides:
72 void OnDisplayAdded(const gfx::Display& new_display) override;
73 void OnDisplayRemoved(const gfx::Display& old_display) override;
74 void OnDisplayMetricsChanged(const gfx::Display& display,
75 uint32_t metrics) override;
77 // TabStripModelObserver overrides:
78 void ActiveTabChanged(content::WebContents* old_contents,
79 content::WebContents* new_contents,
80 int index,
81 int reason) override;
82 void TabReplacedAt(TabStripModel* tab_strip_model,
83 content::WebContents* old_contents,
84 content::WebContents* new_contents,
85 int index) override;
86 void TabInsertedAt(content::WebContents* contents,
87 int index,
88 bool foreground) override;
89 void TabClosingAt(TabStripModel* tab_strip_mode,
90 content::WebContents* contents,
91 int index) override;
93 // Called from our own |LocalWebContentsObserver| when web contents did go
94 // away without any other notification. This might happen in case of
95 // application uninstalls, page crashes, ...).
96 void WebContentsDestroyed(content::WebContents* web_contents);
98 protected:
99 // Add a V1 application to the shelf. This can get overwritten for multi
100 // profile implementations.
101 virtual void AddV1AppToShelf(Browser* browser);
103 // Remove a V1 application from the shelf. This can get overwritten for multi
104 // profile implementations.
105 virtual void RemoveV1AppFromShelf(Browser* browser);
107 // Check if V1 application is currently in the shelf.
108 bool IsV1AppInShelf(Browser* browser);
110 private:
111 class LocalWebContentsObserver;
112 class SettingsWindowObserver;
114 typedef std::map<Browser*, std::string> BrowserToAppIDMap;
115 typedef std::map<content::WebContents*, LocalWebContentsObserver*>
116 WebContentsToObserverMap;
118 // Create LocalWebContentsObserver for |contents|.
119 void AddWebContentsObserver(content::WebContents* contents);
121 // Remove LocalWebContentsObserver for |contents|.
122 void RemoveWebContentsObserver(content::WebContents* contents);
124 // Returns the ShelfID for |contents|.
125 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents);
127 // Sets the shelf id for browsers represented by the browser shortcut item.
128 void SetShelfIDForBrowserWindowContents(Browser* browser,
129 content::WebContents* web_contents);
131 ChromeLauncherController* launcher_controller_;
133 // Hold all observed activation clients.
134 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
135 aura::client::ActivationChangeObserver> observed_activation_clients_;
137 // Hold all observed root windows.
138 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
140 BrowserToAppIDMap browser_to_app_id_map_;
141 WebContentsToObserverMap webcontents_to_observer_map_;
142 scoped_ptr<SettingsWindowObserver> settings_window_observer_;
144 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
147 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_