| 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/launcher/multi_profile_shell_window_launcher_con
troller.h" | 5 #include "chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_con
troller.h" |
| 6 | 6 |
| 7 #include "apps/shell_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 11 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 bool ControlsWindow(aura::Window* window) { | 15 bool ControlsWindow(aura::Window* window) { |
| 16 return chrome::GetHostDesktopTypeForNativeWindow(window) == | 16 return chrome::GetHostDesktopTypeForNativeWindow(window) == |
| 17 chrome::HOST_DESKTOP_TYPE_ASH; | 17 chrome::HOST_DESKTOP_TYPE_ASH; |
| 18 } | 18 } |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 | 22 |
| 23 MultiProfileShellWindowLauncherController:: | 23 MultiProfileShellWindowLauncherController:: |
| 24 MultiProfileShellWindowLauncherController( | 24 MultiProfileShellWindowLauncherController( |
| 25 ChromeLauncherController* owner) | 25 ChromeLauncherController* owner) |
| 26 : ShellWindowLauncherController(owner) { | 26 : ShellWindowLauncherController(owner) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 MultiProfileShellWindowLauncherController:: | 29 MultiProfileShellWindowLauncherController:: |
| 30 ~MultiProfileShellWindowLauncherController() { | 30 ~MultiProfileShellWindowLauncherController() { |
| 31 // We need to remove all Registry observers for added users. | 31 // We need to remove all Registry observers for added users. |
| 32 for (ShellWindowRegistryList::iterator it = multi_user_registry_.begin(); | 32 for (AppWindowRegistryList::iterator it = multi_user_registry_.begin(); |
| 33 it != multi_user_registry_.end(); ++it) | 33 it != multi_user_registry_.end(); |
| 34 ++it) |
| 34 (*it)->RemoveObserver(this); | 35 (*it)->RemoveObserver(this); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void MultiProfileShellWindowLauncherController::ActiveUserChanged( | 38 void MultiProfileShellWindowLauncherController::ActiveUserChanged( |
| 38 const std::string& user_email) { | 39 const std::string& user_email) { |
| 39 // The active user has changed and we need to traverse our list of items to | 40 // The active user has changed and we need to traverse our list of items to |
| 40 // show / hide them one by one. To avoid that a user dependent state | 41 // show / hide them one by one. To avoid that a user dependent state |
| 41 // "survives" in a launcher item, we first delete all items making sure that | 42 // "survives" in a launcher item, we first delete all items making sure that |
| 42 // nothing remains and then re-create them again. | 43 // nothing remains and then re-create them again. |
| 43 for (ShellWindowList::iterator it = shell_window_list_.begin(); | 44 for (AppWindowList::iterator it = app_window_list_.begin(); |
| 44 it != shell_window_list_.end(); ++it) { | 45 it != app_window_list_.end(); |
| 45 apps::ShellWindow* shell_window = *it; | 46 ++it) { |
| 47 apps::AppWindow* app_window = *it; |
| 46 Profile* profile = | 48 Profile* profile = |
| 47 Profile::FromBrowserContext(shell_window->browser_context()); | 49 Profile::FromBrowserContext(app_window->browser_context()); |
| 48 if (!multi_user_util::IsProfileFromActiveUser(profile) && | 50 if (!multi_user_util::IsProfileFromActiveUser(profile) && |
| 49 IsRegisteredApp(shell_window->GetNativeWindow())) | 51 IsRegisteredApp(app_window->GetNativeWindow())) |
| 50 UnregisterApp(shell_window->GetNativeWindow()); | 52 UnregisterApp(app_window->GetNativeWindow()); |
| 51 } | 53 } |
| 52 for (ShellWindowList::iterator it = shell_window_list_.begin(); | 54 for (AppWindowList::iterator it = app_window_list_.begin(); |
| 53 it != shell_window_list_.end(); ++it) { | 55 it != app_window_list_.end(); |
| 54 apps::ShellWindow* shell_window = *it; | 56 ++it) { |
| 57 apps::AppWindow* app_window = *it; |
| 55 Profile* profile = | 58 Profile* profile = |
| 56 Profile::FromBrowserContext(shell_window->browser_context()); | 59 Profile::FromBrowserContext(app_window->browser_context()); |
| 57 if (multi_user_util::IsProfileFromActiveUser(profile) && | 60 if (multi_user_util::IsProfileFromActiveUser(profile) && |
| 58 !IsRegisteredApp(shell_window->GetNativeWindow())) | 61 !IsRegisteredApp(app_window->GetNativeWindow())) |
| 59 RegisterApp(*it); | 62 RegisterApp(*it); |
| 60 } | 63 } |
| 61 } | 64 } |
| 62 | 65 |
| 63 void MultiProfileShellWindowLauncherController::AdditionalUserAddedToSession( | 66 void MultiProfileShellWindowLauncherController::AdditionalUserAddedToSession( |
| 64 Profile* profile) { | 67 Profile* profile) { |
| 65 // Each users ShellRegistry needs to be observed. | 68 // Each users AppWindowRegistry needs to be observed. |
| 66 apps::ShellWindowRegistry* registry = apps::ShellWindowRegistry::Get(profile); | 69 apps::AppWindowRegistry* registry = apps::AppWindowRegistry::Get(profile); |
| 67 multi_user_registry_.push_back(registry); | 70 multi_user_registry_.push_back(registry); |
| 68 registry->AddObserver(this); | 71 registry->AddObserver(this); |
| 69 } | 72 } |
| 70 | 73 |
| 71 void MultiProfileShellWindowLauncherController::OnShellWindowAdded( | 74 void MultiProfileShellWindowLauncherController::OnAppWindowAdded( |
| 72 apps::ShellWindow* shell_window) { | 75 apps::AppWindow* app_window) { |
| 73 if (!ControlsWindow(shell_window->GetNativeWindow())) | 76 if (!ControlsWindow(app_window->GetNativeWindow())) |
| 74 return; | 77 return; |
| 75 shell_window_list_.push_back(shell_window); | 78 app_window_list_.push_back(app_window); |
| 76 Profile* profile = | 79 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); |
| 77 Profile::FromBrowserContext(shell_window->browser_context()); | |
| 78 if (multi_user_util::IsProfileFromActiveUser(profile)) | 80 if (multi_user_util::IsProfileFromActiveUser(profile)) |
| 79 RegisterApp(shell_window); | 81 RegisterApp(app_window); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void MultiProfileShellWindowLauncherController::OnShellWindowRemoved( | 84 void MultiProfileShellWindowLauncherController::OnAppWindowRemoved( |
| 83 apps::ShellWindow* shell_window) { | 85 apps::AppWindow* app_window) { |
| 84 if (!ControlsWindow(shell_window->GetNativeWindow())) | 86 if (!ControlsWindow(app_window->GetNativeWindow())) |
| 85 return; | 87 return; |
| 86 | 88 |
| 87 // If the application is registered with ShellWindowLauncher (because the user | 89 // If the application is registered with ShellWindowLauncher (because the user |
| 88 // is currently active), the OnWindowDestroying observer has already (or will | 90 // is currently active), the OnWindowDestroying observer has already (or will |
| 89 // soon) unregister it independently from the shelf. If it was not registered | 91 // soon) unregister it independently from the shelf. If it was not registered |
| 90 // we don't need to do anything anyways. As such, all which is left to do here | 92 // we don't need to do anything anyways. As such, all which is left to do here |
| 91 // is to get rid of our own reference. | 93 // is to get rid of our own reference. |
| 92 ShellWindowList::iterator it = std::find(shell_window_list_.begin(), | 94 AppWindowList::iterator it = |
| 93 shell_window_list_.end(), | 95 std::find(app_window_list_.begin(), app_window_list_.end(), app_window); |
| 94 shell_window); | 96 DCHECK(it != app_window_list_.end()); |
| 95 DCHECK(it != shell_window_list_.end()); | 97 app_window_list_.erase(it); |
| 96 shell_window_list_.erase(it); | |
| 97 } | 98 } |
| OLD | NEW |