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