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

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

Issue 11233049: Splits shelf alignment and auto-hide behavior into two values, one (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks Created 8 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 | 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 <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 // Stores the optional refocus url pattern for this item. 118 // Stores the optional refocus url pattern for this item.
119 const GURL& refocus_url() const { return refocus_url_; } 119 const GURL& refocus_url() const { return refocus_url_; }
120 void set_refocus_url(const GURL& refocus_url) { refocus_url_ = refocus_url; } 120 void set_refocus_url(const GURL& refocus_url) { refocus_url_ = refocus_url; }
121 121
122 private: 122 private:
123 GURL refocus_url_; 123 GURL refocus_url_;
124 DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController); 124 DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController);
125 }; 125 };
126 126
127 // If the value of the pref at |local_path is not empty, it is returned
128 // otherwise the value of the pref at |synced_path| is returned.
129 std::string GetLocalOrRemotePref(PrefService* pref_service,
130 const char* local_path,
131 const char* synced_path) {
132 const std::string value(pref_service->GetString(local_path));
133 return value.empty() ? pref_service->GetString(synced_path) : value;
134 }
135
136 // If prefs have synced and the pref value at |local_path| is empty the value
137 // from |synced_path| is copied to |local_path|.
Bernhard Bauer 2012/10/23 11:21:25 Why do we need this propagation? If we always go t
sky 2012/10/23 14:54:33 Here's a better example of what the UX folks want.
Bernhard Bauer 2012/10/23 15:31:50 I see. In that case, ...
138 void MaybePropagatePrefToLocal(PrefService* pref_service,
139 const char* local_path,
140 const char* synced_path) {
141 if (pref_service->GetString(local_path).empty() &&
142 pref_service->HasSynced()) {
143 // First time the user is using this machine, propagate from remote to
144 // local.
145 pref_service->SetString(local_path, pref_service->GetString(synced_path));
146 }
147 }
148
127 } // namespace 149 } // namespace
128 150
129 // ChromeLauncherController ---------------------------------------------------- 151 // ChromeLauncherController ----------------------------------------------------
130 152
131 // statics 153 // statics
132 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; 154 ChromeLauncherController* ChromeLauncherController::instance_ = NULL;
133 155
134 ChromeLauncherController::ChromeLauncherController(Profile* profile, 156 ChromeLauncherController::ChromeLauncherController(Profile* profile,
135 ash::LauncherModel* model) 157 ash::LauncherModel* model)
136 : model_(model), 158 : model_(model),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 model_->RemoveItemAt(model_->ItemIndexByID(i->first)); 205 model_->RemoveItemAt(model_->ItemIndexByID(i->first));
184 } 206 }
185 if (instance_ == this) 207 if (instance_ == this)
186 instance_ = NULL; 208 instance_ = NULL;
187 209
188 if (ash::Shell::HasInstance()) 210 if (ash::Shell::HasInstance())
189 ash::Shell::GetInstance()->RemoveShellObserver(this); 211 ash::Shell::GetInstance()->RemoveShellObserver(this);
190 212
191 if (observed_sync_service_) 213 if (observed_sync_service_)
192 observed_sync_service_->RemoveObserver(this); 214 observed_sync_service_->RemoveObserver(this);
215
216 profile_->GetPrefs()->RemoveObserver(this);
193 } 217 }
194 218
195 void ChromeLauncherController::Init() { 219 void ChromeLauncherController::Init() {
196 // TODO(xiyuan): Remove migration code and kUseDefaultPinnedApp after M20. 220 // TODO(xiyuan): Remove migration code and kUseDefaultPinnedApp after M20.
197 // Migration cases: 221 // Migration cases:
198 // - Users that unpin all apps: 222 // - Users that unpin all apps:
199 // - have default pinned apps 223 // - have default pinned apps
200 // - kUseDefaultPinnedApps set to false 224 // - kUseDefaultPinnedApps set to false
201 // Migrate them by setting an empty list for kPinnedLauncherApps. 225 // Migrate them by setting an empty list for kPinnedLauncherApps.
202 // 226 //
(...skipping 12 matching lines...) Expand all
215 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); 239 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
216 updater.Get()->Clear(); 240 updater.Get()->Clear();
217 } 241 }
218 242
219 UpdateAppLaunchersFromPref(); 243 UpdateAppLaunchersFromPref();
220 244
221 // TODO(sky): update unit test so that this test isn't necessary. 245 // TODO(sky): update unit test so that this test isn't necessary.
222 if (ash::Shell::HasInstance()) { 246 if (ash::Shell::HasInstance()) {
223 SetShelfAutoHideBehaviorFromPrefs(); 247 SetShelfAutoHideBehaviorFromPrefs();
224 SetShelfAlignmentFromPrefs(); 248 SetShelfAlignmentFromPrefs();
249 PrefService* prefs = profile_->GetPrefs();
250 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() ||
251 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) {
252 prefs->AddObserver(this);
253 }
225 ash::Shell::GetInstance()->AddShellObserver(this); 254 ash::Shell::GetInstance()->AddShellObserver(this);
226 } 255 }
227 } 256 }
228 257
229 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem( 258 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem(
230 LauncherItemController* controller, 259 LauncherItemController* controller,
231 IncognitoState is_incognito, 260 IncognitoState is_incognito,
232 ash::LauncherItemStatus status) { 261 ash::LauncherItemStatus status) {
233 ash::LauncherID id = model_->next_id(); 262 ash::LauncherID id = model_->next_id();
234 DCHECK(!HasItemController(id)); 263 DCHECK(!HasItemController(id));
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior); 575 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior);
547 const char* value = NULL; 576 const char* value = NULL;
548 switch (behavior) { 577 switch (behavior) {
549 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: 578 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
550 value = ash::kShelfAutoHideBehaviorAlways; 579 value = ash::kShelfAutoHideBehaviorAlways;
551 break; 580 break;
552 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: 581 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
553 value = ash::kShelfAutoHideBehaviorNever; 582 value = ash::kShelfAutoHideBehaviorNever;
554 break; 583 break;
555 } 584 }
585 // See comment in |kShelfAlignment| about why we have two prefs here.
586 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
556 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); 587 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
557 } 588 }
558 589
559 void ChromeLauncherController::RemoveTabFromRunningApp( 590 void ChromeLauncherController::RemoveTabFromRunningApp(
560 TabContents* tab, 591 TabContents* tab,
561 const std::string& app_id) { 592 const std::string& app_id) {
562 tab_contents_to_app_id_.erase(tab); 593 tab_contents_to_app_id_.erase(tab);
563 AppIDToTabContentsListMap::iterator i_app_id = 594 AppIDToTabContentsListMap::iterator i_app_id =
564 app_id_to_tab_contents_list_.find(app_id); 595 app_id_to_tab_contents_list_.find(app_id);
565 if (i_app_id != app_id_to_tab_contents_list_.end()) { 596 if (i_app_id != app_id_to_tab_contents_list_.end()) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 details); 777 details);
747 const Extension* extension = unload_info->extension; 778 const Extension* extension = unload_info->extension;
748 if (IsAppPinned(extension->id())) 779 if (IsAppPinned(extension->id()))
749 DoUnpinAppsWithID(extension->id()); 780 DoUnpinAppsWithID(extension->id());
750 app_icon_loader_->ClearImage(extension->id()); 781 app_icon_loader_->ClearImage(extension->id());
751 break; 782 break;
752 } 783 }
753 case chrome::NOTIFICATION_PREF_CHANGED: { 784 case chrome::NOTIFICATION_PREF_CHANGED: {
754 const std::string& pref_name( 785 const std::string& pref_name(
755 *content::Details<std::string>(details).ptr()); 786 *content::Details<std::string>(details).ptr());
756 if (pref_name == prefs::kPinnedLauncherApps) 787 if (pref_name == prefs::kPinnedLauncherApps) {
757 UpdateAppLaunchersFromPref(); 788 UpdateAppLaunchersFromPref();
758 else if (pref_name == prefs::kShelfAlignment) 789 } else if (pref_name == prefs::kShelfAlignment) {
790 MaybePropagatePrefToLocal(profile_->GetPrefs(),
Bernhard Bauer 2012/10/23 15:31:50 ...do we need this now? I think we're only interes
sky 2012/10/23 15:53:27 Good point. Removed.
791 prefs::kShelfAlignmentLocal,
792 prefs::kShelfAlignment);
793 } else if (pref_name == prefs::kShelfAlignmentLocal) {
759 SetShelfAlignmentFromPrefs(); 794 SetShelfAlignmentFromPrefs();
760 else if (pref_name == prefs::kShelfAutoHideBehavior) 795 } else if (pref_name == prefs::kShelfAutoHideBehavior) {
796 MaybePropagatePrefToLocal(profile_->GetPrefs(),
797 prefs::kShelfAutoHideBehaviorLocal,
798 prefs::kShelfAutoHideBehavior);
799 } else if (pref_name == prefs::kShelfAutoHideBehaviorLocal) {
761 SetShelfAutoHideBehaviorFromPrefs(); 800 SetShelfAutoHideBehaviorFromPrefs();
762 else 801 } else {
763 NOTREACHED() << "Unexpected pref change for " << pref_name; 802 NOTREACHED() << "Unexpected pref change for " << pref_name;
803 }
764 break; 804 break;
765 } 805 }
766 default: 806 default:
767 NOTREACHED() << "Unexpected notification type=" << type; 807 NOTREACHED() << "Unexpected notification type=" << type;
768 } 808 }
769 } 809 }
770 810
771 void ChromeLauncherController::OnShelfAlignmentChanged() { 811 void ChromeLauncherController::OnShelfAlignmentChanged() {
772 const char* pref_value = NULL; 812 const char* pref_value = NULL;
773 switch (ash::Shell::GetInstance()->GetShelfAlignment()) { 813 switch (ash::Shell::GetInstance()->GetShelfAlignment()) {
774 case ash::SHELF_ALIGNMENT_BOTTOM: 814 case ash::SHELF_ALIGNMENT_BOTTOM:
775 pref_value = ash::kShelfAlignmentBottom; 815 pref_value = ash::kShelfAlignmentBottom;
776 break; 816 break;
777 case ash::SHELF_ALIGNMENT_LEFT: 817 case ash::SHELF_ALIGNMENT_LEFT:
778 pref_value = ash::kShelfAlignmentLeft; 818 pref_value = ash::kShelfAlignmentLeft;
779 break; 819 break;
780 case ash::SHELF_ALIGNMENT_RIGHT: 820 case ash::SHELF_ALIGNMENT_RIGHT:
781 pref_value = ash::kShelfAlignmentRight; 821 pref_value = ash::kShelfAlignmentRight;
782 break; 822 break;
783 } 823 }
824 // See comment in |kShelfAlignment| about why we have two prefs here.
825 profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value);
784 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); 826 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value);
785 } 827 }
786 828
787 void ChromeLauncherController::OnStateChanged() { 829 void ChromeLauncherController::OnStateChanged() {
788 DCHECK(observed_sync_service_); 830 DCHECK(observed_sync_service_);
789 CheckAppSync(); 831 CheckAppSync();
790 } 832 }
791 833
834 void ChromeLauncherController::OnHasSyncedChanged() {
835 MaybePropagatePrefToLocal(profile_->GetPrefs(),
836 prefs::kShelfAlignmentLocal,
837 prefs::kShelfAlignment);
838 MaybePropagatePrefToLocal(profile_->GetPrefs(),
839 prefs::kShelfAutoHideBehaviorLocal,
840 prefs::kShelfAutoHideBehavior);
841 }
842
792 void ChromeLauncherController::PersistPinnedState() { 843 void ChromeLauncherController::PersistPinnedState() {
793 // It is a coding error to call PersistPinnedState() if the pinned apps are 844 // It is a coding error to call PersistPinnedState() if the pinned apps are
794 // not user-editable. The code should check earlier and not perform any 845 // not user-editable. The code should check earlier and not perform any
795 // modification actions that trigger persisting the state. 846 // modification actions that trigger persisting the state.
796 if (!CanPin()) { 847 if (!CanPin()) {
797 NOTREACHED() << "Can't pin but pinned state being updated"; 848 NOTREACHED() << "Can't pin but pinned state being updated";
798 return; 849 return;
799 } 850 }
800 851
801 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs 852 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 else 986 else
936 ++index; 987 ++index;
937 } 988 }
938 989
939 // 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.
940 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) 991 for (; pref_app_id != pinned_apps.end(); ++pref_app_id)
941 DoPinAppWithID(*pref_app_id); 992 DoPinAppWithID(*pref_app_id);
942 } 993 }
943 994
944 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { 995 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() {
996 // See comment in |kShelfAlignment| as to why we consider two prefs.
997 const std::string behavior_value(
998 GetLocalOrRemotePref(profile_->GetPrefs(),
999 prefs::kShelfAutoHideBehaviorLocal,
1000 prefs::kShelfAutoHideBehavior));
1001
945 // Note: To maintain sync compatibility with old images of chrome/chromeos 1002 // Note: To maintain sync compatibility with old images of chrome/chromeos
946 // the set of values that may be encountered includes the now-extinct 1003 // the set of values that may be encountered includes the now-extinct
947 // "Default" as well as "Never" and "Always", "Default" should now 1004 // "Default" as well as "Never" and "Always", "Default" should now
948 // be treated as "Never". 1005 // be treated as "Never".
949 // (http://code.google.com/p/chromium/issues/detail?id=146773) 1006 // (http://code.google.com/p/chromium/issues/detail?id=146773)
950 const std::string behavior_value(
951 profile_->GetPrefs()->GetString(prefs::kShelfAutoHideBehavior));
952 ash::ShelfAutoHideBehavior behavior = 1007 ash::ShelfAutoHideBehavior behavior =
953 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; 1008 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
954 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) 1009 if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
955 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 1010 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
956 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior); 1011 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior);
957 } 1012 }
958 1013
959 void ChromeLauncherController::SetShelfAlignmentFromPrefs() { 1014 void ChromeLauncherController::SetShelfAlignmentFromPrefs() {
960 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1015 if (!CommandLine::ForCurrentProcess()->HasSwitch(
961 switches::kShowLauncherAlignmentMenu)) 1016 switches::kShowLauncherAlignmentMenu))
962 return; 1017 return;
963 1018
1019 // See comment in |kShelfAlignment| as to why we consider two prefs.
964 const std::string alignment_value( 1020 const std::string alignment_value(
965 profile_->GetPrefs()->GetString(prefs::kShelfAlignment)); 1021 GetLocalOrRemotePref(profile_->GetPrefs(),
1022 prefs::kShelfAlignmentLocal,
1023 prefs::kShelfAlignment));
966 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; 1024 ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM;
967 if (alignment_value == ash::kShelfAlignmentLeft) 1025 if (alignment_value == ash::kShelfAlignmentLeft)
968 alignment = ash::SHELF_ALIGNMENT_LEFT; 1026 alignment = ash::SHELF_ALIGNMENT_LEFT;
969 else if (alignment_value == ash::kShelfAlignmentRight) 1027 else if (alignment_value == ash::kShelfAlignmentRight)
970 alignment = ash::SHELF_ALIGNMENT_RIGHT; 1028 alignment = ash::SHELF_ALIGNMENT_RIGHT;
1029
971 ash::Shell::GetInstance()->SetShelfAlignment(alignment); 1030 ash::Shell::GetInstance()->SetShelfAlignment(alignment);
972 } 1031 }
973 1032
974 TabContents* ChromeLauncherController::GetLastActiveTabContents( 1033 TabContents* ChromeLauncherController::GetLastActiveTabContents(
975 const std::string& app_id) { 1034 const std::string& app_id) {
976 AppIDToTabContentsListMap::const_iterator i = 1035 AppIDToTabContentsListMap::const_iterator i =
977 app_id_to_tab_contents_list_.find(app_id); 1036 app_id_to_tab_contents_list_.find(app_id);
978 if (i == app_id_to_tab_contents_list_.end()) 1037 if (i == app_id_to_tab_contents_list_.end())
979 return NULL; 1038 return NULL;
980 DCHECK_GT(i->second.size(), 0u); 1039 DCHECK_GT(i->second.size(), 0u);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1120 }
1062 1121
1063 void ChromeLauncherController::StopLoadingAnimation() { 1122 void ChromeLauncherController::StopLoadingAnimation() {
1064 DCHECK(observed_sync_service_); 1123 DCHECK(observed_sync_service_);
1065 1124
1066 model_->SetStatus(ash::LauncherModel::STATUS_NORMAL); 1125 model_->SetStatus(ash::LauncherModel::STATUS_NORMAL);
1067 loading_timer_.Stop(); 1126 loading_timer_.Stop();
1068 observed_sync_service_->RemoveObserver(this); 1127 observed_sync_service_->RemoveObserver(this);
1069 observed_sync_service_ = NULL; 1128 observed_sync_service_ = NULL;
1070 } 1129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698