Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.cc

Issue 2357143004: mash: Support ShelfWindowWatcher via ShelfItem properties. (Closed)
Patch Set: Address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" 5 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shelf/shelf_item_types.h" 8 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/wm_window_observer.h"
9 #include "ash/common/wm_window_property.h" 10 #include "ash/common/wm_window_property.h"
10 #include "ash/resources/grit/ash_resources.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
14 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 14 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/settings_window_manager.h" 19 #include "chrome/browser/ui/settings_window_manager.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/grit/generated_resources.h"
22 #include "components/strings/grit/components_strings.h"
23 #include "ui/base/l10n/l10n_util.h"
24 21
25 MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor( 22 MultiProfileBrowserStatusMonitor::MultiProfileBrowserStatusMonitor(
26 ChromeLauncherController* launcher_controller) 23 ChromeLauncherController* launcher_controller)
27 : BrowserStatusMonitor(launcher_controller), 24 : BrowserStatusMonitor(launcher_controller),
28 launcher_controller_(launcher_controller) { 25 launcher_controller_(launcher_controller) {
29 } 26 }
30 27
31 MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() { 28 MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() {
32 } 29 }
33 30
34 void MultiProfileBrowserStatusMonitor::ActiveUserChanged( 31 void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
35 const std::string& user_email) { 32 const std::string& user_email) {
36 // Handle windowed apps. 33 // Handle windowed apps.
37 for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) { 34 for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) {
38 bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile()); 35 bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile());
39 bool shown = IsV1AppInShelf(*it); 36 bool shown = IsV1AppInShelf(*it);
40 if (owned && !shown) 37 if (owned && !shown)
41 ConnectV1AppToLauncher(*it); 38 ConnectV1AppToLauncher(*it);
42 else if (!owned && shown) 39 else if (!owned && shown)
43 DisconnectV1AppFromLauncher(*it); 40 DisconnectV1AppFromLauncher(*it);
44 } 41 }
45 42
46 // Handle apps in browser tabs: Add the new applications. 43 // Handle apps in browser tabs: Add the new applications.
47 BrowserList* browser_list = BrowserList::GetInstance(); 44 BrowserList* browser_list = BrowserList::GetInstance();
48 45
49 // Remove old (tabbed V1) applications. 46 // Remove old (tabbed V1) applications.
50 for (BrowserList::const_iterator it = browser_list->begin(); 47 for (Browser* browser : *browser_list) {
51 it != browser_list->end(); ++it) {
52 Browser* browser = *it;
53 if (!browser->is_app() && 48 if (!browser->is_app() &&
54 browser->is_type_tabbed() && 49 browser->is_type_tabbed() &&
55 !multi_user_util::IsProfileFromActiveUser(browser->profile())) { 50 !multi_user_util::IsProfileFromActiveUser(browser->profile())) {
56 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 51 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
57 launcher_controller_->UpdateAppState( 52 launcher_controller_->UpdateAppState(
58 browser->tab_strip_model()->GetWebContentsAt(i), 53 browser->tab_strip_model()->GetWebContentsAt(i),
59 ChromeLauncherController::APP_STATE_REMOVED); 54 ChromeLauncherController::APP_STATE_REMOVED);
60 } 55 }
61 } 56 }
62 } 57 }
63 58
64 // Handle apps in browser tabs: Add new (tabbed V1) applications. 59 // Handle apps in browser tabs: Add new (tabbed V1) applications.
65 for (BrowserList::const_iterator it = browser_list->begin(); 60 for (Browser* browser : *browser_list) {
66 it != browser_list->end(); ++it) {
67 Browser* browser = *it;
68 if (!browser->is_app() && 61 if (!browser->is_app() &&
69 browser->is_type_tabbed() && 62 browser->is_type_tabbed() &&
70 multi_user_util::IsProfileFromActiveUser(browser->profile())) { 63 multi_user_util::IsProfileFromActiveUser(browser->profile())) {
71 int active_index = browser->tab_strip_model()->active_index(); 64 int active_index = browser->tab_strip_model()->active_index();
72 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 65 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
73 launcher_controller_->UpdateAppState( 66 launcher_controller_->UpdateAppState(
74 browser->tab_strip_model()->GetWebContentsAt(i), 67 browser->tab_strip_model()->GetWebContentsAt(i),
75 browser->window()->IsActive() && i == active_index ? 68 browser->window()->IsActive() && i == active_index ?
76 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE : 69 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE :
77 ChromeLauncherController::APP_STATE_INACTIVE); 70 ChromeLauncherController::APP_STATE_INACTIVE);
78 } 71 }
79 } 72 }
80 } 73 }
81 74
82 // Remove settings window icons not associated with this profile and create 75 // Hide settings window shelf items not associated with this profile and
83 // icons for windows associated with the current profile. 76 // restore items for windows associated with the current profile.
84 for (BrowserList::const_iterator it = browser_list->begin(); 77 for (Browser* browser : *browser_list) {
85 it != browser_list->end(); ++it) { 78 if (chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(
86 Browser* browser = *it;
87 if (!chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(
88 browser)) { 79 browser)) {
89 continue; 80 aura::Window* aura_window = browser->window()->GetNativeWindow();
90 } 81 ash::WmWindowAura::Get(aura_window)
91 aura::Window* aura_window = browser->window()->GetNativeWindow(); 82 ->SetIntProperty(
92 if (multi_user_util::IsProfileFromActiveUser(browser->profile())) { 83 ash::WmWindowProperty::SHELF_ITEM_TYPE,
93 ash::ShelfItemDetails item_details; 84 multi_user_util::IsProfileFromActiveUser(browser->profile())
94 item_details.type = ash::TYPE_DIALOG; 85 ? ash::TYPE_DIALOG
95 item_details.image_resource_id = IDR_ASH_SHELF_ICON_SETTINGS; 86 : ash::TYPE_UNDEFINED);
96 item_details.title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
97 ash::WmWindowAura::Get(aura_window)->SetShelfItemDetails(item_details);
98 } else {
99 ash::WmWindowAura::Get(aura_window)->ClearShelfItemDetails();
100 } 87 }
101 } 88 }
102 89
103 // Update the browser state since some of the removals / adds above might have 90 // Update the browser state since some of the removals / adds above might have
104 // had an impact on the browser item. 91 // had an impact on the browser item.
105 UpdateBrowserItemState(); 92 UpdateBrowserItemState();
106 } 93 }
107 94
108 void MultiProfileBrowserStatusMonitor::AddV1AppToShelf(Browser* browser) { 95 void MultiProfileBrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
109 DCHECK(browser->is_type_popup() && browser->is_app()); 96 DCHECK(browser->is_type_popup() && browser->is_app());
(...skipping 27 matching lines...) Expand all
137 124
138 void MultiProfileBrowserStatusMonitor::DisconnectV1AppFromLauncher( 125 void MultiProfileBrowserStatusMonitor::DisconnectV1AppFromLauncher(
139 Browser* browser) { 126 Browser* browser) {
140 // Removing a V1 app from the launcher requires to remove the content and 127 // Removing a V1 app from the launcher requires to remove the content and
141 // the launcher item. 128 // the launcher item.
142 launcher_controller_->UpdateAppState( 129 launcher_controller_->UpdateAppState(
143 browser->tab_strip_model()->GetActiveWebContents(), 130 browser->tab_strip_model()->GetActiveWebContents(),
144 ChromeLauncherController::APP_STATE_REMOVED); 131 ChromeLauncherController::APP_STATE_REMOVED);
145 BrowserStatusMonitor::RemoveV1AppFromShelf(browser); 132 BrowserStatusMonitor::RemoveV1AppFromShelf(browser);
146 } 133 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/browser_status_monitor.cc ('k') | chrome/browser/ui/views/task_manager_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698