Chromium Code Reviews| 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/ash/chrome_launcher_prefs.h" | 5 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 15 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | |
| 15 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
| 18 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 19 #include "components/prefs/scoped_user_pref_update.h" | 20 #include "components/prefs/scoped_user_pref_update.h" |
| 20 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
| 21 | 22 |
| 22 namespace ash { | 23 namespace ash { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 return nullptr; | 165 return nullptr; |
| 165 } | 166 } |
| 166 NOTREACHED(); | 167 NOTREACHED(); |
| 167 return nullptr; | 168 return nullptr; |
| 168 } | 169 } |
| 169 | 170 |
| 170 } // namespace | 171 } // namespace |
| 171 | 172 |
| 172 const char kPinnedAppsPrefAppIDPath[] = "id"; | 173 const char kPinnedAppsPrefAppIDPath[] = "id"; |
| 173 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy"; | 174 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy"; |
| 175 const char kPinnedAppsPlaceholder[] = "AppShelfIDPlaceholder--------"; | |
| 174 | 176 |
| 175 const char kShelfAutoHideBehaviorAlways[] = "Always"; | 177 const char kShelfAutoHideBehaviorAlways[] = "Always"; |
| 176 const char kShelfAutoHideBehaviorNever[] = "Never"; | 178 const char kShelfAutoHideBehaviorNever[] = "Never"; |
| 177 | 179 |
| 178 const char kShelfAlignmentBottom[] = "Bottom"; | 180 const char kShelfAlignmentBottom[] = "Bottom"; |
| 179 const char kShelfAlignmentLeft[] = "Left"; | 181 const char kShelfAlignmentLeft[] = "Left"; |
| 180 const char kShelfAlignmentRight[] = "Right"; | 182 const char kShelfAlignmentRight[] = "Right"; |
| 181 | 183 |
| 182 void RegisterChromeLauncherUserPrefs( | 184 void RegisterChromeLauncherUserPrefs( |
| 183 user_prefs::PrefRegistrySyncable* registry) { | 185 user_prefs::PrefRegistrySyncable* registry) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return; | 263 return; |
| 262 | 264 |
| 263 SetPerDisplayPref(prefs, display_id, prefs::kShelfAlignment, value); | 265 SetPerDisplayPref(prefs, display_id, prefs::kShelfAlignment, value); |
| 264 if (display_id == display::Screen::GetScreen()->GetPrimaryDisplay().id()) { | 266 if (display_id == display::Screen::GetScreen()->GetPrimaryDisplay().id()) { |
| 265 // See comment in |kShelfAlignment| as to why we consider two prefs. | 267 // See comment in |kShelfAlignment| as to why we consider two prefs. |
| 266 prefs->SetString(prefs::kShelfAlignmentLocal, value); | 268 prefs->SetString(prefs::kShelfAlignmentLocal, value); |
| 267 prefs->SetString(prefs::kShelfAlignment, value); | 269 prefs->SetString(prefs::kShelfAlignment, value); |
| 268 } | 270 } |
| 269 } | 271 } |
| 270 | 272 |
| 273 std::vector<std::string> GetPinnedAppsFromPrefs( | |
| 274 PrefService* prefs, | |
| 275 LauncherControllerHelper* helper) { | |
| 276 // Adding the app list item to the list of items requires that the ID is not | |
| 277 // a valid and known ID for the extension system. The ID was constructed that | |
| 278 // way - but just to make sure... | |
| 279 DCHECK(!helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder)); | |
| 280 | |
| 281 std::vector<std::string> apps; | |
| 282 const auto* pinned = prefs->GetList(prefs::kPinnedLauncherApps); | |
| 283 const auto* policy = prefs->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 284 | |
| 285 // Get the sanitized preference value for the index of the Chrome app icon. | |
| 286 const size_t chrome_icon_index = std::max<size_t>( | |
| 287 0, std::min<size_t>(pinned->GetSize(), | |
| 288 prefs->GetInteger(prefs::kShelfChromeIconIndex))); | |
| 289 | |
| 290 // Check if Chrome is in either of the the preferences lists. | |
| 291 std::unique_ptr<base::Value> chrome_app( | |
| 292 ash::CreateAppDict(extension_misc::kChromeAppId)); | |
| 293 bool chrome_listed = | |
| 294 (pinned->Find(*chrome_app.get()) != pinned->end() || | |
| 295 (policy && policy->Find(*chrome_app.get()) != policy->end())); | |
| 296 | |
| 297 std::string app_id; | |
| 298 const base::DictionaryValue* dictionary = nullptr; | |
|
sky
2016/05/02 15:21:48
nit: move dictionary inside both for loops.
msw
2016/05/02 20:01:09
Done.
| |
| 299 for (size_t i = 0; policy && (i < policy->GetSize()); ++i) { | |
| 300 if (policy->GetDictionary(i, &dictionary) && | |
| 301 dictionary->GetString(kPinnedAppsPrefAppIDPath, &app_id) && | |
| 302 helper->IsValidIDForCurrentUser(app_id) && | |
| 303 std::find(apps.begin(), apps.end(), app_id) == apps.end()) { | |
| 304 apps.push_back(app_id); | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 for (size_t i = 0; i < pinned->GetSize(); ++i) { | |
| 309 // We need to position the chrome icon relative to its place in the pinned | |
| 310 // preference list - even if an item of that list isn't shown yet. | |
| 311 if (i == chrome_icon_index && !chrome_listed) { | |
| 312 apps.push_back(extension_misc::kChromeAppId); | |
| 313 chrome_listed = true; | |
| 314 } | |
| 315 bool pinned_by_policy = false; | |
| 316 if (pinned->GetDictionary(i, &dictionary) && | |
| 317 dictionary->GetString(kPinnedAppsPrefAppIDPath, &app_id) && | |
| 318 helper->IsValidIDForCurrentUser(app_id) && | |
| 319 std::find(apps.begin(), apps.end(), app_id) == apps.end() && | |
| 320 (!dictionary->GetBoolean(kPinnedAppsPrefPinnedByPolicy, | |
| 321 &pinned_by_policy) || | |
| 322 !pinned_by_policy)) { | |
| 323 apps.push_back(app_id); | |
| 324 } | |
| 325 } | |
| 326 | |
| 327 // If not added yet, the chrome item will be the last item in the list. | |
| 328 if (!chrome_listed) | |
| 329 apps.push_back(extension_misc::kChromeAppId); | |
| 330 | |
| 331 // If not added yet, place the app list item at the beginning of the list. | |
| 332 if (std::find(apps.begin(), apps.end(), kPinnedAppsPlaceholder) == apps.end()) | |
| 333 apps.insert(apps.begin(), kPinnedAppsPlaceholder); | |
| 334 | |
| 335 return apps; | |
| 336 } | |
| 337 | |
| 271 } // namespace ash | 338 } // namespace ash |
| OLD | NEW |