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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.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- Rebased. 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_per_browser. h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser. 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 // If the value of the pref at |local_path is not empty, it is returned 122 // If the value of the pref at |local_path is not empty, it is returned
123 // otherwise the value of the pref at |synced_path| is returned. 123 // otherwise the value of the pref at |synced_path| is returned.
124 std::string GetLocalOrRemotePref(PrefService* pref_service, 124 std::string GetLocalOrRemotePref(PrefService* pref_service,
125 const char* local_path, 125 const char* local_path,
126 const char* synced_path) { 126 const char* synced_path) {
127 const std::string value(pref_service->GetString(local_path)); 127 const std::string value(pref_service->GetString(local_path));
128 return value.empty() ? pref_service->GetString(synced_path) : value; 128 return value.empty() ? pref_service->GetString(synced_path) : value;
129 } 129 }
130 130
131 // If prefs have synced and the pref value at |local_path| is empty the value 131 // If prefs have synced and no user-set value exists at |local_path|, the value
132 // from |synced_path| is copied to |local_path|. 132 // from |synced_path| is copied to |local_path|.
133 void MaybePropagatePrefToLocal(PrefService* pref_service, 133 void MaybePropagatePrefToLocal(PrefService* pref_service,
134 const char* local_path, 134 const char* local_path,
135 const char* synced_path) { 135 const char* synced_path) {
136 if (pref_service->GetString(local_path).empty() && 136 if (!pref_service->FindPreference(local_path)->HasUserSetting() &&
137 pref_service->IsSyncing()) { 137 pref_service->IsSyncing()) {
138 // First time the user is using this machine, propagate from remote to 138 // First time the user is using this machine, propagate from remote to
139 // local. 139 // local.
140 pref_service->SetString(local_path, pref_service->GetString(synced_path)); 140 pref_service->SetString(local_path, pref_service->GetString(synced_path));
141 } 141 }
142 } 142 }
143 143
144 } // namespace 144 } // namespace
145 145
146 // ChromeLauncherControllerPerBrowser ----------------------------------------- 146 // ChromeLauncherControllerPerBrowser -----------------------------------------
(...skipping 21 matching lines...) Expand all
168 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); 168 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this));
169 169
170 notification_registrar_.Add(this, 170 notification_registrar_.Add(this,
171 chrome::NOTIFICATION_EXTENSION_LOADED, 171 chrome::NOTIFICATION_EXTENSION_LOADED,
172 content::Source<Profile>(profile_)); 172 content::Source<Profile>(profile_));
173 notification_registrar_.Add(this, 173 notification_registrar_.Add(this,
174 chrome::NOTIFICATION_EXTENSION_UNLOADED, 174 chrome::NOTIFICATION_EXTENSION_UNLOADED,
175 content::Source<Profile>(profile_)); 175 content::Source<Profile>(profile_));
176 pref_change_registrar_.Init(profile_->GetPrefs()); 176 pref_change_registrar_.Init(profile_->GetPrefs());
177 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); 177 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this);
178 pref_change_registrar_.Add(prefs::kShelfAlignmentLocal, this);
179 pref_change_registrar_.Add(prefs::kShelfAutoHideBehaviorLocal, this);
178 } 180 }
179 181
180 ChromeLauncherControllerPerBrowser::~ChromeLauncherControllerPerBrowser() { 182 ChromeLauncherControllerPerBrowser::~ChromeLauncherControllerPerBrowser() {
181 // Reset the shell window controller here since it has a weak pointer to 183 // Reset the shell window controller here since it has a weak pointer to
182 // this. 184 // 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) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 updater.Get()->Clear(); 224 updater.Get()->Clear();
223 } 225 }
224 226
225 UpdateAppLaunchersFromPref(); 227 UpdateAppLaunchersFromPref();
226 228
227 // TODO(sky): update unit test so that this test isn't necessary. 229 // TODO(sky): update unit test so that this test isn't necessary.
228 if (ash::Shell::HasInstance()) { 230 if (ash::Shell::HasInstance()) {
229 SetShelfAutoHideBehaviorFromPrefs(); 231 SetShelfAutoHideBehaviorFromPrefs();
230 SetShelfAlignmentFromPrefs(); 232 SetShelfAlignmentFromPrefs();
231 PrefService* prefs = profile_->GetPrefs(); 233 PrefService* prefs = profile_->GetPrefs();
232 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || 234 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() ||
233 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { 235 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)->
236 HasUserSetting()) {
234 prefs->AddObserver(this); 237 prefs->AddObserver(this);
235 } 238 }
236 ash::Shell::GetInstance()->AddShellObserver(this); 239 ash::Shell::GetInstance()->AddShellObserver(this);
237 } 240 }
238 } 241 }
239 242
240 ash::LauncherID ChromeLauncherControllerPerBrowser::CreateTabbedLauncherItem( 243 ash::LauncherID ChromeLauncherControllerPerBrowser::CreateTabbedLauncherItem(
241 LauncherItemController* controller, 244 LauncherItemController* controller,
242 IncognitoState is_incognito, 245 IncognitoState is_incognito,
243 ash::LauncherItemStatus status) { 246 ash::LauncherItemStatus status) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 void ChromeLauncherControllerPerBrowser::CreateNewIncognitoWindow() { 558 void ChromeLauncherControllerPerBrowser::CreateNewIncognitoWindow() {
556 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); 559 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile());
557 } 560 }
558 561
559 bool ChromeLauncherControllerPerBrowser::CanPin() const { 562 bool ChromeLauncherControllerPerBrowser::CanPin() const {
560 const PrefService::Preference* pref = 563 const PrefService::Preference* pref =
561 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); 564 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
562 return pref && pref->IsUserModifiable(); 565 return pref && pref->IsUserModifiable();
563 } 566 }
564 567
565 void ChromeLauncherControllerPerBrowser::SetAutoHideBehavior( 568 ash::ShelfAutoHideBehavior
566 ash::ShelfAutoHideBehavior behavior, 569 ChromeLauncherControllerPerBrowser::GetShelfAutoHideBehavior(
570 aura::RootWindow* root_window) const {
571 // TODO(oshima): Support multiple launchers.
572
573 // See comment in |kShelfAlignment| as to why we consider two prefs.
574 const std::string behavior_value(
575 GetLocalOrRemotePref(profile_->GetPrefs(),
576 prefs::kShelfAutoHideBehaviorLocal,
577 prefs::kShelfAutoHideBehavior));
578
579 // Note: To maintain sync compatibility with old images of chrome/chromeos
580 // the set of values that may be encountered includes the now-extinct
581 // "Default" as well as "Never" and "Always", "Default" should now
582 // be treated as "Never" (http://crbug.com/146773).
583 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
584 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
585 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
586 }
587
588 bool ChromeLauncherControllerPerBrowser::CanUserModifyShelfAutoHideBehavior(
589 aura::RootWindow* root_window) const {
590 // TODO(oshima): Support multiple launchers.
591 return profile_->GetPrefs()->
592 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
593 }
594
595 void ChromeLauncherControllerPerBrowser::ToggleShelfAutoHideBehavior(
567 aura::RootWindow* root_window) { 596 aura::RootWindow* root_window) {
568 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( 597 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
569 behavior, 598 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
570 root_window); 599 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
571 // TODO(oshima): Support multiple launcher. 600 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
572 if (root_window != ash::Shell::GetPrimaryRootWindow()) 601 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
573 return; 602 return;
574
575 const char* value = NULL;
576 switch (behavior) {
577 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
578 value = ash::kShelfAutoHideBehaviorAlways;
579 break;
580 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
581 value = ash::kShelfAutoHideBehaviorNever;
582 break;
583 }
584 // See comment in |kShelfAlignment| about why we have two prefs here.
585 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
586 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
587 } 603 }
588 604
589 void ChromeLauncherControllerPerBrowser::RemoveTabFromRunningApp( 605 void ChromeLauncherControllerPerBrowser::RemoveTabFromRunningApp(
590 TabContents* tab, 606 TabContents* tab,
591 const std::string& app_id) { 607 const std::string& app_id) {
592 tab_contents_to_app_id_.erase(tab); 608 tab_contents_to_app_id_.erase(tab);
593 AppIDToTabContentsListMap::iterator i_app_id = 609 AppIDToTabContentsListMap::iterator i_app_id =
594 app_id_to_tab_contents_list_.find(app_id); 610 app_id_to_tab_contents_list_.find(app_id);
595 if (i_app_id != app_id_to_tab_contents_list_.end()) { 611 if (i_app_id != app_id_to_tab_contents_list_.end()) {
596 TabContentsList* tab_list = &i_app_id->second; 612 TabContentsList* tab_list = &i_app_id->second;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 LauncherItemClosed(item.id); 1002 LauncherItemClosed(item.id);
987 else 1003 else
988 ++index; 1004 ++index;
989 } 1005 }
990 1006
991 // Append unprocessed items from the pref to the end of the model. 1007 // Append unprocessed items from the pref to the end of the model.
992 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) 1008 for (; pref_app_id != pinned_apps.end(); ++pref_app_id)
993 DoPinAppWithID(*pref_app_id); 1009 DoPinAppWithID(*pref_app_id);
994 } 1010 }
995 1011
1012 void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorPrefs(
1013 ash::ShelfAutoHideBehavior behavior,
1014 aura::RootWindow* root_window) {
1015 // TODO(oshima): Support multiple launchers.
1016 if (root_window != ash::Shell::GetPrimaryRootWindow())
1017 return;
1018
1019 const char* value = NULL;
1020 switch (behavior) {
1021 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
1022 value = ash::kShelfAutoHideBehaviorAlways;
1023 break;
1024 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
1025 value = ash::kShelfAutoHideBehaviorNever;
1026 break;
1027 }
1028 // See comment in |kShelfAlignment| about why we have two prefs here.
1029 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
1030 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
1031 }
1032
996 void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorFromPrefs() { 1033 void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorFromPrefs() {
997 // See comment in |kShelfAlignment| as to why we consider two prefs.
998 const std::string behavior_value(
999 GetLocalOrRemotePref(profile_->GetPrefs(),
1000 prefs::kShelfAutoHideBehaviorLocal,
1001 prefs::kShelfAutoHideBehavior));
1002
1003 // Note: To maintain sync compatibility with old images of chrome/chromeos
1004 // the set of values that may be encountered includes the now-extinct
1005 // "Default" as well as "Never" and "Always", "Default" should now
1006 // be treated as "Never".
1007 // (http://code.google.com/p/chromium/issues/detail?id=146773)
1008 ash::ShelfAutoHideBehavior behavior =
1009 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
1010 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
1011 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
1012 // TODO(oshima): Support multiple displays. 1034 // TODO(oshima): Support multiple displays.
1035 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
1013 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( 1036 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
1014 behavior, ash::Shell::GetPrimaryRootWindow()); 1037 GetShelfAutoHideBehavior(root_window), root_window);
1015 } 1038 }
1016 1039
1017 void ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() { 1040 void ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() {
1018 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1041 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1019 switches::kShowLauncherAlignmentMenu)) 1042 switches::kShowLauncherAlignmentMenu))
1020 return; 1043 return;
1021 1044
1022 // See comment in |kShelfAlignment| as to why we consider two prefs. 1045 // See comment in |kShelfAlignment| as to why we consider two prefs.
1023 const std::string alignment_value( 1046 const std::string alignment_value(
1024 GetLocalOrRemotePref(profile_->GetPrefs(), 1047 GetLocalOrRemotePref(profile_->GetPrefs(),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 AppIconLoader* loader) { 1129 AppIconLoader* loader) {
1107 app_icon_loader_.reset(loader); 1130 app_icon_loader_.reset(loader);
1108 } 1131 }
1109 1132
1110 const std::string& 1133 const std::string&
1111 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest( 1134 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest(
1112 ash::LauncherID id) { 1135 ash::LauncherID id) {
1113 return id_to_item_controller_map_[id]->app_id(); 1136 return id_to_item_controller_map_[id]->app_id();
1114 } 1137 }
1115 1138
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698