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

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

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/multi_profile_uma.h" 8 #include "ash/multi_profile_uma.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/session/session_state_delegate.h" 10 #include "ash/session/session_state_delegate.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 23 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom eos.h" 26 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom eos.h"
27 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 27 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
28 #include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h" 28 #include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h"
29 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
31 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list.h"
32 #include "chrome/browser/ui/browser_window.h" 32 #include "chrome/browser/ui/browser_window.h"
33 #include "components/user_manager/user_id.h"
33 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
34 #include "extensions/browser/app_window/app_window.h" 35 #include "extensions/browser/app_window/app_window.h"
35 #include "extensions/browser/app_window/app_window_registry.h" 36 #include "extensions/browser/app_window/app_window_registry.h"
36 #include "google_apis/gaia/gaia_auth_util.h" 37 #include "google_apis/gaia/gaia_auth_util.h"
37 #include "ui/aura/client/aura_constants.h" 38 #include "ui/aura/client/aura_constants.h"
38 #include "ui/aura/window.h" 39 #include "ui/aura/window.h"
39 #include "ui/aura/window_event_dispatcher.h" 40 #include "ui/aura/window_event_dispatcher.h"
40 #include "ui/base/ui_base_types.h" 41 #include "ui/base/ui_base_types.h"
41 #include "ui/events/event.h" 42 #include "ui/events/event.h"
42 #include "ui/message_center/message_center.h" 43 #include "ui/message_center/message_center.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 DISALLOW_COPY_AND_ASSIGN(AnimationSetter); 186 DISALLOW_COPY_AND_ASSIGN(AnimationSetter);
186 }; 187 };
187 188
188 // This class keeps track of all applications which were started for a user. 189 // This class keeps track of all applications which were started for a user.
189 // When an app gets created, the window will be tagged for that user. Note 190 // When an app gets created, the window will be tagged for that user. Note
190 // that the destruction does not need to be tracked here since the universal 191 // that the destruction does not need to be tracked here since the universal
191 // window observer will take care of that. 192 // window observer will take care of that.
192 class AppObserver : public extensions::AppWindowRegistry::Observer { 193 class AppObserver : public extensions::AppWindowRegistry::Observer {
193 public: 194 public:
194 explicit AppObserver(const std::string& user_id) : user_id_(user_id) {} 195 explicit AppObserver(const user_manager::UserID& user_id) : user_id_(user_id) {}
195 ~AppObserver() override {} 196 ~AppObserver() override {}
196 197
197 // AppWindowRegistry::Observer overrides: 198 // AppWindowRegistry::Observer overrides:
198 void OnAppWindowAdded(extensions::AppWindow* app_window) override { 199 void OnAppWindowAdded(extensions::AppWindow* app_window) override {
199 aura::Window* window = app_window->GetNativeWindow(); 200 aura::Window* window = app_window->GetNativeWindow();
200 DCHECK(window); 201 DCHECK(window);
201 MultiUserWindowManagerChromeOS::GetInstance()->SetWindowOwner(window, 202 MultiUserWindowManagerChromeOS::GetInstance()->SetWindowOwner(window,
202 user_id_); 203 user_id_);
203 } 204 }
204 205
205 private: 206 private:
206 std::string user_id_; 207 const user_manager::UserID user_id_;
207 208
208 DISALLOW_COPY_AND_ASSIGN(AppObserver); 209 DISALLOW_COPY_AND_ASSIGN(AppObserver);
209 }; 210 };
210 211
211 MultiUserWindowManagerChromeOS::MultiUserWindowManagerChromeOS( 212 MultiUserWindowManagerChromeOS::MultiUserWindowManagerChromeOS(
212 const std::string& current_user_id) 213 const user_manager::UserID& current_user_id)
213 : current_user_id_(current_user_id), 214 : current_user_id_(current_user_id),
215 null_user_id_(std::string(), std::string()),
214 notification_blocker_(new MultiUserNotificationBlockerChromeOS( 216 notification_blocker_(new MultiUserNotificationBlockerChromeOS(
215 message_center::MessageCenter::Get(), current_user_id)), 217 message_center::MessageCenter::Get(), current_user_id)),
216 suppress_visibility_changes_(false), 218 suppress_visibility_changes_(false),
217 animation_speed_(ANIMATION_SPEED_NORMAL) { 219 animation_speed_(ANIMATION_SPEED_NORMAL) {
218 } 220 }
219 221
220 MultiUserWindowManagerChromeOS::~MultiUserWindowManagerChromeOS() { 222 MultiUserWindowManagerChromeOS::~MultiUserWindowManagerChromeOS() {
221 // When the MultiUserWindowManager gets destroyed, ash::Shell is mostly gone. 223 // When the MultiUserWindowManager gets destroyed, ash::Shell is mostly gone.
222 // As such we should not try to finalize any outstanding user animations. 224 // As such we should not try to finalize any outstanding user animations.
223 // Note that the destruction of the object can be done later. 225 // Note that the destruction of the object can be done later.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 content::NotificationService::AllSources()); 270 content::NotificationService::AllSources());
269 271
270 // Add an app window observer & all already running apps. 272 // Add an app window observer & all already running apps.
271 Profile* profile = multi_user_util::GetProfileFromUserID(current_user_id_); 273 Profile* profile = multi_user_util::GetProfileFromUserID(current_user_id_);
272 if (profile) 274 if (profile)
273 AddUser(profile); 275 AddUser(profile);
274 } 276 }
275 277
276 void MultiUserWindowManagerChromeOS::SetWindowOwner( 278 void MultiUserWindowManagerChromeOS::SetWindowOwner(
277 aura::Window* window, 279 aura::Window* window,
278 const std::string& user_id) { 280 const user_manager::UserID& user_id) {
279 // Make sure the window is valid and there was no owner yet. 281 // Make sure the window is valid and there was no owner yet.
280 DCHECK(window); 282 DCHECK(window);
281 DCHECK(!user_id.empty()); 283 DCHECK(!user_id.empty());
282 if (GetWindowOwner(window) == user_id) 284 if (GetWindowOwner(window) == user_id)
283 return; 285 return;
284 DCHECK(GetWindowOwner(window).empty()); 286 DCHECK(GetWindowOwner(window).empty());
285 window_to_entry_[window] = new WindowEntry(user_id); 287 window_to_entry_[window] = new WindowEntry(user_id);
286 288
287 // Remember the initial visibility of the window. 289 // Remember the initial visibility of the window.
288 window_to_entry_[window]->set_show(window->IsVisible()); 290 window_to_entry_[window]->set_show(window->IsVisible());
(...skipping 11 matching lines...) Expand all
300 // will add the children but not the owner to the transient children map. 302 // will add the children but not the owner to the transient children map.
301 AddTransientOwnerRecursive(window, window); 303 AddTransientOwnerRecursive(window, window);
302 304
303 // Notify entry adding. 305 // Notify entry adding.
304 FOR_EACH_OBSERVER(Observer, observers_, OnOwnerEntryAdded(window)); 306 FOR_EACH_OBSERVER(Observer, observers_, OnOwnerEntryAdded(window));
305 307
306 if (!IsWindowOnDesktopOfUser(window, current_user_id_)) 308 if (!IsWindowOnDesktopOfUser(window, current_user_id_))
307 SetWindowVisibility(window, false, 0); 309 SetWindowVisibility(window, false, 0);
308 } 310 }
309 311
310 const std::string& MultiUserWindowManagerChromeOS::GetWindowOwner( 312 const user_manager::UserID& MultiUserWindowManagerChromeOS::GetWindowOwner(
311 aura::Window* window) const { 313 aura::Window* window) const {
312 WindowToEntryMap::const_iterator it = window_to_entry_.find(window); 314 WindowToEntryMap::const_iterator it = window_to_entry_.find(window);
313 return it != window_to_entry_.end() ? it->second->owner() 315 return it != window_to_entry_.end() ? it->second->owner()
314 : base::EmptyString(); 316 : user_manager::EmptyUserID();
315 } 317 }
316 318
317 void MultiUserWindowManagerChromeOS::ShowWindowForUser( 319 void MultiUserWindowManagerChromeOS::ShowWindowForUser(
318 aura::Window* window, 320 aura::Window* window,
319 const std::string& user_id) { 321 const user_manager::UserID& user_id) {
320 std::string previous_owner(GetUserPresentingWindow(window)); 322 user_manager::UserID previous_owner(GetUserPresentingWindow(window));
321 if (!ShowWindowForUserIntern(window, user_id)) 323 if (!ShowWindowForUserIntern(window, user_id))
322 return; 324 return;
323 // The window switched to a new desktop and we have to switch to that desktop, 325 // The window switched to a new desktop and we have to switch to that desktop,
324 // but only when it was on the visible desktop and the the target is not the 326 // but only when it was on the visible desktop and the the target is not the
325 // visible desktop. 327 // visible desktop.
326 if (user_id == current_user_id_ || previous_owner != current_user_id_) 328 if (user_id == current_user_id_ || previous_owner != current_user_id_)
327 return; 329 return;
328 330
329 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser( 331 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser(
330 user_id); 332 user_id);
331 } 333 }
332 334
333 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() const { 335 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() const {
334 WindowToEntryMap::const_iterator it = window_to_entry_.begin(); 336 WindowToEntryMap::const_iterator it = window_to_entry_.begin();
335 for (; it != window_to_entry_.end(); ++it) { 337 for (; it != window_to_entry_.end(); ++it) {
336 if (it->second->owner() != it->second->show_for_user()) 338 if (it->second->owner() != it->second->show_for_user())
337 return true; 339 return true;
338 } 340 }
339 return false; 341 return false;
340 } 342 }
341 343
342 void MultiUserWindowManagerChromeOS::GetOwnersOfVisibleWindows( 344 void MultiUserWindowManagerChromeOS::GetOwnersOfVisibleWindows(
343 std::set<std::string>* user_ids) const { 345 std::set<user_manager::UserID>* user_ids) const {
344 for (WindowToEntryMap::const_iterator it = window_to_entry_.begin(); 346 for (WindowToEntryMap::const_iterator it = window_to_entry_.begin();
345 it != window_to_entry_.end(); 347 it != window_to_entry_.end();
346 ++it) { 348 ++it) {
347 if (it->first->IsVisible()) 349 if (it->first->IsVisible())
348 user_ids->insert(it->second->owner()); 350 user_ids->insert(it->second->owner());
349 } 351 }
350 } 352 }
351 353
352 bool MultiUserWindowManagerChromeOS::IsWindowOnDesktopOfUser( 354 bool MultiUserWindowManagerChromeOS::IsWindowOnDesktopOfUser(
353 aura::Window* window, 355 aura::Window* window,
354 const std::string& user_id) const { 356 const user_manager::UserID& user_id) const {
355 const std::string& presenting_user = GetUserPresentingWindow(window); 357 const user_manager::UserID& presenting_user = GetUserPresentingWindow(window);
356 return presenting_user.empty() || presenting_user == user_id; 358 return presenting_user.empty() || presenting_user == user_id;
357 } 359 }
358 360
359 const std::string& MultiUserWindowManagerChromeOS::GetUserPresentingWindow( 361 const user_manager::UserID& MultiUserWindowManagerChromeOS::GetUserPresentingWin dow(
360 aura::Window* window) const { 362 aura::Window* window) const {
361 WindowToEntryMap::const_iterator it = window_to_entry_.find(window); 363 WindowToEntryMap::const_iterator it = window_to_entry_.find(window);
362 // If the window is not owned by anyone it is shown on all desktops and we 364 // If the window is not owned by anyone it is shown on all desktops and we
363 // return the empty string. 365 // return the empty string.
364 if (it == window_to_entry_.end()) 366 if (it == window_to_entry_.end())
365 return base::EmptyString(); 367 return user_manager::EmptyUserID();
368
366 // Otherwise we ask the object for its desktop. 369 // Otherwise we ask the object for its desktop.
367 return it->second->show_for_user(); 370 return it->second->show_for_user();
368 } 371 }
369 372
370 void MultiUserWindowManagerChromeOS::AddUser(content::BrowserContext* context) { 373 void MultiUserWindowManagerChromeOS::AddUser(content::BrowserContext* context) {
371 Profile* profile = Profile::FromBrowserContext(context); 374 Profile* profile = Profile::FromBrowserContext(context);
372 const std::string& user_id = multi_user_util::GetUserIDFromProfile(profile); 375 const user_manager::UserID& user_id = multi_user_util::GetUserIDFromProfile(pr ofile);
373 if (user_id_to_app_observer_.find(user_id) != user_id_to_app_observer_.end()) 376 if (user_id_to_app_observer_.find(user_id) != user_id_to_app_observer_.end())
374 return; 377 return;
375 378
376 user_id_to_app_observer_[user_id] = new AppObserver(user_id); 379 user_id_to_app_observer_[user_id] = new AppObserver(user_id);
377 extensions::AppWindowRegistry::Get(profile) 380 extensions::AppWindowRegistry::Get(profile)
378 ->AddObserver(user_id_to_app_observer_[user_id]); 381 ->AddObserver(user_id_to_app_observer_[user_id]);
379 382
380 // Account all existing application windows of this user accordingly. 383 // Account all existing application windows of this user accordingly.
381 const extensions::AppWindowRegistry::AppWindowList& app_windows = 384 const extensions::AppWindowRegistry::AppWindowList& app_windows =
382 extensions::AppWindowRegistry::Get(profile)->app_windows(); 385 extensions::AppWindowRegistry::Get(profile)->app_windows();
(...skipping 27 matching lines...) Expand all
410 413
411 void MultiUserWindowManagerChromeOS::AddObserver(Observer* observer) { 414 void MultiUserWindowManagerChromeOS::AddObserver(Observer* observer) {
412 observers_.AddObserver(observer); 415 observers_.AddObserver(observer);
413 } 416 }
414 417
415 void MultiUserWindowManagerChromeOS::RemoveObserver(Observer* observer) { 418 void MultiUserWindowManagerChromeOS::RemoveObserver(Observer* observer) {
416 observers_.RemoveObserver(observer); 419 observers_.RemoveObserver(observer);
417 } 420 }
418 421
419 void MultiUserWindowManagerChromeOS::ActiveUserChanged( 422 void MultiUserWindowManagerChromeOS::ActiveUserChanged(
420 const std::string& user_id) { 423 const user_manager::UserID& user_id) {
421 // This needs to be set before the animation starts. 424 // This needs to be set before the animation starts.
422 current_user_id_ = user_id; 425 current_user_id_ = user_id;
423 426
424 // Here to avoid a very nasty race condition, we must destruct any previously 427 // Here to avoid a very nasty race condition, we must destruct any previously
425 // created animation before creating a new one. Otherwise, the newly 428 // created animation before creating a new one. Otherwise, the newly
426 // constructed will hide all windows of the old user in the first step of the 429 // constructed will hide all windows of the old user in the first step of the
427 // animation only to be reshown again by the destructor of the old animation. 430 // animation only to be reshown again by the destructor of the old animation.
428 animation_.reset(); 431 animation_.reset();
429 animation_.reset( 432 animation_.reset(
430 new UserSwitchAnimatorChromeOS( 433 new UserSwitchAnimatorChromeOS(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 530
528 void MultiUserWindowManagerChromeOS::SetAnimationSpeedForTest( 531 void MultiUserWindowManagerChromeOS::SetAnimationSpeedForTest(
529 MultiUserWindowManagerChromeOS::AnimationSpeed speed) { 532 MultiUserWindowManagerChromeOS::AnimationSpeed speed) {
530 animation_speed_ = speed; 533 animation_speed_ = speed;
531 } 534 }
532 535
533 bool MultiUserWindowManagerChromeOS::IsAnimationRunningForTest() { 536 bool MultiUserWindowManagerChromeOS::IsAnimationRunningForTest() {
534 return animation_.get() != NULL && !animation_->IsAnimationFinished(); 537 return animation_.get() != NULL && !animation_->IsAnimationFinished();
535 } 538 }
536 539
537 const std::string& MultiUserWindowManagerChromeOS::GetCurrentUserForTest() 540 const user_manager::UserID& MultiUserWindowManagerChromeOS::GetCurrentUserForTes t()
538 const { 541 const {
539 return current_user_id_; 542 return current_user_id_;
540 } 543 }
541 544
542 bool MultiUserWindowManagerChromeOS::ShowWindowForUserIntern( 545 bool MultiUserWindowManagerChromeOS::ShowWindowForUserIntern(
543 aura::Window* window, 546 aura::Window* window,
544 const std::string& user_id) { 547 const user_manager::UserID& user_id) {
545 // If there is either no owner, or the owner is the current user, no action 548 // If there is either no owner, or the owner is the current user, no action
546 // is required. 549 // is required.
547 const std::string& owner = GetWindowOwner(window); 550 const user_manager::UserID& owner = GetWindowOwner(window);
548 if (owner.empty() || 551 if (owner.empty() ||
549 (owner == user_id && IsWindowOnDesktopOfUser(window, user_id))) 552 (owner == user_id && IsWindowOnDesktopOfUser(window, user_id)))
550 return false; 553 return false;
551 554
552 bool minimized = ash::wm::GetWindowState(window)->IsMinimized(); 555 bool minimized = ash::wm::GetWindowState(window)->IsMinimized();
553 // Check that we are not trying to transfer ownership of a minimized window. 556 // Check that we are not trying to transfer ownership of a minimized window.
554 if (user_id != owner && minimized) 557 if (user_id != owner && minimized)
555 return false; 558 return false;
556 559
557 if (minimized) { 560 if (minimized) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 // Note that in some cases (e.g. unit test) windows might not have a root 594 // Note that in some cases (e.g. unit test) windows might not have a root
592 // window. 595 // window.
593 if (!visible && window->GetRootWindow()) { 596 if (!visible && window->GetRootWindow()) {
594 // Get the system modal container for the window's root window. 597 // Get the system modal container for the window's root window.
595 aura::Window* system_modal_container = 598 aura::Window* system_modal_container =
596 window->GetRootWindow()->GetChildById( 599 window->GetRootWindow()->GetChildById(
597 ash::kShellWindowId_SystemModalContainer); 600 ash::kShellWindowId_SystemModalContainer);
598 if (window->parent() == system_modal_container) { 601 if (window->parent() == system_modal_container) {
599 // The window is system modal and we need to find the parent which owns 602 // The window is system modal and we need to find the parent which owns
600 // it so that we can switch to the desktop accordingly. 603 // it so that we can switch to the desktop accordingly.
601 std::string user_id = GetUserPresentingWindow(window); 604 user_manager::UserID user_id = GetUserPresentingWindow(window);
602 if (user_id.empty()) { 605 if (user_id.empty()) {
603 aura::Window* owning_window = GetOwningWindowInTransientChain(window); 606 aura::Window* owning_window = GetOwningWindowInTransientChain(window);
604 DCHECK(owning_window); 607 DCHECK(owning_window);
605 user_id = GetUserPresentingWindow(owning_window); 608 user_id = GetUserPresentingWindow(owning_window);
606 DCHECK(!user_id.empty()); 609 DCHECK(!user_id.empty());
607 } 610 }
608 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser( 611 ash::Shell::GetInstance()->session_state_delegate()->SwitchActiveUser(
609 user_id); 612 user_id);
610 return; 613 return;
611 } 614 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 DCHECK_EQ(visible, window->IsVisible()); 743 DCHECK_EQ(visible, window->IsVisible());
741 } 744 }
742 745
743 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS( 746 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS(
744 int default_time_in_ms) const { 747 int default_time_in_ms) const {
745 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms : 748 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms :
746 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0); 749 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0);
747 } 750 }
748 751
749 } // namespace chrome 752 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698