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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.cc

Issue 2098023002: mash: Migrate remaining tray observers and notify functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 6 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/multi_user/multi_user_window_manager_chromeos.h" 5 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
6 6
7 #include "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shell_window_ids.h" 9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/system/tray/system_tray_notifier.h"
10 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm_shell.h"
11 #include "ash/multi_profile_uma.h" 13 #include "ash/multi_profile_uma.h"
12 #include "ash/root_window_controller.h" 14 #include "ash/root_window_controller.h"
13 #include "ash/shelf/shelf.h" 15 #include "ash/shelf/shelf.h"
14 #include "ash/shell.h" 16 #include "ash/shell.h"
15 #include "ash/shell_delegate.h" 17 #include "ash/shell_delegate.h"
16 #include "ash/system/tray/system_tray_notifier.h"
17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 18 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
18 #include "ash/wm/window_state_aura.h" 19 #include "ash/wm/window_state_aura.h"
19 #include "base/auto_reset.h" 20 #include "base/auto_reset.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 26 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (animation_.get()) 245 if (animation_.get())
245 animation_->CancelAnimation(); 246 animation_->CancelAnimation();
246 247
247 // Remove all window observers. 248 // Remove all window observers.
248 WindowToEntryMap::iterator window = window_to_entry_.begin(); 249 WindowToEntryMap::iterator window = window_to_entry_.begin();
249 while (window != window_to_entry_.end()) { 250 while (window != window_to_entry_.end()) {
250 OnWindowDestroyed(window->first); 251 OnWindowDestroyed(window->first);
251 window = window_to_entry_.begin(); 252 window = window_to_entry_.begin();
252 } 253 }
253 254
254 if (ash::Shell::HasInstance()) 255 if (ash::WmShell::HasInstance()) {
255 ash::Shell::GetInstance()->session_state_delegate()-> 256 ash::WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(
256 RemoveSessionStateObserver(this); 257 this);
258 }
257 259
258 // Remove all app observers. 260 // Remove all app observers.
259 ProfileManager* profile_manager = g_browser_process->profile_manager(); 261 ProfileManager* profile_manager = g_browser_process->profile_manager();
260 // might be nullptr in unit tests. 262 // might be nullptr in unit tests.
261 if (!profile_manager) 263 if (!profile_manager)
262 return; 264 return;
263 265
264 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 266 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
265 for (auto it = profiles.begin(); it != profiles.end(); ++it) { 267 for (auto it = profiles.begin(); it != profiles.end(); ++it) {
266 const AccountId account_id = multi_user_util::GetAccountIdFromProfile(*it); 268 const AccountId account_id = multi_user_util::GetAccountIdFromProfile(*it);
267 AccountIdToAppWindowObserver::iterator app_observer_iterator = 269 AccountIdToAppWindowObserver::iterator app_observer_iterator =
268 account_id_to_app_observer_.find(account_id); 270 account_id_to_app_observer_.find(account_id);
269 if (app_observer_iterator != account_id_to_app_observer_.end()) { 271 if (app_observer_iterator != account_id_to_app_observer_.end()) {
270 extensions::AppWindowRegistry::Get(*it)->RemoveObserver( 272 extensions::AppWindowRegistry::Get(*it)->RemoveObserver(
271 app_observer_iterator->second); 273 app_observer_iterator->second);
272 delete app_observer_iterator->second; 274 delete app_observer_iterator->second;
273 account_id_to_app_observer_.erase(app_observer_iterator); 275 account_id_to_app_observer_.erase(app_observer_iterator);
274 } 276 }
275 } 277 }
276 } 278 }
277 279
278 void MultiUserWindowManagerChromeOS::Init() { 280 void MultiUserWindowManagerChromeOS::Init() {
279 // Since we are setting the SessionStateObserver and adding the user, this 281 // Since we are setting the SessionStateObserver and adding the user, this
280 // function should get called only once. 282 // function should get called only once.
281 DCHECK(account_id_to_app_observer_.find(current_account_id_) == 283 DCHECK(account_id_to_app_observer_.find(current_account_id_) ==
282 account_id_to_app_observer_.end()); 284 account_id_to_app_observer_.end());
283 285
284 // Add a session state observer to be able to monitor session changes. 286 // Add a session state observer to be able to monitor session changes.
285 if (ash::Shell::HasInstance()) { 287 if (ash::WmShell::HasInstance()) {
286 ash::Shell::GetInstance()->session_state_delegate()-> 288 ash::WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(
287 AddSessionStateObserver(this); 289 this);
288 } 290 }
289 291
290 // The BrowserListObserver would have been better to use then the old 292 // The BrowserListObserver would have been better to use then the old
291 // notification system, but that observer fires before the window got created. 293 // notification system, but that observer fires before the window got created.
292 registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY, 294 registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY,
293 content::NotificationService::AllSources()); 295 content::NotificationService::AllSources());
294 296
295 // Add an app window observer & all already running apps. 297 // Add an app window observer & all already running apps.
296 Profile* profile = 298 Profile* profile =
297 multi_user_util::GetProfileFromAccountId(current_account_id_); 299 multi_user_util::GetProfileFromAccountId(current_account_id_);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 const AccountId previous_owner(GetUserPresentingWindow(window)); 347 const AccountId previous_owner(GetUserPresentingWindow(window));
346 if (!ShowWindowForUserIntern(window, account_id)) 348 if (!ShowWindowForUserIntern(window, account_id))
347 return; 349 return;
348 // The window switched to a new desktop and we have to switch to that desktop, 350 // The window switched to a new desktop and we have to switch to that desktop,
349 // but only when it was on the visible desktop and the the target is not the 351 // but only when it was on the visible desktop and the the target is not the
350 // visible desktop. 352 // visible desktop.
351 if (account_id == current_account_id_ || 353 if (account_id == current_account_id_ ||
352 previous_owner != current_account_id_) 354 previous_owner != current_account_id_)
353 return; 355 return;
354 356
355 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser( 357 ash::WmShell::Get()->GetSessionStateDelegate()->SwitchActiveUser(account_id);
356 account_id);
357 } 358 }
358 359
359 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() const { 360 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() const {
360 WindowToEntryMap::const_iterator it = window_to_entry_.begin(); 361 WindowToEntryMap::const_iterator it = window_to_entry_.begin();
361 for (; it != window_to_entry_.end(); ++it) { 362 for (; it != window_to_entry_.end(); ++it) {
362 if (it->second->owner() != it->second->show_for_user()) 363 if (it->second->owner() != it->second->show_for_user())
363 return true; 364 return true;
364 } 365 }
365 return false; 366 return false;
366 } 367 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 439
439 // Here to avoid a very nasty race condition, we must destruct any previously 440 // Here to avoid a very nasty race condition, we must destruct any previously
440 // created animation before creating a new one. Otherwise, the newly 441 // created animation before creating a new one. Otherwise, the newly
441 // constructed will hide all windows of the old user in the first step of the 442 // constructed will hide all windows of the old user in the first step of the
442 // animation only to be reshown again by the destructor of the old animation. 443 // animation only to be reshown again by the destructor of the old animation.
443 animation_.reset(); 444 animation_.reset();
444 animation_.reset(new UserSwitchAnimatorChromeOS( 445 animation_.reset(new UserSwitchAnimatorChromeOS(
445 this, account_id, GetAdjustedAnimationTimeInMS(kUserFadeTimeMS))); 446 this, account_id, GetAdjustedAnimationTimeInMS(kUserFadeTimeMS)));
446 // Call notifier here instead of observing ActiveUserChanged because 447 // Call notifier here instead of observing ActiveUserChanged because
447 // this must happen after MultiUserWindowManagerChromeOS is notified. 448 // this must happen after MultiUserWindowManagerChromeOS is notified.
448 ash::Shell::GetInstance() 449 ash::WmShell::Get()->system_tray_notifier()->NotifyMediaCaptureChanged();
449 ->system_tray_notifier()
450 ->NotifyMediaCaptureChanged();
451 } 450 }
452 451
453 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) { 452 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) {
454 if (GetWindowOwner(window).empty()) { 453 if (GetWindowOwner(window).empty()) {
455 // This must be a window in the transient chain - remove it and its 454 // This must be a window in the transient chain - remove it and its
456 // children from the owner. 455 // children from the owner.
457 RemoveTransientOwnerRecursive(window); 456 RemoveTransientOwnerRecursive(window);
458 return; 457 return;
459 } 458 }
460 wm::TransientWindowManager::Get(window)->RemoveObserver(this); 459 wm::TransientWindowManager::Get(window)->RemoveObserver(this);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 if (HasSystemModalTransientChildWindow(window)) { 610 if (HasSystemModalTransientChildWindow(window)) {
612 // The window is system modal and we need to find the parent which owns 611 // The window is system modal and we need to find the parent which owns
613 // it so that we can switch to the desktop accordingly. 612 // it so that we can switch to the desktop accordingly.
614 AccountId account_id = GetUserPresentingWindow(window); 613 AccountId account_id = GetUserPresentingWindow(window);
615 if (!account_id.is_valid()) { 614 if (!account_id.is_valid()) {
616 aura::Window* owning_window = GetOwningWindowInTransientChain(window); 615 aura::Window* owning_window = GetOwningWindowInTransientChain(window);
617 DCHECK(owning_window); 616 DCHECK(owning_window);
618 account_id = GetUserPresentingWindow(owning_window); 617 account_id = GetUserPresentingWindow(owning_window);
619 DCHECK(account_id.is_valid()); 618 DCHECK(account_id.is_valid());
620 } 619 }
621 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser( 620 ash::WmShell::Get()->GetSessionStateDelegate()->SwitchActiveUser(
622 account_id); 621 account_id);
623 return; 622 return;
624 } 623 }
625 } 624 }
626 625
627 // To avoid that these commands are recorded as any other commands, we are 626 // To avoid that these commands are recorded as any other commands, we are
628 // suppressing any window entry changes while this is going on. 627 // suppressing any window entry changes while this is going on.
629 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true); 628 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true);
630 629
631 if (visible) 630 if (visible)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 window->Hide(); 752 window->Hide();
754 } 753 }
755 754
756 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS( 755 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS(
757 int default_time_in_ms) const { 756 int default_time_in_ms) const {
758 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms : 757 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms :
759 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0); 758 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0);
760 } 759 }
761 760
762 } // namespace chrome 761 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698