OLD | NEW |
---|---|
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 "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/multi_profile_uma.h" | 10 #include "ash/multi_profile_uma.h" |
11 #include "ash/session_state_delegate.h" | 11 #include "ash/session_state_delegate.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/wm/mru_window_tracker.h" | 15 #include "ash/wm/mru_window_tracker.h" |
16 #include "ash/wm/window_positioner.h" | 16 #include "ash/wm/window_positioner.h" |
17 #include "ash/wm/window_state.h" | 17 #include "ash/wm/window_state.h" |
18 #include "base/auto_reset.h" | 18 #include "base/auto_reset.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_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_util.h" | 27 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
32 #include "google_apis/gaia/gaia_auth_util.h" | 33 #include "google_apis/gaia/gaia_auth_util.h" |
33 #include "ui/aura/client/activation_client.h" | 34 #include "ui/aura/client/activation_client.h" |
34 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
35 #include "ui/aura/root_window.h" | 36 #include "ui/aura/root_window.h" |
36 #include "ui/aura/window.h" | 37 #include "ui/aura/window.h" |
37 #include "ui/base/ui_base_types.h" | 38 #include "ui/base/ui_base_types.h" |
38 #include "ui/events/event.h" | 39 #include "ui/events/event.h" |
40 #include "ui/message_center/message_center.h" | |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 // Checks if a given event is a user event. | 44 // Checks if a given event is a user event. |
43 bool IsUserEvent(ui::Event* e) { | 45 bool IsUserEvent(ui::Event* e) { |
44 if (e) { | 46 if (e) { |
45 ui::EventType type = e->type(); | 47 ui::EventType type = e->type(); |
46 if (type != ui::ET_CANCEL_MODE && | 48 if (type != ui::ET_CANCEL_MODE && |
47 type != ui::ET_UMA_DATA && | 49 type != ui::ET_UMA_DATA && |
48 type != ui::ET_UNKNOWN) | 50 type != ui::ET_UNKNOWN) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 171 |
170 private: | 172 private: |
171 std::string user_id_; | 173 std::string user_id_; |
172 | 174 |
173 DISALLOW_COPY_AND_ASSIGN(AppObserver); | 175 DISALLOW_COPY_AND_ASSIGN(AppObserver); |
174 }; | 176 }; |
175 | 177 |
176 MultiUserWindowManagerChromeOS::MultiUserWindowManagerChromeOS( | 178 MultiUserWindowManagerChromeOS::MultiUserWindowManagerChromeOS( |
177 const std::string& current_user_id) | 179 const std::string& current_user_id) |
178 : current_user_id_(current_user_id), | 180 : current_user_id_(current_user_id), |
181 notification_blocker_(new MultiUserNotificationBlockerChromeOS( | |
182 message_center::MessageCenter::Get())), | |
179 suppress_visibility_changes_(false) { | 183 suppress_visibility_changes_(false) { |
180 // Add a session state observer to be able to monitor session changes. | 184 // Add a session state observer to be able to monitor session changes. |
181 if (ash::Shell::HasInstance()) | 185 if (ash::Shell::HasInstance()) |
182 ash::Shell::GetInstance()->session_state_delegate()-> | 186 ash::Shell::GetInstance()->session_state_delegate()-> |
183 AddSessionStateObserver(this); | 187 AddSessionStateObserver(this); |
184 | 188 |
185 // The BrowserListObserver would have been better to use then the old | 189 // The BrowserListObserver would have been better to use then the old |
186 // notification system, but that observer fires before the window got created. | 190 // notification system, but that observer fires before the window got created. |
187 registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY, | 191 registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY, |
188 content::NotificationService::AllSources()); | 192 content::NotificationService::AllSources()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 244 |
241 // Check if this window was created due to a user interaction. If it was, | 245 // Check if this window was created due to a user interaction. If it was, |
242 // transfer it to the current user. | 246 // transfer it to the current user. |
243 if (IsProcessingUserEvent()) | 247 if (IsProcessingUserEvent()) |
244 window_to_entry_[window]->set_show_for_user(current_user_id_); | 248 window_to_entry_[window]->set_show_for_user(current_user_id_); |
245 | 249 |
246 // Add all transient children to our set of windows. Note that the function | 250 // Add all transient children to our set of windows. Note that the function |
247 // will add the children but not the owner to the transient children map. | 251 // will add the children but not the owner to the transient children map. |
248 AddTransientOwnerRecursive(window, window); | 252 AddTransientOwnerRecursive(window, window); |
249 | 253 |
254 notification_blocker_->UpdateWindowOwners(); | |
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
At the moment we have only this use case, but we m
Jun Mukai
2014/01/08 20:41:24
Done.
| |
255 | |
250 if (!IsWindowOnDesktopOfUser(window, current_user_id_)) | 256 if (!IsWindowOnDesktopOfUser(window, current_user_id_)) |
251 SetWindowVisibility(window, false); | 257 SetWindowVisibility(window, false); |
252 } | 258 } |
253 | 259 |
254 const std::string& MultiUserWindowManagerChromeOS::GetWindowOwner( | 260 const std::string& MultiUserWindowManagerChromeOS::GetWindowOwner( |
255 aura::Window* window) { | 261 aura::Window* window) { |
256 WindowToEntryMap::iterator it = window_to_entry_.find(window); | 262 WindowToEntryMap::iterator it = window_to_entry_.find(window); |
257 return it != window_to_entry_.end() ? it->second->owner() | 263 return it != window_to_entry_.end() ? it->second->owner() |
258 : base::EmptyString(); | 264 : base::EmptyString(); |
259 } | 265 } |
(...skipping 27 matching lines...) Expand all Loading... | |
287 it->second->set_show_for_user(user_id); | 293 it->second->set_show_for_user(user_id); |
288 | 294 |
289 // Show the window if the added user is the current one. | 295 // Show the window if the added user is the current one. |
290 if (user_id == current_user_id_) { | 296 if (user_id == current_user_id_) { |
291 // Only show the window if it should be shown according to its state. | 297 // Only show the window if it should be shown according to its state. |
292 if (it->second->show()) | 298 if (it->second->show()) |
293 SetWindowVisibility(window, true); | 299 SetWindowVisibility(window, true); |
294 } else { | 300 } else { |
295 SetWindowVisibility(window, false); | 301 SetWindowVisibility(window, false); |
296 } | 302 } |
303 | |
304 notification_blocker_->UpdateWindowOwners(); | |
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
See above
Jun Mukai
2014/01/08 20:41:24
Done.
| |
297 } | 305 } |
298 | 306 |
299 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() { | 307 bool MultiUserWindowManagerChromeOS::AreWindowsSharedAmongUsers() { |
300 WindowToEntryMap::iterator it = window_to_entry_.begin(); | 308 WindowToEntryMap::iterator it = window_to_entry_.begin(); |
301 for (; it != window_to_entry_.end(); ++it) { | 309 for (; it != window_to_entry_.end(); ++it) { |
302 if (it->second->owner() != it->second->show_for_user()) | 310 if (it->second->owner() != it->second->show_for_user()) |
303 return true; | 311 return true; |
304 } | 312 } |
305 return false; | 313 return false; |
306 } | 314 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 406 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
399 if (IsWindowOnDesktopOfUser(window, user_id) && | 407 if (IsWindowOnDesktopOfUser(window, user_id) && |
400 !window_state->IsMinimized()) { | 408 !window_state->IsMinimized()) { |
401 aura::client::ActivationClient* client = | 409 aura::client::ActivationClient* client = |
402 aura::client::GetActivationClient(window->GetRootWindow()); | 410 aura::client::GetActivationClient(window->GetRootWindow()); |
403 // Several unit tests come here without an activation client. | 411 // Several unit tests come here without an activation client. |
404 if (client) | 412 if (client) |
405 client->ActivateWindow(window); | 413 client->ActivateWindow(window); |
406 } | 414 } |
407 } | 415 } |
416 | |
417 // This is called directly here to make sure notification_blocker will see the | |
418 // new window status. | |
419 notification_blocker_->ActiveUserChanged(user_id); | |
408 } | 420 } |
409 | 421 |
410 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) { | 422 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) { |
411 if (GetWindowOwner(window).empty()) { | 423 if (GetWindowOwner(window).empty()) { |
412 // This must be a window in the transient chain - remove it and its | 424 // This must be a window in the transient chain - remove it and its |
413 // children from the owner. | 425 // children from the owner. |
414 RemoveTransientOwnerRecursive(window); | 426 RemoveTransientOwnerRecursive(window); |
415 return; | 427 return; |
416 } | 428 } |
417 // Remove the state and the window observer. | 429 // Remove the state and the window observer. |
418 ash::wm::GetWindowState(window)->RemoveObserver(this); | 430 ash::wm::GetWindowState(window)->RemoveObserver(this); |
419 // Remove the window from the owners list. | 431 // Remove the window from the owners list. |
420 delete window_to_entry_[window]; | 432 delete window_to_entry_[window]; |
421 window_to_entry_.erase(window); | 433 window_to_entry_.erase(window); |
434 notification_blocker_->UpdateWindowOwners(); | |
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
And again.
Jun Mukai
2014/01/08 20:41:24
Done.
| |
422 } | 435 } |
423 | 436 |
424 void MultiUserWindowManagerChromeOS::OnWindowVisibilityChanging( | 437 void MultiUserWindowManagerChromeOS::OnWindowVisibilityChanging( |
425 aura::Window* window, bool visible) { | 438 aura::Window* window, bool visible) { |
426 // This command gets called first and immediately when show or hide gets | 439 // This command gets called first and immediately when show or hide gets |
427 // called. We remember here the desired state for restoration IF we were | 440 // called. We remember here the desired state for restoration IF we were |
428 // not ourselves issuing the call. | 441 // not ourselves issuing the call. |
429 // Note also that using the OnWindowVisibilityChanged callback cannot be | 442 // Note also that using the OnWindowVisibilityChanged callback cannot be |
430 // used for this. | 443 // used for this. |
431 if (suppress_visibility_changes_) | 444 if (suppress_visibility_changes_) |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 // To prevent these commands from being recorded as any other commands, we | 650 // To prevent these commands from being recorded as any other commands, we |
638 // are suppressing any window entry changes while this is going on. | 651 // are suppressing any window entry changes while this is going on. |
639 // Instead of calling SetWindowVisible, only show gets called here since all | 652 // Instead of calling SetWindowVisible, only show gets called here since all |
640 // dependents have been shown previously already. | 653 // dependents have been shown previously already. |
641 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true); | 654 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true); |
642 window->Show(); | 655 window->Show(); |
643 } | 656 } |
644 } | 657 } |
645 | 658 |
646 } // namespace chrome | 659 } // namespace chrome |
OLD | NEW |