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/app_tab_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/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 21 | 22 |
| 22 namespace ash { | 23 namespace ash { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 161 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
| 161 // This should not be a valid preference option for now. We only want to | 162 // This should not be a valid preference option for now. We only want to |
| 162 // completely hide it when we run in app mode - or while we temporarily | 163 // completely hide it when we run in app mode - or while we temporarily |
| 163 // hide the shelf as part of an animation (e.g. the multi user change). | 164 // hide the shelf as part of an animation (e.g. the multi user change). |
| 164 return nullptr; | 165 return nullptr; |
| 165 } | 166 } |
| 166 NOTREACHED(); | 167 NOTREACHED(); |
| 167 return nullptr; | 168 return nullptr; |
| 168 } | 169 } |
| 169 | 170 |
| 171 void UpdatePinnedApps(const std::string& app_id, | |
|
sky
2016/04/27 21:01:33
I see you're just moving this code, but have some
| |
| 172 bool valid_for_current_user, | |
| 173 std::vector<std::string>* pinned_apps, | |
| 174 bool* chrome_icon_added, | |
| 175 bool* app_list_icon_added) { | |
| 176 if (app_id == extension_misc::kChromeAppId) { | |
| 177 *chrome_icon_added = true; | |
|
sky
2016/04/27 21:01:33
nit: always set to false early on to avoid possibl
msw
2016/04/29 22:30:49
This function was called repeatedly with the same
| |
| 178 pinned_apps->push_back(extension_misc::kChromeAppId); | |
| 179 } else if (app_id == kPinnedAppsPlaceholder) { | |
| 180 *app_list_icon_added = true; | |
| 181 pinned_apps->push_back(kPinnedAppsPlaceholder); | |
| 182 } else if (valid_for_current_user) { | |
| 183 // Note: In multi profile scenarios we only want to show pinnable apps | |
| 184 // here which is correct. Running applications from the other users will | |
| 185 // continue to run. So no need for multi profile modifications. | |
| 186 pinned_apps->push_back(app_id); | |
| 187 } | |
| 188 } | |
| 189 | |
| 170 } // namespace | 190 } // namespace |
| 171 | 191 |
| 172 const char kPinnedAppsPrefAppIDPath[] = "id"; | 192 const char kPinnedAppsPrefAppIDPath[] = "id"; |
| 173 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy"; | 193 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy"; |
| 194 const char kPinnedAppsPlaceholder[] = "AppShelfIDPlaceholder--------"; | |
| 174 | 195 |
| 175 const char kShelfAutoHideBehaviorAlways[] = "Always"; | 196 const char kShelfAutoHideBehaviorAlways[] = "Always"; |
| 176 const char kShelfAutoHideBehaviorNever[] = "Never"; | 197 const char kShelfAutoHideBehaviorNever[] = "Never"; |
| 177 | 198 |
| 178 const char kShelfAlignmentBottom[] = "Bottom"; | 199 const char kShelfAlignmentBottom[] = "Bottom"; |
| 179 const char kShelfAlignmentLeft[] = "Left"; | 200 const char kShelfAlignmentLeft[] = "Left"; |
| 180 const char kShelfAlignmentRight[] = "Right"; | 201 const char kShelfAlignmentRight[] = "Right"; |
| 181 | 202 |
| 182 void RegisterChromeLauncherUserPrefs( | 203 void RegisterChromeLauncherUserPrefs( |
| 183 user_prefs::PrefRegistrySyncable* registry) { | 204 user_prefs::PrefRegistrySyncable* registry) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return; | 282 return; |
| 262 | 283 |
| 263 SetPerDisplayPref(prefs, display_id, prefs::kShelfAlignment, value); | 284 SetPerDisplayPref(prefs, display_id, prefs::kShelfAlignment, value); |
| 264 if (display_id == gfx::Screen::GetScreen()->GetPrimaryDisplay().id()) { | 285 if (display_id == gfx::Screen::GetScreen()->GetPrimaryDisplay().id()) { |
| 265 // See comment in |kShelfAlignment| as to why we consider two prefs. | 286 // See comment in |kShelfAlignment| as to why we consider two prefs. |
| 266 prefs->SetString(prefs::kShelfAlignmentLocal, value); | 287 prefs->SetString(prefs::kShelfAlignmentLocal, value); |
| 267 prefs->SetString(prefs::kShelfAlignment, value); | 288 prefs->SetString(prefs::kShelfAlignment, value); |
| 268 } | 289 } |
| 269 } | 290 } |
| 270 | 291 |
| 292 std::vector<std::string> GetPinnedAppsFromPrefs(PrefService* prefs, | |
|
sky
2016/04/27 21:01:33
I'm assuming this is a straight move.
msw
2016/04/29 22:30:49
Not quite... I refactored this a bit, my next PS g
| |
| 293 AppTabHelper* app_tab_helper) { | |
| 294 // Adding the app list item to the list of items requires that the ID is not | |
| 295 // a valid and known ID for the extension system. The ID was constructed that | |
| 296 // way - but just to make sure... | |
| 297 DCHECK(!app_tab_helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder)); | |
| 298 | |
| 299 std::vector<std::string> pinned_apps; | |
| 300 | |
| 301 const base::ListValue* pinned_apps_pref = | |
| 302 prefs->GetList(prefs::kPinnedLauncherApps); | |
| 303 const base::ListValue* policy_pinned_apps_pref = | |
| 304 prefs->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 305 | |
| 306 // Keep track of the addition of the chrome and the app list icon. | |
| 307 bool chrome_icon_added = false; | |
| 308 bool app_list_icon_added = false; | |
| 309 | |
| 310 const size_t chrome_icon_index = std::max<size_t>( | |
| 311 0, std::min<size_t>(pinned_apps_pref->GetSize(), | |
| 312 prefs->GetInteger(prefs::kShelfChromeIconIndex))); | |
| 313 | |
| 314 if (policy_pinned_apps_pref) { | |
| 315 for (size_t i = 0; i < policy_pinned_apps_pref->GetSize(); ++i) { | |
| 316 const base::DictionaryValue* app = nullptr; | |
| 317 std::string app_id; | |
| 318 if (policy_pinned_apps_pref->GetDictionary(i, &app) && | |
| 319 app->GetString(kPinnedAppsPrefAppIDPath, &app_id) && | |
| 320 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 321 pinned_apps.end())) | |
| 322 UpdatePinnedApps( | |
| 323 app_id, app_tab_helper->IsValidIDForCurrentUser(app_id), | |
| 324 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 for (size_t i = 0; i < pinned_apps_pref->GetSize(); ++i) { | |
| 329 // We need to position the chrome icon relative to its place in the pinned | |
| 330 // preference list - even if an item of that list isn't shown yet. | |
| 331 if (i == chrome_icon_index && !chrome_icon_added) { | |
| 332 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 333 chrome_icon_added = true; | |
| 334 } | |
| 335 const base::DictionaryValue* app = nullptr; | |
| 336 std::string app_id; | |
| 337 if (pinned_apps_pref->GetDictionary(i, &app) && | |
| 338 app->GetString(kPinnedAppsPrefAppIDPath, &app_id) && | |
| 339 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 340 pinned_apps.end())) { | |
| 341 bool pinned_by_policy = false; | |
| 342 if (app->GetBoolean(kPinnedAppsPrefPinnedByPolicy, &pinned_by_policy) && | |
| 343 pinned_by_policy) { | |
| 344 continue; | |
| 345 } | |
| 346 UpdatePinnedApps(app_id, app_tab_helper->IsValidIDForCurrentUser(app_id), | |
| 347 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 // If not added yet, the chrome item will be the last item in the list. | |
| 352 if (!chrome_icon_added) | |
| 353 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 354 | |
| 355 // If not added yet, add the app list item either at the end or at the | |
| 356 // beginning - depending on the shelf layout. | |
| 357 if (!app_list_icon_added) | |
| 358 pinned_apps.insert(pinned_apps.begin(), kPinnedAppsPlaceholder); | |
| 359 | |
| 360 return pinned_apps; | |
| 361 } | |
| 362 | |
| 271 } // namespace ash | 363 } // namespace ash |
| OLD | NEW |