Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / browser_status_monitor.h
blobb0a4e5bda5f9d75982cf1590ea1c19cec073cd27
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(aura::Window* gained_active,
60 aura::Window* lost_active) override;
62 // aura::WindowObserver overrides:
63 void OnWindowDestroyed(aura::Window* window) override;
65 // chrome::BrowserListObserver overrides:
66 void OnBrowserAdded(Browser* browser) override;
67 void OnBrowserRemoved(Browser* browser) override;
69 // gfx::DisplayObserver overrides:
70 void OnDisplayAdded(const gfx::Display& new_display) override;
71 void OnDisplayRemoved(const gfx::Display& old_display) override;
72 void OnDisplayMetricsChanged(const gfx::Display& display,
73 uint32_t metrics) override;
75 // TabStripModelObserver overrides:
76 void ActiveTabChanged(content::WebContents* old_contents,
77 content::WebContents* new_contents,
78 int index,
79 int reason) override;
80 void TabReplacedAt(TabStripModel* tab_strip_model,
81 content::WebContents* old_contents,
82 content::WebContents* new_contents,
83 int index) override;
84 void TabInsertedAt(content::WebContents* contents,
85 int index,
86 bool foreground) override;
87 void TabClosingAt(TabStripModel* tab_strip_mode,
88 content::WebContents* contents,
89 int index) override;
91 // Called from our own |LocalWebContentsObserver| when web contents did go
92 // away without any other notification. This might happen in case of
93 // application uninstalls, page crashes, ...).
94 void WebContentsDestroyed(content::WebContents* web_contents);
96 protected:
97 // Add a V1 application to the shelf. This can get overwritten for multi
98 // profile implementations.
99 virtual void AddV1AppToShelf(Browser* browser);
101 // Remove a V1 application from the shelf. This can get overwritten for multi
102 // profile implementations.
103 virtual void RemoveV1AppFromShelf(Browser* browser);
105 // Check if V1 application is currently in the shelf.
106 bool IsV1AppInShelf(Browser* browser);
108 private:
109 class LocalWebContentsObserver;
110 class SettingsWindowObserver;
112 typedef std::map<Browser*, std::string> BrowserToAppIDMap;
113 typedef std::map<content::WebContents*, LocalWebContentsObserver*>
114 WebContentsToObserverMap;
116 // Create LocalWebContentsObserver for |contents|.
117 void AddWebContentsObserver(content::WebContents* contents);
119 // Remove LocalWebContentsObserver for |contents|.
120 void RemoveWebContentsObserver(content::WebContents* contents);
122 // Returns the ShelfID for |contents|.
123 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents);
125 // Sets the shelf id for browsers represented by the browser shortcut item.
126 void SetShelfIDForBrowserWindowContents(Browser* browser,
127 content::WebContents* web_contents);
129 ChromeLauncherController* launcher_controller_;
131 // Hold all observed activation clients.
132 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
133 aura::client::ActivationChangeObserver> observed_activation_clients_;
135 // Hold all observed root windows.
136 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
138 BrowserToAppIDMap browser_to_app_id_map_;
139 WebContentsToObserverMap webcontents_to_observer_map_;
140 scoped_ptr<SettingsWindowObserver> settings_window_observer_;
142 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
145 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_