This source file includes following definitions.
- launcher_controller_
- ActiveUserChanged
- AddV1AppToShelf
- RemoveV1AppFromShelf
- ConnectV1AppToLauncher
- DisconnectV1AppFromLauncher
#include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor(
ChromeLauncherController* launcher_controller)
: BrowserStatusMonitor(launcher_controller),
launcher_controller_(launcher_controller) {
}
MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() {
}
void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
const std::string& user_email) {
for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) {
bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile());
bool shown = IsV1AppInShelf(*it);
if (owned && !shown)
ConnectV1AppToLauncher(*it);
else if (!owned && shown)
DisconnectV1AppFromLauncher(*it);
}
BrowserList* browser_list =
BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
for (BrowserList::const_iterator it = browser_list->begin();
it != browser_list->end(); ++it) {
Browser* browser = *it;
if (!browser->is_app() &&
browser->is_type_tabbed() &&
!multi_user_util::IsProfileFromActiveUser(browser->profile())) {
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
launcher_controller_->UpdateAppState(
browser->tab_strip_model()->GetWebContentsAt(i),
ChromeLauncherController::APP_STATE_REMOVED);
}
}
}
for (BrowserList::const_iterator it = browser_list->begin();
it != browser_list->end(); ++it) {
Browser* browser = *it;
if (!browser->is_app() &&
browser->is_type_tabbed() &&
multi_user_util::IsProfileFromActiveUser(browser->profile())) {
int active_index = browser->tab_strip_model()->active_index();
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
launcher_controller_->UpdateAppState(
browser->tab_strip_model()->GetWebContentsAt(i),
browser->window()->IsActive() && i == active_index ?
ChromeLauncherController::APP_STATE_WINDOW_ACTIVE :
ChromeLauncherController::APP_STATE_INACTIVE);
}
}
}
UpdateBrowserItemState();
}
void MultiProfileBrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
DCHECK(browser->is_type_popup() && browser->is_app());
DCHECK(std::find(app_list_.begin(), app_list_.end(), browser) ==
app_list_.end());
app_list_.push_back(browser);
if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
BrowserStatusMonitor::AddV1AppToShelf(browser);
}
}
void MultiProfileBrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) {
DCHECK(browser->is_type_popup() && browser->is_app());
AppList::iterator it = std::find(app_list_.begin(), app_list_.end(), browser);
DCHECK(it != app_list_.end());
app_list_.erase(it);
if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
BrowserStatusMonitor::RemoveV1AppFromShelf(browser);
}
}
void MultiProfileBrowserStatusMonitor::ConnectV1AppToLauncher(
Browser* browser) {
BrowserStatusMonitor::AddV1AppToShelf(browser);
launcher_controller_->UpdateAppState(
browser->tab_strip_model()->GetActiveWebContents(),
ChromeLauncherController::APP_STATE_INACTIVE);
}
void MultiProfileBrowserStatusMonitor::DisconnectV1AppFromLauncher(
Browser* browser) {
launcher_controller_->UpdateAppState(
browser->tab_strip_model()->GetActiveWebContents(),
ChromeLauncherController::APP_STATE_REMOVED);
BrowserStatusMonitor::RemoveV1AppFromShelf(browser);
}