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

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

Issue 1400823003: Creates BrowserTabStripTracker to consolidate common code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback and git cl format Created 5 years, 2 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" 7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/shelf/shelf_util.h" 8 #include "ash/shelf/shelf_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 private: 98 private:
99 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver); 99 DISALLOW_COPY_AND_ASSIGN(SettingsWindowObserver);
100 }; 100 };
101 101
102 BrowserStatusMonitor::BrowserStatusMonitor( 102 BrowserStatusMonitor::BrowserStatusMonitor(
103 ChromeLauncherController* launcher_controller) 103 ChromeLauncherController* launcher_controller)
104 : launcher_controller_(launcher_controller), 104 : launcher_controller_(launcher_controller),
105 observed_activation_clients_(this), 105 observed_activation_clients_(this),
106 observed_root_windows_(this), 106 observed_root_windows_(this),
107 settings_window_observer_(new SettingsWindowObserver) { 107 settings_window_observer_(new SettingsWindowObserver),
108 browser_tab_strip_tracker_(this, this, this) {
108 DCHECK(launcher_controller_); 109 DCHECK(launcher_controller_);
109 BrowserList::AddObserver(this); 110
110 chrome::SettingsWindowManager::GetInstance()->AddObserver( 111 chrome::SettingsWindowManager::GetInstance()->AddObserver(
111 settings_window_observer_.get()); 112 settings_window_observer_.get());
112 113
113 // This check needs for win7_aura. Without this, all tests in 114 // This check needs for win7_aura. Without this, all tests in
114 // ChromeLauncherController will fail in win7_aura. 115 // ChromeLauncherController will fail in win7_aura.
115 if (ash::Shell::HasInstance()) { 116 if (ash::Shell::HasInstance()) {
116 // We can't assume all RootWindows have the same ActivationClient. 117 // We can't assume all RootWindows have the same ActivationClient.
117 // Add a RootWindow and its ActivationClient to the observed list. 118 // Add a RootWindow and its ActivationClient to the observed list.
118 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 119 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
119 aura::Window::Windows::const_iterator iter = root_windows.begin(); 120 aura::Window::Windows::const_iterator iter = root_windows.begin();
120 for (; iter != root_windows.end(); ++iter) { 121 for (; iter != root_windows.end(); ++iter) {
121 // |observed_activation_clients_| can have the same activation client 122 // |observed_activation_clients_| can have the same activation client
122 // multiple times - which would be handled by the used 123 // multiple times - which would be handled by the used
123 // |ScopedObserverWithDuplicatedSources|. 124 // |ScopedObserverWithDuplicatedSources|.
124 observed_activation_clients_.Add( 125 observed_activation_clients_.Add(
125 aura::client::GetActivationClient(*iter)); 126 aura::client::GetActivationClient(*iter));
126 observed_root_windows_.Add(static_cast<aura::Window*>(*iter)); 127 observed_root_windows_.Add(static_cast<aura::Window*>(*iter));
127 } 128 }
128 ash::Shell::GetInstance()->GetScreen()->AddObserver(this); 129 ash::Shell::GetInstance()->GetScreen()->AddObserver(this);
129 } 130 }
131
132 browser_tab_strip_tracker_.Init(
133 BrowserTabStripTracker::InitWith::ALL_BROWERS);
130 } 134 }
131 135
132 BrowserStatusMonitor::~BrowserStatusMonitor() { 136 BrowserStatusMonitor::~BrowserStatusMonitor() {
133 // This check needs for win7_aura. Without this, all tests in 137 // This check needs for win7_aura. Without this, all tests in
134 // ChromeLauncherController will fail in win7_aura. 138 // ChromeLauncherController will fail in win7_aura.
135 if (ash::Shell::HasInstance()) 139 if (ash::Shell::HasInstance())
136 ash::Shell::GetInstance()->GetScreen()->RemoveObserver(this); 140 ash::Shell::GetInstance()->GetScreen()->RemoveObserver(this);
137 141
138 chrome::SettingsWindowManager::GetInstance()->RemoveObserver( 142 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(
139 settings_window_observer_.get()); 143 settings_window_observer_.get());
140 144
141 BrowserList::RemoveObserver(this); 145 browser_tab_strip_tracker_.StopObservingAndSendOnBrowserRemoved();
142
143 BrowserList* browser_list =
144 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
145 for (BrowserList::const_iterator i = browser_list->begin();
146 i != browser_list->end(); ++i) {
147 OnBrowserRemoved(*i);
148 }
149 146
150 STLDeleteContainerPairSecondPointers(webcontents_to_observer_map_.begin(), 147 STLDeleteContainerPairSecondPointers(webcontents_to_observer_map_.begin(),
151 webcontents_to_observer_map_.end()); 148 webcontents_to_observer_map_.end());
152 } 149 }
153 150
154 void BrowserStatusMonitor::UpdateAppItemState( 151 void BrowserStatusMonitor::UpdateAppItemState(
155 content::WebContents* contents, 152 content::WebContents* contents,
156 ChromeLauncherController::AppState app_state) { 153 ChromeLauncherController::AppState app_state) {
157 DCHECK(contents); 154 DCHECK(contents);
158 // It is possible to come here from Browser::SwapTabContent where the contents 155 // It is possible to come here from Browser::SwapTabContent where the contents
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 UpdateBrowserItemState(); 201 UpdateBrowserItemState();
205 } 202 }
206 203
207 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { 204 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) {
208 // Remove RootWindow and its ActivationClient from observed list. 205 // Remove RootWindow and its ActivationClient from observed list.
209 observed_root_windows_.Remove(window); 206 observed_root_windows_.Remove(window);
210 observed_activation_clients_.Remove( 207 observed_activation_clients_.Remove(
211 aura::client::GetActivationClient(window)); 208 aura::client::GetActivationClient(window));
212 } 209 }
213 210
211 bool BrowserStatusMonitor::ShouldTrackBrowser(Browser* browser) {
212 return browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH;
213 }
214
214 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) { 215 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
215 if (browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
216 return;
217
218 if (browser->is_type_popup() && browser->is_app()) { 216 if (browser->is_type_popup() && browser->is_app()) {
219 // Note: A V1 application will set the tab strip observer when the app gets 217 // Note: A V1 application will set the tab strip observer when the app gets
220 // added to the shelf. This makes sure that in the multi user case we will 218 // added to the shelf. This makes sure that in the multi user case we will
221 // only set the observer while the app item exists in the shelf. 219 // only set the observer while the app item exists in the shelf.
222 AddV1AppToShelf(browser); 220 AddV1AppToShelf(browser);
223 } else {
224 browser->tab_strip_model()->AddObserver(this);
225 } 221 }
226 } 222 }
227 223
228 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { 224 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
229 if (browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
230 return;
231
232 if (browser->is_type_popup() && browser->is_app()) 225 if (browser->is_type_popup() && browser->is_app())
233 RemoveV1AppFromShelf(browser); 226 RemoveV1AppFromShelf(browser);
234 else
235 browser->tab_strip_model()->RemoveObserver(this);
236 227
237 UpdateBrowserItemState(); 228 UpdateBrowserItemState();
238 } 229 }
239 230
240 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) { 231 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) {
241 // Add a new RootWindow and its ActivationClient to observed list. 232 // Add a new RootWindow and its ActivationClient to observed list.
242 aura::Window* root_window = ash::Shell::GetInstance() 233 aura::Window* root_window = ash::Shell::GetInstance()
243 ->window_tree_host_manager() 234 ->window_tree_host_manager()
244 ->GetRootWindowForDisplayId(new_display.id()); 235 ->GetRootWindowForDisplayId(new_display.id());
245 // When the primary root window's display get removed, the existing root 236 // When the primary root window's display get removed, the existing root
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 333
343 void BrowserStatusMonitor::WebContentsDestroyed( 334 void BrowserStatusMonitor::WebContentsDestroyed(
344 content::WebContents* contents) { 335 content::WebContents* contents) {
345 UpdateAppItemState(contents, ChromeLauncherController::APP_STATE_REMOVED); 336 UpdateAppItemState(contents, ChromeLauncherController::APP_STATE_REMOVED);
346 RemoveWebContentsObserver(contents); 337 RemoveWebContentsObserver(contents);
347 } 338 }
348 339
349 void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) { 340 void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
350 DCHECK(browser->is_type_popup() && browser->is_app()); 341 DCHECK(browser->is_type_popup() && browser->is_app());
351 342
352 browser->tab_strip_model()->AddObserver(this);
353
354 std::string app_id = 343 std::string app_id =
355 web_app::GetExtensionIdFromApplicationName(browser->app_name()); 344 web_app::GetExtensionIdFromApplicationName(browser->app_name());
356 if (!app_id.empty()) { 345 if (!app_id.empty()) {
357 browser_to_app_id_map_[browser] = app_id; 346 browser_to_app_id_map_[browser] = app_id;
358 launcher_controller_->LockV1AppWithID(app_id); 347 launcher_controller_->LockV1AppWithID(app_id);
359 } 348 }
360 } 349 }
361 350
362 void BrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) { 351 void BrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) {
363 DCHECK(browser->is_type_popup() && browser->is_app()); 352 DCHECK(browser->is_type_popup() && browser->is_app());
364 353
365 browser->tab_strip_model()->RemoveObserver(this);
366
367 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { 354 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) {
368 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); 355 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]);
369 browser_to_app_id_map_.erase(browser); 356 browser_to_app_id_map_.erase(browser);
370 } 357 }
371 } 358 }
372 359
373 bool BrowserStatusMonitor::IsV1AppInShelf(Browser* browser) { 360 bool BrowserStatusMonitor::IsV1AppInShelf(Browser* browser) {
374 return browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end(); 361 return browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end();
375 } 362 }
376 363
(...skipping 18 matching lines...) Expand all
395 content::WebContents* contents) { 382 content::WebContents* contents) {
396 return launcher_controller_->GetShelfIDForWebContents(contents); 383 return launcher_controller_->GetShelfIDForWebContents(contents);
397 } 384 }
398 385
399 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( 386 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents(
400 Browser* browser, 387 Browser* browser,
401 content::WebContents* web_contents) { 388 content::WebContents* web_contents) {
402 launcher_controller_->GetBrowserShortcutLauncherItemController()-> 389 launcher_controller_->GetBrowserShortcutLauncherItemController()->
403 SetShelfIDForBrowserWindowContents(browser, web_contents); 390 SetShelfIDForBrowserWindowContents(browser, web_contents);
404 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/browser_status_monitor.h ('k') | chrome/browser/ui/ash/metrics/chrome_user_metrics_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698