Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / multi_profile_browser_status_monitor.cc
blobac2bb4ac64670e5f37242dfe37fe26f827755244
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 "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor(
18 ChromeLauncherController* launcher_controller)
19 : BrowserStatusMonitor(launcher_controller),
20 launcher_controller_(launcher_controller) {
23 MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() {
26 void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
27 const std::string& user_email) {
28 // Handle windowed apps.
29 for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) {
30 bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile());
31 bool shown = IsV1AppInShelf(*it);
32 if (owned && !shown)
33 ConnectV1AppToLauncher(*it);
34 else if (!owned && shown)
35 DisconnectV1AppFromLauncher(*it);
38 // Handle apps in browser tabs: Add the new applications.
39 BrowserList* browser_list =
40 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
42 // Remove old (tabbed V1) applications.
43 for (BrowserList::const_iterator it = browser_list->begin();
44 it != browser_list->end(); ++it) {
45 Browser* browser = *it;
46 if (!browser->is_app() &&
47 browser->is_type_tabbed() &&
48 !multi_user_util::IsProfileFromActiveUser(browser->profile())) {
49 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
50 launcher_controller_->UpdateAppState(
51 browser->tab_strip_model()->GetWebContentsAt(i),
52 ChromeLauncherController::APP_STATE_REMOVED);
57 // Handle apps in browser tabs: Add new (tabbed V1) applications.
58 for (BrowserList::const_iterator it = browser_list->begin();
59 it != browser_list->end(); ++it) {
60 Browser* browser = *it;
61 if (!browser->is_app() &&
62 browser->is_type_tabbed() &&
63 multi_user_util::IsProfileFromActiveUser(browser->profile())) {
64 int active_index = browser->tab_strip_model()->active_index();
65 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
66 launcher_controller_->UpdateAppState(
67 browser->tab_strip_model()->GetWebContentsAt(i),
68 browser->window()->IsActive() && i == active_index ?
69 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE :
70 ChromeLauncherController::APP_STATE_INACTIVE);
75 // Update the browser state since some of the removals / adds above might have
76 // had an impact on the browser item.
77 UpdateBrowserItemState();
80 void MultiProfileBrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
81 DCHECK(browser->is_type_popup() && browser->is_app());
82 DCHECK(std::find(app_list_.begin(), app_list_.end(), browser) ==
83 app_list_.end());
84 app_list_.push_back(browser);
85 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
86 BrowserStatusMonitor::AddV1AppToShelf(browser);
90 void MultiProfileBrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) {
91 DCHECK(browser->is_type_popup() && browser->is_app());
92 AppList::iterator it = std::find(app_list_.begin(), app_list_.end(), browser);
93 DCHECK(it != app_list_.end());
94 app_list_.erase(it);
95 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
96 BrowserStatusMonitor::RemoveV1AppFromShelf(browser);
100 void MultiProfileBrowserStatusMonitor::ConnectV1AppToLauncher(
101 Browser* browser) {
102 // Adding a V1 app to the launcher consists of two actions: Add the browser
103 // (launcher item) and add the content (launcher item status).
104 BrowserStatusMonitor::AddV1AppToShelf(browser);
105 launcher_controller_->UpdateAppState(
106 browser->tab_strip_model()->GetActiveWebContents(),
107 ChromeLauncherController::APP_STATE_INACTIVE);
110 void MultiProfileBrowserStatusMonitor::DisconnectV1AppFromLauncher(
111 Browser* browser) {
112 // Removing a V1 app from the launcher requires to remove the content and
113 // the launcher item.
114 launcher_controller_->UpdateAppState(
115 browser->tab_strip_model()->GetActiveWebContents(),
116 ChromeLauncherController::APP_STATE_REMOVED);
117 BrowserStatusMonitor::RemoveV1AppFromShelf(browser);