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

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

Issue 1428213004: This CL replaces std::string user_id in ash/* with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 1 month 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/signin/core/account_id/account_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 class Profile; 25 class Profile;
25 26
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public content::NotificationObserver, 63 public content::NotificationObserver,
63 public wm::TransientWindowObserver { 64 public wm::TransientWindowObserver {
64 public: 65 public:
65 // The speed which should be used to perform animations. 66 // The speed which should be used to perform animations.
66 enum AnimationSpeed { 67 enum AnimationSpeed {
67 ANIMATION_SPEED_NORMAL, // The normal animation speed. 68 ANIMATION_SPEED_NORMAL, // The normal animation speed.
68 ANIMATION_SPEED_FAST, // Unit test speed which test animations. 69 ANIMATION_SPEED_FAST, // Unit test speed which test animations.
69 ANIMATION_SPEED_DISABLED // Unit tests which do not require animations. 70 ANIMATION_SPEED_DISABLED // Unit tests which do not require animations.
70 }; 71 };
71 72
72 // Create the manager and use |active_user_id| as the active user. 73 // Create the manager and use |active_account_id| as the active user.
73 explicit MultiUserWindowManagerChromeOS(const std::string& active_user_id); 74 explicit MultiUserWindowManagerChromeOS(const AccountId& active_account_id);
74 ~MultiUserWindowManagerChromeOS() override; 75 ~MultiUserWindowManagerChromeOS() override;
75 76
76 // Initializes the manager after its creation. Should only be called once. 77 // Initializes the manager after its creation. Should only be called once.
77 void Init(); 78 void Init();
78 79
79 // MultiUserWindowManager overrides: 80 // MultiUserWindowManager overrides:
80 void SetWindowOwner( 81 void SetWindowOwner(aura::Window* window,
81 aura::Window* window, const std::string& user_id) override; 82 const AccountId& account_id) override;
82 const std::string& GetWindowOwner( 83 const AccountId& GetWindowOwner(aura::Window* window) const override;
83 aura::Window* window) const override; 84 void ShowWindowForUser(aura::Window* window,
84 void ShowWindowForUser( 85 const AccountId& account_id) override;
85 aura::Window* window, const std::string& user_id) override;
86 bool AreWindowsSharedAmongUsers() const override; 86 bool AreWindowsSharedAmongUsers() const override;
87 void GetOwnersOfVisibleWindows( 87 void GetOwnersOfVisibleWindows(
88 std::set<std::string>* user_ids) const override; 88 std::set<AccountId>* account_ids) const override;
89 bool IsWindowOnDesktopOfUser( 89 bool IsWindowOnDesktopOfUser(aura::Window* window,
90 aura::Window* window, 90 const AccountId& account_id) const override;
91 const std::string& user_id) const override; 91 const AccountId& GetUserPresentingWindow(aura::Window* window) const override;
92 const std::string& GetUserPresentingWindow(
93 aura::Window* window) const override;
94 void AddUser(content::BrowserContext* context) override; 92 void AddUser(content::BrowserContext* context) override;
95 void AddObserver(Observer* observer) override; 93 void AddObserver(Observer* observer) override;
96 void RemoveObserver(Observer* observer) override; 94 void RemoveObserver(Observer* observer) override;
97 95
98 // SessionStateObserver overrides: 96 // SessionStateObserver overrides:
99 void ActiveUserChanged(const std::string& user_id) override; 97 void ActiveUserChanged(const AccountId& account_id) override;
100 98
101 // WindowObserver overrides: 99 // WindowObserver overrides:
102 void OnWindowDestroyed(aura::Window* window) override; 100 void OnWindowDestroyed(aura::Window* window) override;
103 void OnWindowVisibilityChanging(aura::Window* window, bool visible) override; 101 void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;
104 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; 102 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
105 103
106 // TransientWindowObserver overrides: 104 // TransientWindowObserver overrides:
107 void OnTransientChildAdded(aura::Window* window, 105 void OnTransientChildAdded(aura::Window* window,
108 aura::Window* transient) override; 106 aura::Window* transient) override;
109 void OnTransientChildRemoved(aura::Window* window, 107 void OnTransientChildRemoved(aura::Window* window,
110 aura::Window* transient) override; 108 aura::Window* transient) override;
111 109
112 // content::NotificationObserver overrides: 110 // content::NotificationObserver overrides:
113 void Observe(int type, 111 void Observe(int type,
114 const content::NotificationSource& source, 112 const content::NotificationSource& source,
115 const content::NotificationDetails& details) override; 113 const content::NotificationDetails& details) override;
116 114
117 // Disable any animations for unit tests. 115 // Disable any animations for unit tests.
118 void SetAnimationSpeedForTest(AnimationSpeed speed); 116 void SetAnimationSpeedForTest(AnimationSpeed speed);
119 117
120 // Returns true when a user switch animation is running. For unit tests. 118 // Returns true when a user switch animation is running. For unit tests.
121 bool IsAnimationRunningForTest(); 119 bool IsAnimationRunningForTest();
122 120
123 // Returns the current user for unit tests. 121 // Returns the current user for unit tests.
124 const std::string& GetCurrentUserForTest() const; 122 const AccountId& GetCurrentUserForTest() const;
125 123
126 protected: 124 protected:
127 friend class UserSwitchAnimatorChromeOS; 125 friend class UserSwitchAnimatorChromeOS;
128 126
129 class WindowEntry { 127 class WindowEntry {
130 public: 128 public:
131 explicit WindowEntry(const std::string& user_id) 129 explicit WindowEntry(const AccountId& account_id)
132 : owner_(user_id), 130 : owner_(account_id), show_for_user_(account_id), show_(true) {}
133 show_for_user_(user_id),
134 show_(true) {}
135 virtual ~WindowEntry() {} 131 virtual ~WindowEntry() {}
136 132
137 // Returns the owner of this window. This cannot be changed. 133 // Returns the owner of this window. This cannot be changed.
138 const std::string& owner() const { return owner_; } 134 const AccountId& owner() const { return owner_; }
139 135
140 // Returns the user for which this should be shown. 136 // Returns the user for which this should be shown.
141 const std::string& show_for_user() const { return show_for_user_; } 137 const AccountId& show_for_user() const { return show_for_user_; }
142 138
143 // Returns if the window should be shown for the "show user" or not. 139 // Returns if the window should be shown for the "show user" or not.
144 bool show() const { return show_; } 140 bool show() const { return show_; }
145 141
146 // Set the user which will display the window on the owned desktop. If 142 // Set the user which will display the window on the owned desktop. If
147 // an empty user id gets passed the owner will be used. 143 // an empty user id gets passed the owner will be used.
148 void set_show_for_user(const std::string& user_id) { 144 void set_show_for_user(const AccountId& account_id) {
149 show_for_user_ = user_id.empty() ? owner_ : user_id; 145 show_for_user_ = account_id.is_valid() ? account_id : owner_;
150 } 146 }
151 147
152 // Sets if the window gets shown for the active user or not. 148 // Sets if the window gets shown for the active user or not.
153 void set_show(bool show) { show_ = show; } 149 void set_show(bool show) { show_ = show; }
154 150
155 private: 151 private:
156 // The user id of the owner of this window. 152 // The user id of the owner of this window.
157 const std::string owner_; 153 const AccountId owner_;
158 154
159 // The user id of the user on which desktop the window gets shown. 155 // The user id of the user on which desktop the window gets shown.
160 std::string show_for_user_; 156 AccountId show_for_user_;
161 157
162 // True if the window should be visible for the user which shows the window. 158 // True if the window should be visible for the user which shows the window.
163 bool show_; 159 bool show_;
164 160
165 DISALLOW_COPY_AND_ASSIGN(WindowEntry); 161 DISALLOW_COPY_AND_ASSIGN(WindowEntry);
166 }; 162 };
167 163
168 typedef std::map<aura::Window*, WindowEntry*> WindowToEntryMap; 164 typedef std::map<aura::Window*, WindowEntry*> WindowToEntryMap;
169 165
170 // Show a window for a user without switching the user. 166 // Show a window for a user without switching the user.
171 // Returns true when the window moved to a new desktop. 167 // Returns true when the window moved to a new desktop.
172 bool ShowWindowForUserIntern(aura::Window* window, 168 bool ShowWindowForUserIntern(aura::Window* window,
173 const std::string& user_id); 169 const AccountId& account_id);
174 170
175 // Show / hide the given window. Note: By not doing this within the functions, 171 // Show / hide the given window. Note: By not doing this within the functions,
176 // this allows to either switching to different ways to show/hide and / or to 172 // this allows to either switching to different ways to show/hide and / or to
177 // distinguish state changes performed by this class vs. state changes 173 // distinguish state changes performed by this class vs. state changes
178 // performed by the others. Note furthermore that system modal dialogs will 174 // performed by the others. Note furthermore that system modal dialogs will
179 // not get hidden. We will switch instead to the owners desktop. 175 // not get hidden. We will switch instead to the owners desktop.
180 // The |animation_time_in_ms| is the time the animation should take. Set to 0 176 // The |animation_time_in_ms| is the time the animation should take. Set to 0
181 // if it should get set instantly. 177 // if it should get set instantly.
182 void SetWindowVisibility(aura::Window* window, 178 void SetWindowVisibility(aura::Window* window,
183 bool visible, 179 bool visible,
184 int animation_time_in_ms); 180 int animation_time_in_ms);
185 181
186 const WindowToEntryMap& window_to_entry() { return window_to_entry_; } 182 const WindowToEntryMap& window_to_entry() { return window_to_entry_; }
187 MultiUserNotificationBlockerChromeOS* notification_blocker() { 183 MultiUserNotificationBlockerChromeOS* notification_blocker() {
188 return notification_blocker_.get(); 184 return notification_blocker_.get();
189 } 185 }
190 186
191 private: 187 private:
192 friend class ::MultiUserNotificationBlockerChromeOSTest; 188 friend class ::MultiUserNotificationBlockerChromeOSTest;
193 friend class ash::test::MultiUserWindowManagerChromeOSTest; 189 friend class ash::test::MultiUserWindowManagerChromeOSTest;
194 190
195 typedef std::map<std::string, AppObserver*> UserIDToAppWindowObserver; 191 typedef std::map<AccountId, AppObserver*> AccountIdToAppWindowObserver;
196 typedef std::map<aura::Window*, bool> TransientWindowToVisibility; 192 typedef std::map<aura::Window*, bool> TransientWindowToVisibility;
197 193
198 // Add a browser window to the system so that the owner can be remembered. 194 // Add a browser window to the system so that the owner can be remembered.
199 void AddBrowserWindow(Browser* browser); 195 void AddBrowserWindow(Browser* browser);
200 196
201 // Show the window and its transient children. However - if a transient child 197 // Show the window and its transient children. However - if a transient child
202 // was turned invisible by some other operation, it will stay invisible. 198 // was turned invisible by some other operation, it will stay invisible.
203 // Use the given |animation_time_in_ms| for transitioning. 199 // Use the given |animation_time_in_ms| for transitioning.
204 void ShowWithTransientChildrenRecursive(aura::Window* window, 200 void ShowWithTransientChildrenRecursive(aura::Window* window,
205 int animation_time_in_ms); 201 int animation_time_in_ms);
(...skipping 14 matching lines...) Expand all
220 216
221 // Animate a |window| to be |visible| in |animation_time_in_ms|. 217 // Animate a |window| to be |visible| in |animation_time_in_ms|.
222 void SetWindowVisible(aura::Window* window, 218 void SetWindowVisible(aura::Window* window,
223 bool visible, 219 bool visible,
224 int aimation_time_in_ms); 220 int aimation_time_in_ms);
225 221
226 // Get the animation time in milliseconds dependent on the |AnimationSpeed| 222 // Get the animation time in milliseconds dependent on the |AnimationSpeed|
227 // from the passed |default_time_in_ms|. 223 // from the passed |default_time_in_ms|.
228 int GetAdjustedAnimationTimeInMS(int default_time_in_ms) const; 224 int GetAdjustedAnimationTimeInMS(int default_time_in_ms) const;
229 225
230 // This is called when KeyedService (for |iser_id| and |profile|) is 226 // This is called when KeyedService (for |account_id| and |profile|) is
231 // destroyed, or when MultiUserWindowManagerChromeOS is destroyed. 227 // destroyed, or when MultiUserWindowManagerChromeOS is destroyed.
232 // This happens on shutdown, before profile prefs are stored to 228 // This happens on shutdown, before profile prefs are stored to
233 // disk. 229 // disk.
234 void RemoveUser(const std::string& user_id, Profile* profile); 230 void RemoveUser(const AccountId& account_id, Profile* profile);
235 231
236 // A lookup to see to which user the given window belongs to, where and if it 232 // A lookup to see to which user the given window belongs to, where and if it
237 // should get shown. 233 // should get shown.
238 WindowToEntryMap window_to_entry_; 234 WindowToEntryMap window_to_entry_;
239 235
240 // A list of all known users and their app window observers. 236 // A list of all known users and their app window observers.
241 UserIDToAppWindowObserver user_id_to_app_observer_; 237 AccountIdToAppWindowObserver account_id_to_app_observer_;
242 238
243 // An observer list to be notified upon window owner changes. 239 // An observer list to be notified upon window owner changes.
244 base::ObserverList<Observer> observers_; 240 base::ObserverList<Observer> observers_;
245 241
246 // A map which remembers for owned transient windows their own visibility. 242 // A map which remembers for owned transient windows their own visibility.
247 TransientWindowToVisibility transient_window_to_visibility_; 243 TransientWindowToVisibility transient_window_to_visibility_;
248 244
249 // The currently selected active user. It is used to find the proper 245 // The currently selected active user. It is used to find the proper
250 // visibility state in various cases. The state is stored here instead of 246 // visibility state in various cases. The state is stored here instead of
251 // being read from the user manager to be in sync while a switch occurs. 247 // being read from the user manager to be in sync while a switch occurs.
252 std::string current_user_id_; 248 AccountId current_account_id_;
253 249
254 // The blocker which controls the desktop notification visibility based on the 250 // The blocker which controls the desktop notification visibility based on the
255 // current multi-user status. 251 // current multi-user status.
256 scoped_ptr<MultiUserNotificationBlockerChromeOS> notification_blocker_; 252 scoped_ptr<MultiUserNotificationBlockerChromeOS> notification_blocker_;
257 253
258 // The notification registrar to track the creation of browser windows. 254 // The notification registrar to track the creation of browser windows.
259 content::NotificationRegistrar registrar_; 255 content::NotificationRegistrar registrar_;
260 256
261 // 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.
262 bool suppress_visibility_changes_; 258 bool suppress_visibility_changes_;
263 259
264 // The speed which is used to perform any animations. 260 // The speed which is used to perform any animations.
265 AnimationSpeed animation_speed_; 261 AnimationSpeed animation_speed_;
266 262
267 // The animation between users. 263 // The animation between users.
268 scoped_ptr<UserSwitchAnimatorChromeOS> animation_; 264 scoped_ptr<UserSwitchAnimatorChromeOS> animation_;
269 265
270 DISALLOW_COPY_AND_ASSIGN(MultiUserWindowManagerChromeOS); 266 DISALLOW_COPY_AND_ASSIGN(MultiUserWindowManagerChromeOS);
271 }; 267 };
272 268
273 } // namespace chrome 269 } // namespace chrome
274 270
275 #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