Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / multi_profile_shell_window_launcher_controller.cc
blob13280a99297fc67053595496affea981ea7754a4
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_controller.h"
7 #include "apps/shell_window.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
11 #include "chrome/browser/ui/host_desktop.h"
13 namespace {
15 bool ControlsWindow(aura::Window* window) {
16 return chrome::GetHostDesktopTypeForNativeWindow(window) ==
17 chrome::HOST_DESKTOP_TYPE_ASH;
20 } // namespace
23 MultiProfileShellWindowLauncherController::
24 MultiProfileShellWindowLauncherController(
25 ChromeLauncherController* owner)
26 : ShellWindowLauncherController(owner) {
29 MultiProfileShellWindowLauncherController::
30 ~MultiProfileShellWindowLauncherController() {
31 // We need to remove all Registry observers for added users.
32 for (ShellWindowRegistryList::iterator it = multi_user_registry_.begin();
33 it != multi_user_registry_.end(); ++it)
34 (*it)->RemoveObserver(this);
37 void MultiProfileShellWindowLauncherController::ActiveUserChanged(
38 const std::string& user_email) {
39 // 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 // "survives" in a launcher item, we first delete all items making sure that
42 // nothing remains and then re-create them again.
43 for (ShellWindowList::iterator it = shell_window_list_.begin();
44 it != shell_window_list_.end(); ++it) {
45 apps::ShellWindow* shell_window = *it;
46 if (!multi_user_util::IsProfileFromActiveUser(shell_window->profile()) &&
47 IsRegisteredApp(shell_window->GetNativeWindow()))
48 UnregisterApp(shell_window->GetNativeWindow());
50 for (ShellWindowList::iterator it = shell_window_list_.begin();
51 it != shell_window_list_.end(); ++it) {
52 apps::ShellWindow* shell_window = *it;
53 if (multi_user_util::IsProfileFromActiveUser(shell_window->profile()) &&
54 !IsRegisteredApp(shell_window->GetNativeWindow()))
55 RegisterApp(*it);
59 void MultiProfileShellWindowLauncherController::AdditionalUserAddedToSession(
60 Profile* profile) {
61 // Each users ShellRegistry needs to be observed.
62 apps::ShellWindowRegistry* registry = apps::ShellWindowRegistry::Get(profile);
63 multi_user_registry_.push_back(registry);
64 registry->AddObserver(this);
67 void MultiProfileShellWindowLauncherController::OnShellWindowAdded(
68 apps::ShellWindow* shell_window) {
69 if (!ControlsWindow(shell_window->GetNativeWindow()))
70 return;
71 shell_window_list_.push_back(shell_window);
72 if (multi_user_util::IsProfileFromActiveUser(shell_window->profile()))
73 RegisterApp(shell_window);
76 void MultiProfileShellWindowLauncherController::OnShellWindowRemoved(
77 apps::ShellWindow* shell_window) {
78 if (!ControlsWindow(shell_window->GetNativeWindow()))
79 return;
81 // If the application is registered with ShellWindowLauncher (because the user
82 // is currently active), the OnWindowDestroying observer has already (or will
83 // soon) unregister it independently from the shelf. If it was not registered
84 // we don't need to do anything anyways. As such, all which is left to do here
85 // is to get rid of our own reference.
86 ShellWindowList::iterator it = std::find(shell_window_list_.begin(),
87 shell_window_list_.end(),
88 shell_window);
89 DCHECK(it != shell_window_list_.end());
90 shell_window_list_.erase(it);