Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_status_monitor.cc

Issue 2185743002: Remove ash::ScopedObserverWithDuplicatedSources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
6 6
7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/shelf/shelf_util.h" 7 #include "ash/shelf/shelf_util.h"
9 #include "ash/shell.h" 8 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/stl_util.h" 11 #include "base/stl_util.h"
13 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 12 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
16 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/settings_window_manager.h" 19 #include "chrome/browser/ui/settings_window_manager.h"
21 #include "chrome/browser/ui/settings_window_manager_observer.h" 20 #include "chrome/browser/ui/settings_window_manager_observer.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/browser/web_applications/web_app.h" 22 #include "chrome/browser/web_applications/web_app.h"
24 #include "components/strings/grit/components_strings.h" 23 #include "components/strings/grit/components_strings.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
27 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
28 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
29 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
30 #include "ui/aura/window_event_dispatcher.h" 29 #include "ui/aura/window_event_dispatcher.h"
31 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/display/screen.h"
33 #include "ui/wm/public/activation_client.h" 31 #include "ui/wm/public/activation_client.h"
34 32
35 // This class monitors the WebContent of the all tab and notifies a navigation 33 // This class monitors the WebContent of the all tab and notifies a navigation
36 // to the BrowserStatusMonitor. 34 // to the BrowserStatusMonitor.
37 class BrowserStatusMonitor::LocalWebContentsObserver 35 class BrowserStatusMonitor::LocalWebContentsObserver
38 : public content::WebContentsObserver { 36 : public content::WebContentsObserver {
39 public: 37 public:
40 LocalWebContentsObserver(content::WebContents* contents, 38 LocalWebContentsObserver(content::WebContents* contents,
41 BrowserStatusMonitor* monitor) 39 BrowserStatusMonitor* monitor)
42 : content::WebContentsObserver(contents), 40 : content::WebContentsObserver(contents),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); 96 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
99 } 97 }
100 98
101 private: 99 private:
102 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver); 100 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver);
103 }; 101 };
104 102
105 BrowserStatusMonitor::BrowserStatusMonitor( 103 BrowserStatusMonitor::BrowserStatusMonitor(
106 ChromeLauncherController* launcher_controller) 104 ChromeLauncherController* launcher_controller)
107 : launcher_controller_(launcher_controller), 105 : launcher_controller_(launcher_controller),
108 observed_activation_clients_(this),
109 observed_root_windows_(this),
110 settings_window_observer_(new SettingsWindowObserver), 106 settings_window_observer_(new SettingsWindowObserver),
111 browser_tab_strip_tracker_(this, this, this) { 107 browser_tab_strip_tracker_(this, this, this) {
112 DCHECK(launcher_controller_); 108 DCHECK(launcher_controller_);
113 109
114 chrome::SettingsWindowManager::GetInstance()->AddObserver( 110 chrome::SettingsWindowManager::GetInstance()->AddObserver(
115 settings_window_observer_.get()); 111 settings_window_observer_.get());
116 112 ash::Shell::GetInstance()->activation_client()->AddObserver(this);
117 // This check needs for win7_aura. Without this, all tests in
118 // ChromeLauncherController will fail in win7_aura.
119 if (ash::Shell::HasInstance()) {
120 // We can't assume all RootWindows have the same ActivationClient.
121 // Add a RootWindow and its ActivationClient to the observed list.
122 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
123 aura::Window::Windows::const_iterator iter = root_windows.begin();
124 for (; iter != root_windows.end(); ++iter) {
125 // |observed_activation_clients_| can have the same activation client
126 // multiple times - which would be handled by the used
127 // |ScopedObserverWithDuplicatedSources|.
128 observed_activation_clients_.Add(
129 aura::client::GetActivationClient(*iter));
130 observed_root_windows_.Add(static_cast<aura::Window*>(*iter));
131 }
132 display::Screen::GetScreen()->AddObserver(this);
133 }
134 113
135 browser_tab_strip_tracker_.Init( 114 browser_tab_strip_tracker_.Init(
136 BrowserTabStripTracker::InitWith::ALL_BROWERS); 115 BrowserTabStripTracker::InitWith::ALL_BROWERS);
137 } 116 }
138 117
139 BrowserStatusMonitor::~BrowserStatusMonitor() { 118 BrowserStatusMonitor::~BrowserStatusMonitor() {
140 // This check needs for win7_aura. Without this, all tests in 119 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this);
141 // ChromeLauncherController will fail in win7_aura.
142 if (ash::Shell::HasInstance())
143 display::Screen::GetScreen()->RemoveObserver(this);
144
145 chrome::SettingsWindowManager::GetInstance()->RemoveObserver( 120 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(
146 settings_window_observer_.get()); 121 settings_window_observer_.get());
147 122
148 browser_tab_strip_tracker_.StopObservingAndSendOnBrowserRemoved(); 123 browser_tab_strip_tracker_.StopObservingAndSendOnBrowserRemoved();
149 124
150 STLDeleteContainerPairSecondPointers(webcontents_to_observer_map_.begin(), 125 STLDeleteContainerPairSecondPointers(webcontents_to_observer_map_.begin(),
151 webcontents_to_observer_map_.end()); 126 webcontents_to_observer_map_.end());
152 } 127 }
153 128
154 void BrowserStatusMonitor::UpdateAppItemState( 129 void BrowserStatusMonitor::UpdateAppItemState(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 UpdateAppItemState( 172 UpdateAppItemState(
198 contents_from_gained, 173 contents_from_gained,
199 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE); 174 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE);
200 } 175 }
201 } 176 }
202 177
203 if (contents_from_lost || contents_from_gained) 178 if (contents_from_lost || contents_from_gained)
204 UpdateBrowserItemState(); 179 UpdateBrowserItemState();
205 } 180 }
206 181
207 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) {
208 // Remove RootWindow and its ActivationClient from observed list.
209 observed_root_windows_.Remove(window);
210 observed_activation_clients_.Remove(
211 aura::client::GetActivationClient(window));
212 }
213
214 bool BrowserStatusMonitor::ShouldTrackBrowser(Browser* browser) { 182 bool BrowserStatusMonitor::ShouldTrackBrowser(Browser* browser) {
215 return true; 183 return true;
216 } 184 }
217 185
218 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) { 186 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
219 if (browser->is_type_popup() && browser->is_app()) { 187 if (browser->is_type_popup() && browser->is_app()) {
220 // Note: A V1 application will set the tab strip observer when the app gets 188 // Note: A V1 application will set the tab strip observer when the app gets
221 // added to the shelf. This makes sure that in the multi user case we will 189 // added to the shelf. This makes sure that in the multi user case we will
222 // only set the observer while the app item exists in the shelf. 190 // only set the observer while the app item exists in the shelf.
223 AddV1AppToShelf(browser); 191 AddV1AppToShelf(browser);
224 } 192 }
225 } 193 }
226 194
227 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { 195 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
228 if (browser->is_type_popup() && browser->is_app()) 196 if (browser->is_type_popup() && browser->is_app())
229 RemoveV1AppFromShelf(browser); 197 RemoveV1AppFromShelf(browser);
230 198
231 UpdateBrowserItemState(); 199 UpdateBrowserItemState();
232 } 200 }
233 201
234 void BrowserStatusMonitor::OnDisplayAdded(const display::Display& new_display) {
235 // Add a new RootWindow and its ActivationClient to observed list.
236 aura::Window* root_window = ash::Shell::GetInstance()
237 ->window_tree_host_manager()
238 ->GetRootWindowForDisplayId(new_display.id());
239 // When the primary root window's display get removed, the existing root
240 // window is taken over by the new display and the observer is already set.
241 if (!observed_root_windows_.IsObserving(root_window)) {
242 observed_root_windows_.Add(static_cast<aura::Window*>(root_window));
243 observed_activation_clients_.Add(
244 aura::client::GetActivationClient(root_window));
245 }
246 }
247
248 void BrowserStatusMonitor::OnDisplayRemoved(
249 const display::Display& old_display) {
250 // When this is called, RootWindow of |old_display| is already removed.
251 // Instead, we can remove RootWindow and its ActivationClient in the
252 // OnWindowRemoved().
253 // Do nothing here.
254 }
255
256 void BrowserStatusMonitor::OnDisplayMetricsChanged(const display::Display&,
257 uint32_t) {
258 // Do nothing here.
259 }
260
261 void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents, 202 void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents,
262 content::WebContents* new_contents, 203 content::WebContents* new_contents,
263 int index, 204 int index,
264 int reason) { 205 int reason) {
265 Browser* browser = NULL; 206 Browser* browser = NULL;
266 // Use |new_contents|. |old_contents| could be NULL. 207 // Use |new_contents|. |old_contents| could be NULL.
267 DCHECK(new_contents); 208 DCHECK(new_contents);
268 browser = chrome::FindBrowserWithWebContents(new_contents); 209 browser = chrome::FindBrowserWithWebContents(new_contents);
269 210
270 ChromeLauncherController::AppState state = 211 ChromeLauncherController::AppState state =
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 content::WebContents* contents) { 321 content::WebContents* contents) {
381 return launcher_controller_->GetShelfIDForWebContents(contents); 322 return launcher_controller_->GetShelfIDForWebContents(contents);
382 } 323 }
383 324
384 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( 325 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents(
385 Browser* browser, 326 Browser* browser,
386 content::WebContents* web_contents) { 327 content::WebContents* web_contents) {
387 launcher_controller_->GetBrowserShortcutLauncherItemController()-> 328 launcher_controller_->GetBrowserShortcutLauncherItemController()->
388 SetShelfIDForBrowserWindowContents(browser, web_contents); 329 SetShelfIDForBrowserWindowContents(browser, web_contents);
389 } 330 }
OLDNEW
« ash/shelf/shelf_window_watcher.cc ('K') | « chrome/browser/ui/ash/launcher/browser_status_monitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698