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

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

Issue 11418114: Add policy for ash launcher auto-hide behavior (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 // If the value of the pref at |local_path is not empty, it is returned 120 // If the value of the pref at |local_path is not empty, it is returned
121 // otherwise the value of the pref at |synced_path| is returned. 121 // otherwise the value of the pref at |synced_path| is returned.
122 std::string GetLocalOrRemotePref(PrefService* pref_service, 122 std::string GetLocalOrRemotePref(PrefService* pref_service,
123 const char* local_path, 123 const char* local_path,
124 const char* synced_path) { 124 const char* synced_path) {
125 const std::string value(pref_service->GetString(local_path)); 125 const std::string value(pref_service->GetString(local_path));
126 return value.empty() ? pref_service->GetString(synced_path) : value; 126 return value.empty() ? pref_service->GetString(synced_path) : value;
127 } 127 }
128 128
129 // If prefs have synced and the pref value at |local_path| is empty the value 129 // If prefs have synced and no user-set value exists at |local_path|, the value
130 // from |synced_path| is copied to |local_path|. 130 // from |synced_path| is copied to |local_path|.
131 void MaybePropagatePrefToLocal(PrefService* pref_service, 131 void MaybePropagatePrefToLocal(PrefService* pref_service,
132 const char* local_path, 132 const char* local_path,
133 const char* synced_path) { 133 const char* synced_path) {
134 if (pref_service->GetString(local_path).empty() && 134 if (!pref_service->FindPreference(local_path)->HasUserSetting() &&
sky 2012/11/29 23:46:06 I'm not familiar with HasUserSetting. How does thi
bartfab (slow) 2012/11/30 11:55:47 A quick bit of context: There are multiple sources
135 pref_service->IsSyncing()) { 135 pref_service->IsSyncing()) {
136 // First time the user is using this machine, propagate from remote to 136 // First time the user is using this machine, propagate from remote to
137 // local. 137 // local.
138 pref_service->SetString(local_path, pref_service->GetString(synced_path)); 138 pref_service->SetString(local_path, pref_service->GetString(synced_path));
139 } 139 }
140 } 140 }
141 141
142 } // namespace 142 } // namespace
143 143
144 // ChromeLauncherController ---------------------------------------------------- 144 // ChromeLauncherController ----------------------------------------------------
(...skipping 24 matching lines...) Expand all
169 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); 169 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this));
170 170
171 notification_registrar_.Add(this, 171 notification_registrar_.Add(this,
172 chrome::NOTIFICATION_EXTENSION_LOADED, 172 chrome::NOTIFICATION_EXTENSION_LOADED,
173 content::Source<Profile>(profile_)); 173 content::Source<Profile>(profile_));
174 notification_registrar_.Add(this, 174 notification_registrar_.Add(this,
175 chrome::NOTIFICATION_EXTENSION_UNLOADED, 175 chrome::NOTIFICATION_EXTENSION_UNLOADED,
176 content::Source<Profile>(profile_)); 176 content::Source<Profile>(profile_));
177 pref_change_registrar_.Init(profile_->GetPrefs()); 177 pref_change_registrar_.Init(profile_->GetPrefs());
178 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); 178 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this);
179 pref_change_registrar_.Add(prefs::kShelfAlignmentLocal, this);
180 pref_change_registrar_.Add(prefs::kShelfAutoHideBehaviorLocal, this);
179 } 181 }
180 182
181 ChromeLauncherController::~ChromeLauncherController() { 183 ChromeLauncherController::~ChromeLauncherController() {
182 // Reset the shell window controller here since it has a weak pointer to this. 184 // Reset the shell window controller here since it has a weak pointer to this.
183 shell_window_controller_.reset(); 185 shell_window_controller_.reset();
184 186
185 model_->RemoveObserver(this); 187 model_->RemoveObserver(this);
186 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 188 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
187 i != id_to_item_controller_map_.end(); ++i) { 189 i != id_to_item_controller_map_.end(); ++i) {
188 i->second->OnRemoved(); 190 i->second->OnRemoved();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 updater.Get()->Clear(); 226 updater.Get()->Clear();
225 } 227 }
226 228
227 UpdateAppLaunchersFromPref(); 229 UpdateAppLaunchersFromPref();
228 230
229 // TODO(sky): update unit test so that this test isn't necessary. 231 // TODO(sky): update unit test so that this test isn't necessary.
230 if (ash::Shell::HasInstance()) { 232 if (ash::Shell::HasInstance()) {
231 SetShelfAutoHideBehaviorFromPrefs(); 233 SetShelfAutoHideBehaviorFromPrefs();
232 SetShelfAlignmentFromPrefs(); 234 SetShelfAlignmentFromPrefs();
233 PrefService* prefs = profile_->GetPrefs(); 235 PrefService* prefs = profile_->GetPrefs();
234 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || 236 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() ||
sky 2012/11/29 23:46:06 Does this need to be updated? Seems like at a mini
bartfab (slow) 2012/11/30 11:55:47 Actually, prefs->AddObserver(this) is very mislead
235 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { 237 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) {
236 prefs->AddObserver(this); 238 prefs->AddObserver(this);
237 } 239 }
238 ash::Shell::GetInstance()->AddShellObserver(this); 240 ash::Shell::GetInstance()->AddShellObserver(this);
239 } 241 }
240 } 242 }
241 243
242 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem( 244 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem(
243 LauncherItemController* controller, 245 LauncherItemController* controller,
244 IncognitoState is_incognito, 246 IncognitoState is_incognito,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 void ChromeLauncherController::CreateNewIncognitoWindow() { 552 void ChromeLauncherController::CreateNewIncognitoWindow() {
551 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); 553 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile());
552 } 554 }
553 555
554 bool ChromeLauncherController::CanPin() const { 556 bool ChromeLauncherController::CanPin() const {
555 const PrefService::Preference* pref = 557 const PrefService::Preference* pref =
556 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); 558 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
557 return pref && pref->IsUserModifiable(); 559 return pref && pref->IsUserModifiable();
558 } 560 }
559 561
560 void ChromeLauncherController::SetAutoHideBehavior( 562 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior(
561 ash::ShelfAutoHideBehavior behavior, 563 aura::RootWindow* root_window) const {
564 // TODO(oshima): Support multiple launchers.
565
566 // See comment in |kShelfAlignment| as to why we consider two prefs.
567 const std::string behavior_value(
568 GetLocalOrRemotePref(profile_->GetPrefs(),
569 prefs::kShelfAutoHideBehaviorLocal,
570 prefs::kShelfAutoHideBehavior));
571
572 // Note: To maintain sync compatibility with old images of chrome/chromeos
573 // the set of values that may be encountered includes the now-extinct
574 // "Default" as well as "Never" and "Always", "Default" should now
575 // be treated as "Never" (http://crbug.com/146773).
576 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
577 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
578 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
579 }
580
581 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior(
582 aura::RootWindow* root_window) const {
583 // TODO(oshima): Support multiple launchers.
584 return profile_->GetPrefs()->
585 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
586 }
587
588 void ChromeLauncherController::ToggleShelfAutoHideBehavior(
562 aura::RootWindow* root_window) { 589 aura::RootWindow* root_window) {
563 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( 590 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
564 behavior, 591 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
565 root_window); 592 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
566 // TODO(oshima): Support multiple launcher. 593 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
567 if (root_window != ash::Shell::GetPrimaryRootWindow()) 594 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
568 return;
569
570 const char* value = NULL;
571 switch (behavior) {
572 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
573 value = ash::kShelfAutoHideBehaviorAlways;
574 break;
575 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
576 value = ash::kShelfAutoHideBehaviorNever;
577 break;
578 }
579 // See comment in |kShelfAlignment| about why we have two prefs here.
580 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
581 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
582 } 595 }
583 596
584 void ChromeLauncherController::RemoveTabFromRunningApp( 597 void ChromeLauncherController::RemoveTabFromRunningApp(
585 TabContents* tab, 598 TabContents* tab,
586 const std::string& app_id) { 599 const std::string& app_id) {
587 tab_contents_to_app_id_.erase(tab); 600 tab_contents_to_app_id_.erase(tab);
588 AppIDToTabContentsListMap::iterator i_app_id = 601 AppIDToTabContentsListMap::iterator i_app_id =
589 app_id_to_tab_contents_list_.find(app_id); 602 app_id_to_tab_contents_list_.find(app_id);
590 if (i_app_id != app_id_to_tab_contents_list_.end()) { 603 if (i_app_id != app_id_to_tab_contents_list_.end()) {
591 TabContentsList* tab_list = &i_app_id->second; 604 TabContentsList* tab_list = &i_app_id->second;
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 LauncherItemClosed(item.id); 985 LauncherItemClosed(item.id);
973 else 986 else
974 ++index; 987 ++index;
975 } 988 }
976 989
977 // Append unprocessed items from the pref to the end of the model. 990 // Append unprocessed items from the pref to the end of the model.
978 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) 991 for (; pref_app_id != pinned_apps.end(); ++pref_app_id)
979 DoPinAppWithID(*pref_app_id); 992 DoPinAppWithID(*pref_app_id);
980 } 993 }
981 994
995 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs(
996 ash::ShelfAutoHideBehavior behavior,
997 aura::RootWindow* root_window) {
998 // TODO(oshima): Support multiple launchers.
999 if (root_window != ash::Shell::GetPrimaryRootWindow())
1000 return;
1001
1002 const char* value = NULL;
1003 switch (behavior) {
1004 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
1005 value = ash::kShelfAutoHideBehaviorAlways;
1006 break;
1007 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
1008 value = ash::kShelfAutoHideBehaviorNever;
1009 break;
1010 }
1011 // See comment in |kShelfAlignment| about why we have two prefs here.
1012 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
1013 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
1014 }
1015
982 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { 1016 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() {
983 // See comment in |kShelfAlignment| as to why we consider two prefs.
984 const std::string behavior_value(
985 GetLocalOrRemotePref(profile_->GetPrefs(),
986 prefs::kShelfAutoHideBehaviorLocal,
987 prefs::kShelfAutoHideBehavior));
988
989 // Note: To maintain sync compatibility with old images of chrome/chromeos
990 // the set of values that may be encountered includes the now-extinct
991 // "Default" as well as "Never" and "Always", "Default" should now
992 // be treated as "Never".
993 // (http://code.google.com/p/chromium/issues/detail?id=146773)
994 ash::ShelfAutoHideBehavior behavior =
995 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
996 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
997 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
998 // TODO(oshima): Support multiple displays. 1017 // TODO(oshima): Support multiple displays.
1018 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
999 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( 1019 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
1000 behavior, ash::Shell::GetPrimaryRootWindow()); 1020 GetShelfAutoHideBehavior(root_window), root_window);
1001 } 1021 }
1002 1022
1003 void ChromeLauncherController::SetShelfAlignmentFromPrefs() { 1023 void ChromeLauncherController::SetShelfAlignmentFromPrefs() {
1004 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1024 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1005 switches::kShowLauncherAlignmentMenu)) 1025 switches::kShowLauncherAlignmentMenu))
1006 return; 1026 return;
1007 1027
1008 // See comment in |kShelfAlignment| as to why we consider two prefs. 1028 // See comment in |kShelfAlignment| as to why we consider two prefs.
1009 const std::string alignment_value( 1029 const std::string alignment_value(
1010 GetLocalOrRemotePref(profile_->GetPrefs(), 1030 GetLocalOrRemotePref(profile_->GetPrefs(),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 new AppShortcutLauncherItemController(app_id, this); 1093 new AppShortcutLauncherItemController(app_id, this);
1074 ash::LauncherID launcher_id = InsertAppLauncherItem( 1094 ash::LauncherID launcher_id = InsertAppLauncherItem(
1075 controller, app_id, ash::STATUS_CLOSED, index); 1095 controller, app_id, ash::STATUS_CLOSED, index);
1076 return launcher_id; 1096 return launcher_id;
1077 } 1097 }
1078 1098
1079 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { 1099 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const {
1080 return id_to_item_controller_map_.find(id) != 1100 return id_to_item_controller_map_.find(id) !=
1081 id_to_item_controller_map_.end(); 1101 id_to_item_controller_map_.end();
1082 } 1102 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.h ('k') | chrome/browser/ui/ash/launcher/launcher_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698