| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| OLD | NEW |