Commit de1e63d5 authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

Manage settings window icon for multi profile

Includes some minor refactoring: merges launcher_item_util.cc into
ash:shelf_util.cc

BUG=385161
R=ben@chromium.org, skuhne@chromium.org

Review URL: https://codereview.chromium.org/332163006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278629 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f94bfaa
......@@ -39,6 +39,16 @@ void SetShelfItemDetailsForWindow(aura::Window* window,
window->SetProperty(kShelfItemDetailsKey, item_details);
}
void SetShelfItemDetailsForDialogWindow(aura::Window* window,
int image_resource_id) {
// |item_details| is owned by |window|.
ShelfItemDetails* item_details = new ShelfItemDetails;
item_details->type = TYPE_DIALOG;
item_details->image_resource_id = image_resource_id;
item_details->title = window->title();
window->SetProperty(kShelfItemDetailsKey, item_details);
}
void ClearShelfItemDetailsForWindow(aura::Window* window) {
window->ClearProperty(kShelfItemDetailsKey);
}
......
......@@ -32,10 +32,16 @@ ASH_EXPORT void SetShelfIDForWindow(ShelfID id, aura::Window* window);
// currently active tab.
ASH_EXPORT ShelfID GetShelfIDForWindow(const aura::Window* window);
// Sets ShelfItemDetails for |window|.
// Creates a new ShelfItemDetails instance from |details| and sets it for
// |window|.
ASH_EXPORT void SetShelfItemDetailsForWindow(aura::Window* window,
const ShelfItemDetails& details);
// Creates a new ShelfItemDetails instance with type DIALOG and image id
// |image_resource_id| and sets it for |window|.
ASH_EXPORT void SetShelfItemDetailsForDialogWindow(aura::Window* window,
int image_resource_id);
// Clears ShelfItemDetails for |window|.
// If |window| has a ShelfItem by SetShelfItemDetailsForWindow(), it will
// be removed.
......
......@@ -23,6 +23,7 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/settings_window_manager.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/extensions/extension_constants.h"
......
......@@ -10,7 +10,6 @@
#include "base/stl_util.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_item_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -83,8 +82,9 @@ class BrowserStatusMonitor::SettingsWindowObserver
// SettingsWindowManagerObserver
virtual void OnNewSettingsWindow(Browser* settings_browser) OVERRIDE {
CreateShelfItemForDialog(IDR_ASH_SHELF_ICON_SETTINGS,
settings_browser->window()->GetNativeWindow());
ash::SetShelfItemDetailsForDialogWindow(
settings_browser->window()->GetNativeWindow(),
IDR_ASH_SHELF_ICON_SETTINGS);
}
private:
......
......@@ -2129,4 +2129,7 @@ IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, SettingsWindow) {
ASSERT_TRUE(settings_browser);
EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false));
EXPECT_EQ(item_count + 1, shelf_model->item_count());
// TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded.
// crbug.com/230464.
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_item_types.h"
#include "ash/shelf/shelf_util.h"
void CreateShelfItemForDialog(int image_resource_id, aura::Window* window) {
ash::ShelfItemDetails item_details;
item_details.type = ash::TYPE_DIALOG;
item_details.image_resource_id = image_resource_id;
item_details.title = window->title();
ash::SetShelfItemDetailsForWindow(window, item_details);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_UTIL_H_
#define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_UTIL_H_
#include "base/strings/string16.h"
namespace aura {
class Window;
}
// Creates an item on the shelf for |window|. The item is destroyed when the
// window is destroyed.
// TODO(simonhong): Move this function to NativeWidgetAura.
void CreateShelfItemForDialog(int image_resource_id,
aura::Window* window);
#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_UTIL_H_
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h"
#include "ash/shelf/shelf_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
......@@ -12,7 +13,9 @@
#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/settings_window_manager.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "grit/ash_resources.h"
MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor(
ChromeLauncherController* launcher_controller)
......@@ -72,6 +75,24 @@ void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
}
}
// Remove settings window icons not associated with this profile and create
// icons for windows associated with the current profile.
for (BrowserList::const_iterator it = browser_list->begin();
it != browser_list->end(); ++it) {
Browser* browser = *it;
if (!chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(
browser)) {
continue;
}
if (multi_user_util::IsProfileFromActiveUser(browser->profile())) {
ash::SetShelfItemDetailsForDialogWindow(
browser->window()->GetNativeWindow(),
IDR_ASH_SHELF_ICON_SETTINGS);
} else {
ash::ClearShelfItemDetailsForWindow(browser->window()->GetNativeWindow());
}
}
// Update the browser state since some of the removals / adds above might have
// had an impact on the browser item.
UpdateBrowserItemState();
......
......@@ -74,6 +74,13 @@ Browser* SettingsWindowManager::FindBrowserForProfile(Profile* profile) {
return NULL;
}
bool SettingsWindowManager::IsSettingsBrowser(Browser* browser) const {
ProfileSessionMap::const_iterator iter =
settings_session_map_.find(browser->profile());
return (iter != settings_session_map_.end() &&
iter->second == browser->session_id().id());
}
SettingsWindowManager::SettingsWindowManager() {
}
......
......@@ -38,6 +38,9 @@ class SettingsWindowManager {
// returns it, otherwise returns NULL.
Browser* FindBrowserForProfile(Profile* profile);
// Returns true if |browser| is a settings window.
bool IsSettingsBrowser(Browser* browser) const;
private:
friend struct DefaultSingletonTraits<SettingsWindowManager>;
typedef std::map<Profile*, SessionID::id_type> ProfileSessionMap;
......
......@@ -41,8 +41,8 @@
#include "ui/views/window/dialog_delegate.h"
#if defined(USE_ASH)
#include "ash/shelf/shelf_util.h"
#include "ash/wm/window_util.h"
#include "chrome/browser/ui/ash/launcher/launcher_item_util.h"
#include "grit/ash_resources.h"
#endif
......@@ -496,8 +496,9 @@ void TaskManagerView::Show(Browser* browser) {
focus_manager->SetFocusedView(instance_->tab_table_);
#if defined(USE_ASH)
CreateShelfItemForDialog(IDR_ASH_SHELF_ICON_TASK_MANAGER,
instance_->GetWidget()->GetNativeWindow());
ash::SetShelfItemDetailsForDialogWindow(
instance_->GetWidget()->GetNativeWindow(),
IDR_ASH_SHELF_ICON_TASK_MANAGER);
#endif
}
......
......@@ -329,8 +329,6 @@
'browser/ui/ash/launcher/launcher_favicon_loader.h',
'browser/ui/ash/launcher/launcher_item_controller.cc',
'browser/ui/ash/launcher/launcher_item_controller.h',
'browser/ui/ash/launcher/launcher_item_util.cc',
'browser/ui/ash/launcher/launcher_item_util.h',
'browser/ui/ash/launcher/multi_profile_app_window_launcher_controller.cc',
'browser/ui/ash/launcher/multi_profile_app_window_launcher_controller.h',
'browser/ui/ash/launcher/multi_profile_browser_status_monitor.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment