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

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

Issue 10055003: Keep emtpy List/Dictionary pref value with non-empty default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #1 Created 8 years, 8 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
« no previous file with comments | « chrome/browser/prefs/testing_pref_store.cc ('k') | chrome/common/json_pref_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/ash/launcher/chrome_launcher_delegate.h" 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h"
6 6
7 #include "ash/launcher/launcher_model.h" 7 #include "ash/launcher/launcher_model.h"
8 #include "ash/launcher/launcher_types.h" 8 #include "ash/launcher/launcher_types.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 model_->RemoveObserver(this); 133 model_->RemoveObserver(this);
134 for (IDToItemMap::iterator i = id_to_item_map_.begin(); 134 for (IDToItemMap::iterator i = id_to_item_map_.begin();
135 i != id_to_item_map_.end(); ++i) { 135 i != id_to_item_map_.end(); ++i) {
136 model_->RemoveItemAt(model_->ItemIndexByID(i->first)); 136 model_->RemoveItemAt(model_->ItemIndexByID(i->first));
137 } 137 }
138 if (instance_ == this) 138 if (instance_ == this)
139 instance_ = NULL; 139 instance_ = NULL;
140 } 140 }
141 141
142 void ChromeLauncherDelegate::Init() { 142 void ChromeLauncherDelegate::Init() {
143 // TODO(xiyuan): Remove migration code and kUseDefaultPinnedApp after M20.
144 // Migration cases:
145 // - Users that unpin all apps:
146 // - have default pinned apps
147 // - kUseDefaultPinnedApps set to false
148 // Migrate them by setting an empty list for kPinnedLauncherApps.
149 //
150 // - Users that have customized pinned apps:
151 // - have non-default non-empty pinned apps list
152 // - kUseDefaultPinnedApps set to false
153 // Nothing needs to be done because customized pref overrides default.
154 //
155 // - Users that have default apps (i.e. new user or never pin/unpin):
156 // - have default pinned apps
157 // - kUseDefaultPinnedApps is still true
158 // Nothing needs to be done because they should get the default.
159 if (profile_->GetPrefs()->FindPreference(
160 prefs::kPinnedLauncherApps)->IsDefaultValue() &&
161 !profile_->GetPrefs()->GetBoolean(prefs::kUseDefaultPinnedApps)) {
162 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
163 updater.Get()->Clear();
164 }
165
143 const base::ListValue* pinned_apps = 166 const base::ListValue* pinned_apps =
144 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); 167 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
145
146 // Use default pinned apps only when current pinned apps list is empty and
147 // kUseDefaultPinnedApps is true.
148 // TODO(xiyuan): Remove this after http://crbug.com/122679 is resolved.
149 scoped_ptr<base::ListValue> default_pinned_apps;
150 if (pinned_apps->empty() &&
151 profile_->GetPrefs()->GetBoolean(prefs::kUseDefaultPinnedApps)) {
152 default_pinned_apps.reset(CreateDefaultPinnedAppsList());
153 pinned_apps = default_pinned_apps.get();
154 }
155
156 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { 168 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) {
157 DictionaryValue* app = NULL; 169 DictionaryValue* app = NULL;
158 if (pinned_apps->GetDictionary(i, &app)) { 170 if (pinned_apps->GetDictionary(i, &app)) {
159 std::string app_id, type_string; 171 std::string app_id, type_string;
160 if (app->GetString(kAppIDPath, &app_id) && 172 if (app->GetString(kAppIDPath, &app_id) &&
161 app->GetString(kAppTypePath, &type_string)) { 173 app->GetString(kAppTypePath, &type_string)) {
162 AppType app_type; 174 AppType app_type;
163 if (type_string == kAppTypeWindow) 175 if (type_string == kAppTypeWindow)
164 app_type = APP_TYPE_WINDOW; 176 app_type = APP_TYPE_WINDOW;
165 else if (type_string == kAppTypePanel) 177 else if (type_string == kAppTypePanel)
(...skipping 28 matching lines...) Expand all
194 } 206 }
195 207
196 // static 208 // static
197 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { 209 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) {
198 // TODO: If we want to support multiple profiles this will likely need to be 210 // TODO: If we want to support multiple profiles this will likely need to be
199 // pushed to local state and we'll need to track profile per item. 211 // pushed to local state and we'll need to track profile per item.
200 user_prefs->RegisterBooleanPref(prefs::kUseDefaultPinnedApps, 212 user_prefs->RegisterBooleanPref(prefs::kUseDefaultPinnedApps,
201 true, 213 true,
202 PrefService::SYNCABLE_PREF); 214 PrefService::SYNCABLE_PREF);
203 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps, 215 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps,
216 CreateDefaultPinnedAppsList(),
204 PrefService::SYNCABLE_PREF); 217 PrefService::SYNCABLE_PREF);
205 user_prefs->RegisterStringPref(prefs::kShelfAutoHideBehavior, 218 user_prefs->RegisterStringPref(prefs::kShelfAutoHideBehavior,
206 kShelfAutoHideBehaviorDefault, 219 kShelfAutoHideBehaviorDefault,
207 PrefService::SYNCABLE_PREF); 220 PrefService::SYNCABLE_PREF);
208 } 221 }
209 222
210 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem( 223 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem(
211 LauncherUpdater* updater, 224 LauncherUpdater* updater,
212 IncognitoState is_incognito, 225 IncognitoState is_incognito,
213 ash::LauncherItemStatus status) { 226 ash::LauncherItemStatus status) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 NOTREACHED() << "Unexpected notification type=" << type; 579 NOTREACHED() << "Unexpected notification type=" << type;
567 } 580 }
568 } 581 }
569 582
570 void ChromeLauncherDelegate::PersistPinnedState() { 583 void ChromeLauncherDelegate::PersistPinnedState() {
571 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs 584 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs
572 // from now on. 585 // from now on.
573 profile_->GetPrefs()->SetBoolean(prefs::kUseDefaultPinnedApps, false); 586 profile_->GetPrefs()->SetBoolean(prefs::kUseDefaultPinnedApps, false);
574 587
575 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); 588 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
576 updater.Get()->Clear(); 589 updater->Clear();
577 for (size_t i = 0; i < model_->items().size(); ++i) { 590 for (size_t i = 0; i < model_->items().size(); ++i) {
578 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) { 591 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) {
579 ash::LauncherID id = model_->items()[i].id; 592 ash::LauncherID id = model_->items()[i].id;
580 if (id_to_item_map_.find(id) != id_to_item_map_.end() && 593 if (id_to_item_map_.find(id) != id_to_item_map_.end() &&
581 IsPinned(id)) { 594 IsPinned(id)) {
582 base::DictionaryValue* app_value = CreateAppDict( 595 base::DictionaryValue* app_value = CreateAppDict(
583 id_to_item_map_[id].app_id, 596 id_to_item_map_[id].app_id,
584 id_to_item_map_[id].app_type); 597 id_to_item_map_[id].app_type);
585 if (app_value) 598 if (app_value)
586 updater.Get()->Append(app_value); 599 updater->Append(app_value);
587 } 600 }
588 } 601 }
589 } 602 }
590 } 603 }
591 604
592 void ChromeLauncherDelegate::SetAppIconLoaderForTest(AppIconLoader* loader) { 605 void ChromeLauncherDelegate::SetAppIconLoaderForTest(AppIconLoader* loader) {
593 app_icon_loader_.reset(loader); 606 app_icon_loader_.reset(loader);
594 } 607 }
595 608
596 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { 609 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() {
597 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 610 return ProfileManager::GetDefaultProfileOrOffTheRecord();
598 } 611 }
599 612
600 void ChromeLauncherDelegate::ProcessPendingPinnedApps() { 613 void ChromeLauncherDelegate::ProcessPendingPinnedApps() {
601 while (!pending_pinned_apps_.empty()) { 614 while (!pending_pinned_apps_.empty()) {
602 const Item& item = pending_pinned_apps_.front(); 615 const Item& item = pending_pinned_apps_.front();
603 616
604 if (!app_icon_loader_->IsValidID(item.app_id)) 617 if (!app_icon_loader_->IsValidID(item.app_id))
605 return; 618 return;
606 619
607 PinAppWithID(item.app_id, item.app_type); 620 PinAppWithID(item.app_id, item.app_type);
608 pending_pinned_apps_.pop(); 621 pending_pinned_apps_.pop();
609 } 622 }
610 } 623 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/testing_pref_store.cc ('k') | chrome/common/json_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698