Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / multi_profile_browser_status_monitor.cc
blob72095f4c785ca93aa2d892898184572f117b2b0a
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_browser_status_monitor.h"
7 #include "ash/shelf/shelf_util.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/settings_window_manager.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "grit/ash_resources.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
22 MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor(
23 ChromeLauncherController* launcher_controller)
24 : BrowserStatusMonitor(launcher_controller),
25 launcher_controller_(launcher_controller) {
28 MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() {
31 void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
32 const std::string& user_email) {
33 // Handle windowed apps.
34 for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) {
35 bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile());
36 bool shown = IsV1AppInShelf(*it);
37 if (owned && !shown)
38 ConnectV1AppToLauncher(*it);
39 else if (!owned && shown)
40 DisconnectV1AppFromLauncher(*it);
43 // Handle apps in browser tabs: Add the new applications.
44 BrowserList* browser_list =
45 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
47 // Remove old (tabbed V1) applications.
48 for (BrowserList::const_iterator it = browser_list->begin();
49 it != browser_list->end(); ++it) {
50 Browser* browser = *it;
51 if (!browser->is_app() &&
52 browser->is_type_tabbed() &&
53 !multi_user_util::IsProfileFromActiveUser(browser->profile())) {
54 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
55 launcher_controller_->UpdateAppState(
56 browser->tab_strip_model()->GetWebContentsAt(i),
57 ChromeLauncherController::APP_STATE_REMOVED);
62 // Handle apps in browser tabs: Add new (tabbed V1) applications.
63 for (BrowserList::const_iterator it = browser_list->begin();
64 it != browser_list->end(); ++it) {
65 Browser* browser = *it;
66 if (!browser->is_app() &&
67 browser->is_type_tabbed() &&
68 multi_user_util::IsProfileFromActiveUser(browser->profile())) {
69 int active_index = browser->tab_strip_model()->active_index();
70 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
71 launcher_controller_->UpdateAppState(
72 browser->tab_strip_model()->GetWebContentsAt(i),
73 browser->window()->IsActive() && i == active_index ?
74 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE :
75 ChromeLauncherController::APP_STATE_INACTIVE);
80 // Remove settings window icons not associated with this profile and create
81 // icons for windows associated with the current profile.
82 for (BrowserList::const_iterator it = browser_list->begin();
83 it != browser_list->end(); ++it) {
84 Browser* browser = *it;
85 if (!chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(
86 browser)) {
87 continue;
89 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
90 ash::SetShelfItemDetailsForDialogWindow(
91 browser->window()->GetNativeWindow(),
92 IDR_ASH_SHELF_ICON_SETTINGS,
93 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
94 } else {
95 ash::ClearShelfItemDetailsForWindow(browser->window()->GetNativeWindow());
99 // Update the browser state since some of the removals / adds above might have
100 // had an impact on the browser item.
101 UpdateBrowserItemState();
104 void MultiProfileBrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
105 DCHECK(browser->is_type_popup() && browser->is_app());
106 DCHECK(std::find(app_list_.begin(), app_list_.end(), browser) ==
107 app_list_.end());
108 app_list_.push_back(browser);
109 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
110 BrowserStatusMonitor::AddV1AppToShelf(browser);
114 void MultiProfileBrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) {
115 DCHECK(browser->is_type_popup() && browser->is_app());
116 AppList::iterator it = std::find(app_list_.begin(), app_list_.end(), browser);
117 DCHECK(it != app_list_.end());
118 app_list_.erase(it);
119 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
120 BrowserStatusMonitor::RemoveV1AppFromShelf(browser);
124 void MultiProfileBrowserStatusMonitor::ConnectV1AppToLauncher(
125 Browser* browser) {
126 // Adding a V1 app to the launcher consists of two actions: Add the browser
127 // (launcher item) and add the content (launcher item status).
128 BrowserStatusMonitor::AddV1AppToShelf(browser);
129 launcher_controller_->UpdateAppState(
130 browser->tab_strip_model()->GetActiveWebContents(),
131 ChromeLauncherController::APP_STATE_INACTIVE);
134 void MultiProfileBrowserStatusMonitor::DisconnectV1AppFromLauncher(
135 Browser* browser) {
136 // Removing a V1 app from the launcher requires to remove the content and
137 // the launcher item.
138 launcher_controller_->UpdateAppState(
139 browser->tab_strip_model()->GetActiveWebContents(),
140 ChromeLauncherController::APP_STATE_REMOVED);
141 BrowserStatusMonitor::RemoveV1AppFromShelf(browser);