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

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

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 #ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H_ 5 #ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H_
6 #define CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H_ 6 #define CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "ash/session/session_state_observer.h" 11 #include "ash/session/session_state_observer.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
16 #include "components/user_manager/user_id.h"
16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
18 #include "ui/aura/window_observer.h" 19 #include "ui/aura/window_observer.h"
19 #include "ui/wm/core/transient_window_observer.h" 20 #include "ui/wm/core/transient_window_observer.h"
20 21
21 class Browser; 22 class Browser;
22 class MultiUserNotificationBlockerChromeOS; 23 class MultiUserNotificationBlockerChromeOS;
23 class MultiUserNotificationBlockerChromeOSTest; 24 class MultiUserNotificationBlockerChromeOSTest;
24 25
25 namespace content { 26 namespace content {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public wm::TransientWindowObserver { 63 public wm::TransientWindowObserver {
63 public: 64 public:
64 // The speed which should be used to perform animations. 65 // The speed which should be used to perform animations.
65 enum AnimationSpeed { 66 enum AnimationSpeed {
66 ANIMATION_SPEED_NORMAL, // The normal animation speed. 67 ANIMATION_SPEED_NORMAL, // The normal animation speed.
67 ANIMATION_SPEED_FAST, // Unit test speed which test animations. 68 ANIMATION_SPEED_FAST, // Unit test speed which test animations.
68 ANIMATION_SPEED_DISABLED // Unit tests which do not require animations. 69 ANIMATION_SPEED_DISABLED // Unit tests which do not require animations.
69 }; 70 };
70 71
71 // Create the manager and use |active_user_id| as the active user. 72 // Create the manager and use |active_user_id| as the active user.
72 explicit MultiUserWindowManagerChromeOS(const std::string& active_user_id); 73 explicit MultiUserWindowManagerChromeOS(const user_manager::UserID& active_use r_id);
73 ~MultiUserWindowManagerChromeOS() override; 74 ~MultiUserWindowManagerChromeOS() override;
74 75
75 // Initializes the manager after its creation. Should only be called once. 76 // Initializes the manager after its creation. Should only be called once.
76 void Init(); 77 void Init();
77 78
78 // MultiUserWindowManager overrides: 79 // MultiUserWindowManager overrides:
79 void SetWindowOwner( 80 void SetWindowOwner(
80 aura::Window* window, const std::string& user_id) override; 81 aura::Window* window, const user_manager::UserID& user_id) override;
81 const std::string& GetWindowOwner( 82 const user_manager::UserID& GetWindowOwner(
82 aura::Window* window) const override; 83 aura::Window* window) const override;
83 void ShowWindowForUser( 84 void ShowWindowForUser(
84 aura::Window* window, const std::string& user_id) override; 85 aura::Window* window, const user_manager::UserID& user_id) override;
85 bool AreWindowsSharedAmongUsers() const override; 86 bool AreWindowsSharedAmongUsers() const override;
86 void GetOwnersOfVisibleWindows( 87 void GetOwnersOfVisibleWindows(
87 std::set<std::string>* user_ids) const override; 88 std::set<user_manager::UserID>* user_ids) const override;
88 bool IsWindowOnDesktopOfUser( 89 bool IsWindowOnDesktopOfUser(
89 aura::Window* window, 90 aura::Window* window,
90 const std::string& user_id) const override; 91 const user_manager::UserID& user_id) const override;
91 const std::string& GetUserPresentingWindow( 92 const user_manager::UserID& GetUserPresentingWindow(
92 aura::Window* window) const override; 93 aura::Window* window) const override;
93 void AddUser(content::BrowserContext* context) override; 94 void AddUser(content::BrowserContext* context) override;
94 void AddObserver(Observer* observer) override; 95 void AddObserver(Observer* observer) override;
95 void RemoveObserver(Observer* observer) override; 96 void RemoveObserver(Observer* observer) override;
96 97
97 // SessionStateObserver overrides: 98 // SessionStateObserver overrides:
98 void ActiveUserChanged(const std::string& user_id) override; 99 void ActiveUserChanged(const user_manager::UserID& user_id) override;
99 100
100 // WindowObserver overrides: 101 // WindowObserver overrides:
101 void OnWindowDestroyed(aura::Window* window) override; 102 void OnWindowDestroyed(aura::Window* window) override;
102 void OnWindowVisibilityChanging(aura::Window* window, bool visible) override; 103 void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;
103 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; 104 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
104 105
105 // TransientWindowObserver overrides: 106 // TransientWindowObserver overrides:
106 void OnTransientChildAdded(aura::Window* window, 107 void OnTransientChildAdded(aura::Window* window,
107 aura::Window* transient) override; 108 aura::Window* transient) override;
108 void OnTransientChildRemoved(aura::Window* window, 109 void OnTransientChildRemoved(aura::Window* window,
109 aura::Window* transient) override; 110 aura::Window* transient) override;
110 111
111 // content::NotificationObserver overrides: 112 // content::NotificationObserver overrides:
112 void Observe(int type, 113 void Observe(int type,
113 const content::NotificationSource& source, 114 const content::NotificationSource& source,
114 const content::NotificationDetails& details) override; 115 const content::NotificationDetails& details) override;
115 116
116 // Disable any animations for unit tests. 117 // Disable any animations for unit tests.
117 void SetAnimationSpeedForTest(AnimationSpeed speed); 118 void SetAnimationSpeedForTest(AnimationSpeed speed);
118 119
119 // Returns true when a user switch animation is running. For unit tests. 120 // Returns true when a user switch animation is running. For unit tests.
120 bool IsAnimationRunningForTest(); 121 bool IsAnimationRunningForTest();
121 122
122 // Returns the current user for unit tests. 123 // Returns the current user for unit tests.
123 const std::string& GetCurrentUserForTest() const; 124 const user_manager::UserID& GetCurrentUserForTest() const;
124 125
125 protected: 126 protected:
126 friend class UserSwitchAnimatorChromeOS; 127 friend class UserSwitchAnimatorChromeOS;
127 128
128 class WindowEntry { 129 class WindowEntry {
129 public: 130 public:
130 explicit WindowEntry(const std::string& user_id) 131 explicit WindowEntry(const user_manager::UserID& user_id)
131 : owner_(user_id), 132 : owner_(user_id),
132 show_for_user_(user_id), 133 show_for_user_(user_id),
133 show_(true) {} 134 show_(true) {}
134 virtual ~WindowEntry() {} 135 virtual ~WindowEntry() {}
135 136
136 // Returns the owner of this window. This cannot be changed. 137 // Returns the owner of this window. This cannot be changed.
137 const std::string& owner() const { return owner_; } 138 const user_manager::UserID& owner() const { return owner_; }
138 139
139 // Returns the user for which this should be shown. 140 // Returns the user for which this should be shown.
140 const std::string& show_for_user() const { return show_for_user_; } 141 const user_manager::UserID& show_for_user() const { return show_for_user_; }
141 142
142 // Returns if the window should be shown for the "show user" or not. 143 // Returns if the window should be shown for the "show user" or not.
143 bool show() const { return show_; } 144 bool show() const { return show_; }
144 145
145 // Set the user which will display the window on the owned desktop. If 146 // Set the user which will display the window on the owned desktop. If
146 // an empty user id gets passed the owner will be used. 147 // an empty user id gets passed the owner will be used.
147 void set_show_for_user(const std::string& user_id) { 148 void set_show_for_user(const user_manager::UserID& user_id) {
148 show_for_user_ = user_id.empty() ? owner_ : user_id; 149 show_for_user_ = user_id.empty() ? owner_ : user_id;
149 } 150 }
150 151
151 // Sets if the window gets shown for the active user or not. 152 // Sets if the window gets shown for the active user or not.
152 void set_show(bool show) { show_ = show; } 153 void set_show(bool show) { show_ = show; }
153 154
154 private: 155 private:
155 // The user id of the owner of this window. 156 // The user id of the owner of this window.
156 const std::string owner_; 157 const user_manager::UserID owner_;
157 158
158 // The user id of the user on which desktop the window gets shown. 159 // The user id of the user on which desktop the window gets shown.
159 std::string show_for_user_; 160 user_manager::UserID show_for_user_;
160 161
161 // True if the window should be visible for the user which shows the window. 162 // True if the window should be visible for the user which shows the window.
162 bool show_; 163 bool show_;
163 164
164 DISALLOW_COPY_AND_ASSIGN(WindowEntry); 165 DISALLOW_COPY_AND_ASSIGN(WindowEntry);
165 }; 166 };
166 167
167 typedef std::map<aura::Window*, WindowEntry*> WindowToEntryMap; 168 typedef std::map<aura::Window*, WindowEntry*> WindowToEntryMap;
168 169
169 // Show a window for a user without switching the user. 170 // Show a window for a user without switching the user.
170 // Returns true when the window moved to a new desktop. 171 // Returns true when the window moved to a new desktop.
171 bool ShowWindowForUserIntern(aura::Window* window, 172 bool ShowWindowForUserIntern(aura::Window* window,
172 const std::string& user_id); 173 const user_manager::UserID& user_id);
173 174
174 // Show / hide the given window. Note: By not doing this within the functions, 175 // Show / hide the given window. Note: By not doing this within the functions,
175 // this allows to either switching to different ways to show/hide and / or to 176 // this allows to either switching to different ways to show/hide and / or to
176 // distinguish state changes performed by this class vs. state changes 177 // distinguish state changes performed by this class vs. state changes
177 // performed by the others. Note furthermore that system modal dialogs will 178 // performed by the others. Note furthermore that system modal dialogs will
178 // not get hidden. We will switch instead to the owners desktop. 179 // not get hidden. We will switch instead to the owners desktop.
179 // The |animation_time_in_ms| is the time the animation should take. Set to 0 180 // The |animation_time_in_ms| is the time the animation should take. Set to 0
180 // if it should get set instantly. 181 // if it should get set instantly.
181 void SetWindowVisibility(aura::Window* window, 182 void SetWindowVisibility(aura::Window* window,
182 bool visible, 183 bool visible,
183 int animation_time_in_ms); 184 int animation_time_in_ms);
184 185
185 const WindowToEntryMap& window_to_entry() { return window_to_entry_; } 186 const WindowToEntryMap& window_to_entry() { return window_to_entry_; }
186 MultiUserNotificationBlockerChromeOS* notification_blocker() { 187 MultiUserNotificationBlockerChromeOS* notification_blocker() {
187 return notification_blocker_.get(); 188 return notification_blocker_.get();
188 } 189 }
189 190
190 private: 191 private:
191 friend class ::MultiUserNotificationBlockerChromeOSTest; 192 friend class ::MultiUserNotificationBlockerChromeOSTest;
192 friend class ash::test::MultiUserWindowManagerChromeOSTest; 193 friend class ash::test::MultiUserWindowManagerChromeOSTest;
193 194
194 typedef std::map<std::string, AppObserver*> UserIDToAppWindowObserver; 195 typedef std::map<user_manager::UserID, AppObserver*> UserIDToAppWindowObserver ;
195 typedef std::map<aura::Window*, bool> TransientWindowToVisibility; 196 typedef std::map<aura::Window*, bool> TransientWindowToVisibility;
196 197
197 // Add a browser window to the system so that the owner can be remembered. 198 // Add a browser window to the system so that the owner can be remembered.
198 void AddBrowserWindow(Browser* browser); 199 void AddBrowserWindow(Browser* browser);
199 200
200 // Show the window and its transient children. However - if a transient child 201 // Show the window and its transient children. However - if a transient child
201 // was turned invisible by some other operation, it will stay invisible. 202 // was turned invisible by some other operation, it will stay invisible.
202 // Use the given |animation_time_in_ms| for transitioning. 203 // Use the given |animation_time_in_ms| for transitioning.
203 void ShowWithTransientChildrenRecursive(aura::Window* window, 204 void ShowWithTransientChildrenRecursive(aura::Window* window,
204 int animation_time_in_ms); 205 int animation_time_in_ms);
(...skipping 30 matching lines...) Expand all
235 236
236 // An observer list to be notified upon window owner changes. 237 // An observer list to be notified upon window owner changes.
237 ObserverList<Observer> observers_; 238 ObserverList<Observer> observers_;
238 239
239 // A map which remembers for owned transient windows their own visibility. 240 // A map which remembers for owned transient windows their own visibility.
240 TransientWindowToVisibility transient_window_to_visibility_; 241 TransientWindowToVisibility transient_window_to_visibility_;
241 242
242 // The currently selected active user. It is used to find the proper 243 // The currently selected active user. It is used to find the proper
243 // visibility state in various cases. The state is stored here instead of 244 // visibility state in various cases. The state is stored here instead of
244 // being read from the user manager to be in sync while a switch occurs. 245 // being read from the user manager to be in sync while a switch occurs.
245 std::string current_user_id_; 246 user_manager::UserID current_user_id_;
247
248 const user_manager::UserID null_user_id_;
246 249
247 // The blocker which controls the desktop notification visibility based on the 250 // The blocker which controls the desktop notification visibility based on the
248 // current multi-user status. 251 // current multi-user status.
249 scoped_ptr<MultiUserNotificationBlockerChromeOS> notification_blocker_; 252 scoped_ptr<MultiUserNotificationBlockerChromeOS> notification_blocker_;
250 253
251 // The notification registrar to track the creation of browser windows. 254 // The notification registrar to track the creation of browser windows.
252 content::NotificationRegistrar registrar_; 255 content::NotificationRegistrar registrar_;
253 256
254 // Suppress changes to the visibility flag while we are changing it ourselves. 257 // Suppress changes to the visibility flag while we are changing it ourselves.
255 bool suppress_visibility_changes_; 258 bool suppress_visibility_changes_;
256 259
257 // The speed which is used to perform any animations. 260 // The speed which is used to perform any animations.
258 AnimationSpeed animation_speed_; 261 AnimationSpeed animation_speed_;
259 262
260 // The animation between users. 263 // The animation between users.
261 scoped_ptr<UserSwitchAnimatorChromeOS> animation_; 264 scoped_ptr<UserSwitchAnimatorChromeOS> animation_;
262 265
263 DISALLOW_COPY_AND_ASSIGN(MultiUserWindowManagerChromeOS); 266 DISALLOW_COPY_AND_ASSIGN(MultiUserWindowManagerChromeOS);
264 }; 267 };
265 268
266 } // namespace chrome 269 } // namespace chrome
267 270
268 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H _ 271 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_CHROMEOS_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698