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

Side by Side Diff: chrome/browser/ui/ash/chrome_launcher_prefs.cc

Issue 2352353002: Add AppLauncherId wrapper for items shown in shelf (Closed)
Patch Set: Rebase Created 4 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
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/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 <set> 9 #include <set>
10 10
(...skipping 24 matching lines...) Expand all
35 namespace { 35 namespace {
36 36
37 // App ID of default pinned apps. 37 // App ID of default pinned apps.
38 const char* kDefaultPinnedApps[] = { 38 const char* kDefaultPinnedApps[] = {
39 extension_misc::kGmailAppId, extension_misc::kGoogleDocAppId, 39 extension_misc::kGmailAppId, extension_misc::kGoogleDocAppId,
40 extension_misc::kYoutubeAppId, ArcSupportHost::kHostAppId}; 40 extension_misc::kYoutubeAppId, ArcSupportHost::kHostAppId};
41 41
42 base::ListValue* CreateDefaultPinnedAppsList() { 42 base::ListValue* CreateDefaultPinnedAppsList() {
43 std::unique_ptr<base::ListValue> apps(new base::ListValue); 43 std::unique_ptr<base::ListValue> apps(new base::ListValue);
44 for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i) 44 for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i)
45 apps->Append(CreateAppDict(kDefaultPinnedApps[i])); 45 apps->Append(CreateAppDict(AppLauncherId(kDefaultPinnedApps[i])));
46 46
47 return apps.release(); 47 return apps.release();
48 } 48 }
49 49
50 // Returns the preference value for the display with the given |display_id|. 50 // Returns the preference value for the display with the given |display_id|.
51 // The pref value is stored in |local_path| and |path|, but the pref service may 51 // The pref value is stored in |local_path| and |path|, but the pref service may
52 // have per-display preferences and the value can be specified by policy. 52 // have per-display preferences and the value can be specified by policy.
53 // Here is the priority: 53 // Here is the priority:
54 // * A value managed by policy. This is a single value that applies to all 54 // * A value managed by policy. This is a single value that applies to all
55 // displays. 55 // displays.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // copied to |local_path|. 199 // copied to |local_path|.
200 void PropagatePrefToLocalIfNotSet( 200 void PropagatePrefToLocalIfNotSet(
201 syncable_prefs::PrefServiceSyncable* pref_service, 201 syncable_prefs::PrefServiceSyncable* pref_service,
202 const char* local_path, 202 const char* local_path,
203 const char* synced_path) { 203 const char* synced_path) {
204 if (!pref_service->FindPreference(local_path)->HasUserSetting()) 204 if (!pref_service->FindPreference(local_path)->HasUserSetting())
205 pref_service->SetString(local_path, pref_service->GetString(synced_path)); 205 pref_service->SetString(local_path, pref_service->GetString(synced_path));
206 } 206 }
207 207
208 struct PinInfo { 208 struct PinInfo {
209 PinInfo(const std::string& app_id, const syncer::StringOrdinal& item_ordinal) 209 PinInfo(const AppLauncherId& app_launcher_id,
210 : app_id(app_id), item_ordinal(item_ordinal) {} 210 const syncer::StringOrdinal& item_ordinal)
211 : app_launcher_id(app_launcher_id.GetAsString()),
212 item_ordinal(item_ordinal) {}
211 213
212 std::string app_id; 214 std::string app_launcher_id;
213 syncer::StringOrdinal item_ordinal; 215 syncer::StringOrdinal item_ordinal;
214 }; 216 };
215 217
216 struct ComparePinInfo { 218 struct ComparePinInfo {
217 bool operator()(const PinInfo& pin1, const PinInfo& pin2) { 219 bool operator()(const PinInfo& pin1, const PinInfo& pin2) {
218 return pin1.item_ordinal.LessThan(pin2.item_ordinal); 220 return pin1.item_ordinal.LessThan(pin2.item_ordinal);
219 } 221 }
220 }; 222 };
221 223
222 // Helper class to keep apps in order of appearance and to provide fast way 224 // Helper class to keep apps in order of appearance and to provide fast way
223 // to check if app exists in the list. 225 // to check if app exists in the list.
224 class AppTracker { 226 class AppTracker {
225 public: 227 public:
226 bool HasApp(const std::string& app_id) const { 228 bool HasApp(const AppLauncherId& app_launcher_id) const {
227 return app_set_.find(app_id) != app_set_.end(); 229 return app_set_.find(app_launcher_id.GetAsString()) != app_set_.end();
228 } 230 }
229 231
230 void AddApp(const std::string& app_id) { 232 void AddApp(const AppLauncherId& app_launcher_id) {
231 if (HasApp(app_id)) 233 if (HasApp(app_launcher_id))
232 return; 234 return;
233 app_list_.push_back(app_id); 235 app_list_.push_back(app_launcher_id.GetAsString());
234 app_set_.insert(app_id); 236 app_set_.insert(app_launcher_id.GetAsString());
235 } 237 }
236 238
237 void MaybeAddApp(const std::string& app_id, 239 void MaybeAddApp(const AppLauncherId& app_launcher_id,
238 const LauncherControllerHelper* helper) { 240 const LauncherControllerHelper* helper) {
239 DCHECK_NE(kPinnedAppsPlaceholder, app_id); 241 DCHECK_NE(kPinnedAppsPlaceholder, app_launcher_id.GetAsString());
240 if (!helper->IsValidIDForCurrentUser(app_id)) 242 if (!helper->IsValidIDForCurrentUser(app_launcher_id.GetAsString()))
241 return; 243 return;
242 AddApp(app_id); 244 AddApp(app_launcher_id);
243 } 245 }
244 246
245 void MaybeAddAppFromPref(const base::DictionaryValue* app_pref, 247 void MaybeAddAppFromPref(const base::DictionaryValue* app_pref,
246 const LauncherControllerHelper* helper) { 248 const LauncherControllerHelper* helper) {
247 std::string app_id; 249 std::string app_id;
248 if (!app_pref->GetString(kPinnedAppsPrefAppIDPath, &app_id)) { 250 if (!app_pref->GetString(kPinnedAppsPrefAppIDPath, &app_id)) {
249 LOG(ERROR) << "Cannot get app id from app pref entry."; 251 LOG(ERROR) << "Cannot get app id from app pref entry.";
250 return; 252 return;
251 } 253 }
252 254
253 if (app_id == kPinnedAppsPlaceholder) 255 if (app_id == kPinnedAppsPlaceholder)
254 return; 256 return;
255 257
256 bool pinned_by_policy = false; 258 bool pinned_by_policy = false;
257 if (app_pref->GetBoolean(kPinnedAppsPrefPinnedByPolicy, 259 if (app_pref->GetBoolean(kPinnedAppsPrefPinnedByPolicy,
258 &pinned_by_policy) && 260 &pinned_by_policy) &&
259 pinned_by_policy) { 261 pinned_by_policy) {
260 return; 262 return;
261 } 263 }
262 264
263 MaybeAddApp(app_id, helper); 265 MaybeAddApp(AppLauncherId(app_id), helper);
264 } 266 }
265 267
266 const std::vector<std::string>& app_list() const { return app_list_; } 268 const std::vector<std::string>& app_list() const { return app_list_; }
stevenjb 2016/09/27 16:42:36 These should both store AppLauncherId instead of a
Andra Paraschiv 2016/10/03 15:53:02 Done.
267 269
268 private: 270 private:
269 std::vector<std::string> app_list_; 271 std::vector<std::string> app_list_;
270 std::set<std::string> app_set_; 272 std::set<std::string> app_set_;
271 }; 273 };
272 274
273 } // namespace 275 } // namespace
274 276
275 const char kPinnedAppsPrefAppIDPath[] = "id"; 277 const char kPinnedAppsPrefAppIDPath[] = "id";
276 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy"; 278 const char kPinnedAppsPrefPinnedByPolicy[] = "pinned_by_policy";
(...skipping 25 matching lines...) Expand all
302 std::string()); 304 std::string());
303 registry->RegisterStringPref(prefs::kShelfAlignment, 305 registry->RegisterStringPref(prefs::kShelfAlignment,
304 kShelfAlignmentBottom, 306 kShelfAlignmentBottom,
305 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 307 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
306 registry->RegisterStringPref(prefs::kShelfAlignmentLocal, std::string()); 308 registry->RegisterStringPref(prefs::kShelfAlignmentLocal, std::string());
307 registry->RegisterDictionaryPref(prefs::kShelfPreferences); 309 registry->RegisterDictionaryPref(prefs::kShelfPreferences);
308 registry->RegisterIntegerPref(prefs::kLogoutDialogDurationMs, 20000); 310 registry->RegisterIntegerPref(prefs::kLogoutDialogDurationMs, 20000);
309 registry->RegisterBooleanPref(prefs::kShowLogoutButtonInTray, false); 311 registry->RegisterBooleanPref(prefs::kShowLogoutButtonInTray, false);
310 } 312 }
311 313
312 base::DictionaryValue* CreateAppDict(const std::string& app_id) { 314 base::DictionaryValue* CreateAppDict(const AppLauncherId& app_launcher_id) {
313 std::unique_ptr<base::DictionaryValue> app_value(new base::DictionaryValue); 315 std::unique_ptr<base::DictionaryValue> app_value(new base::DictionaryValue);
314 app_value->SetString(kPinnedAppsPrefAppIDPath, app_id); 316 app_value->SetString(kPinnedAppsPrefAppIDPath, app_launcher_id.GetAsString());
315 return app_value.release(); 317 return app_value.release();
316 } 318 }
317 319
318 ShelfAutoHideBehavior GetShelfAutoHideBehaviorPref(PrefService* prefs, 320 ShelfAutoHideBehavior GetShelfAutoHideBehaviorPref(PrefService* prefs,
319 int64_t display_id) { 321 int64_t display_id) {
320 DCHECK_GE(display_id, 0); 322 DCHECK_GE(display_id, 0);
321 323
322 // Don't show the shelf in app mode. 324 // Don't show the shelf in app mode.
323 if (chrome::IsRunningInAppMode()) 325 if (chrome::IsRunningInAppMode())
324 return SHELF_AUTO_HIDE_ALWAYS_HIDDEN; 326 return SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (!arc_app_list_pref) 403 if (!arc_app_list_pref)
402 continue; 404 continue;
403 405
404 // We are dealing with package name, not with 32 characters ID. 406 // We are dealing with package name, not with 32 characters ID.
405 const std::string& arc_package = app_id; 407 const std::string& arc_package = app_id;
406 const std::vector<std::string> activities = GetActivitiesForPackage( 408 const std::vector<std::string> activities = GetActivitiesForPackage(
407 arc_package, all_arc_app_ids, *arc_app_list_pref); 409 arc_package, all_arc_app_ids, *arc_app_list_pref);
408 for (const auto& activity : activities) { 410 for (const auto& activity : activities) {
409 const std::string arc_app_id = 411 const std::string arc_app_id =
410 ArcAppListPrefs::GetAppId(arc_package, activity); 412 ArcAppListPrefs::GetAppId(arc_package, activity);
411 apps->MaybeAddApp(arc_app_id, helper); 413 apps->MaybeAddApp(AppLauncherId(arc_app_id), helper);
412 } 414 }
413 } else { 415 } else {
414 apps->MaybeAddApp(app_id, helper); 416 apps->MaybeAddApp(AppLauncherId(app_id), helper);
415 } 417 }
416 } 418 }
417 } 419 }
418 420
419 std::vector<std::string> GetPinnedAppsFromPrefsLegacy( 421 std::vector<std::string> GetPinnedAppsFromPrefsLegacy(
420 const PrefService* prefs, 422 const PrefService* prefs,
421 const LauncherControllerHelper* helper) { 423 const LauncherControllerHelper* helper) {
422 // Adding the app list item to the list of items requires that the ID is not 424 // Adding the app list item to the list of items requires that the ID is not
423 // a valid and known ID for the extension system. The ID was constructed that 425 // a valid and known ID for the extension system. The ID was constructed that
424 // way - but just to make sure... 426 // way - but just to make sure...
425 DCHECK(!helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder)); 427 DCHECK(!helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder));
426 428
427 const auto* pinned_apps = prefs->GetList(prefs::kPinnedLauncherApps); 429 const auto* pinned_apps = prefs->GetList(prefs::kPinnedLauncherApps);
428 430
429 // Get the sanitized preference value for the index of the Chrome app icon. 431 // Get the sanitized preference value for the index of the Chrome app icon.
430 const size_t chrome_icon_index = std::max<size_t>( 432 const size_t chrome_icon_index = std::max<size_t>(
431 0, std::min<size_t>(pinned_apps->GetSize(), 433 0, std::min<size_t>(pinned_apps->GetSize(),
432 prefs->GetInteger(prefs::kShelfChromeIconIndex))); 434 prefs->GetInteger(prefs::kShelfChromeIconIndex)));
433 435
434 // Check if Chrome is in either of the the preferences lists. 436 // Check if Chrome is in either of the the preferences lists.
435 std::unique_ptr<base::Value> chrome_app( 437 std::unique_ptr<base::Value> chrome_app(
436 CreateAppDict(extension_misc::kChromeAppId)); 438 CreateAppDict(AppLauncherId(extension_misc::kChromeAppId)));
437 439
438 AppTracker apps; 440 AppTracker apps;
439 GetAppsPinnedByPolicy(prefs, helper, &apps); 441 GetAppsPinnedByPolicy(prefs, helper, &apps);
440 442
441 std::string app_id; 443 std::string app_id;
442 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { 444 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) {
443 // We need to position the chrome icon relative to its place in the pinned 445 // We need to position the chrome icon relative to its place in the pinned
444 // preference list - even if an item of that list isn't shown yet. 446 // preference list - even if an item of that list isn't shown yet.
445 if (i == chrome_icon_index) 447 if (i == chrome_icon_index)
446 apps.AddApp(extension_misc::kChromeAppId); 448 apps.AddApp(AppLauncherId(extension_misc::kChromeAppId));
447 const base::DictionaryValue* app_pref = nullptr; 449 const base::DictionaryValue* app_pref = nullptr;
448 if (!pinned_apps->GetDictionary(i, &app_pref)) { 450 if (!pinned_apps->GetDictionary(i, &app_pref)) {
449 LOG(ERROR) << "There is no dictionary for app entry."; 451 LOG(ERROR) << "There is no dictionary for app entry.";
450 continue; 452 continue;
451 } 453 }
452 apps.MaybeAddAppFromPref(app_pref, helper); 454 apps.MaybeAddAppFromPref(app_pref, helper);
453 } 455 }
454 456
455 // If not added yet, the chrome item will be the last item in the list. 457 // If not added yet, the chrome item will be the last item in the list.
456 apps.AddApp(extension_misc::kChromeAppId); 458 apps.AddApp(AppLauncherId(extension_misc::kChromeAppId));
457 return apps.app_list(); 459 return apps.app_list();
458 } 460 }
459 461
460 // static 462 // static
461 std::unique_ptr<ChromeLauncherPrefsObserver> 463 std::unique_ptr<ChromeLauncherPrefsObserver>
462 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) { 464 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) {
463 syncable_prefs::PrefServiceSyncable* prefs = 465 syncable_prefs::PrefServiceSyncable* prefs =
464 PrefServiceSyncableFromProfile(profile); 466 PrefServiceSyncableFromProfile(profile);
465 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || 467 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() ||
466 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal) 468 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 if (!sync_peer.second->item_pin_ordinal.IsValid()) 592 if (!sync_peer.second->item_pin_ordinal.IsValid())
591 continue; 593 continue;
592 594
593 first_run = false; 595 first_run = false;
594 // Don't include apps that currently do not exist on device. 596 // Don't include apps that currently do not exist on device.
595 if (sync_peer.first != extension_misc::kChromeAppId && 597 if (sync_peer.first != extension_misc::kChromeAppId &&
596 !helper->IsValidIDForCurrentUser(sync_peer.first)) { 598 !helper->IsValidIDForCurrentUser(sync_peer.first)) {
597 continue; 599 continue;
598 } 600 }
599 601
600 pin_infos.push_back( 602 pin_infos.push_back(PinInfo(AppLauncherId(sync_peer.first),
601 PinInfo(sync_peer.first, sync_peer.second->item_pin_ordinal)); 603 sync_peer.second->item_pin_ordinal));
602 } 604 }
603 605
604 if (first_run) { 606 if (first_run) {
605 // We need to import legacy pins model and convert it to sync based 607 // We need to import legacy pins model and convert it to sync based
606 // model. 608 // model.
607 return ImportLegacyPinnedApps(prefs, helper, policy_apps); 609 return ImportLegacyPinnedApps(prefs, helper, policy_apps);
608 } 610 }
609 611
610 // Sort pins according their ordinals. 612 // Sort pins according their ordinals.
611 std::sort(pin_infos.begin(), pin_infos.end(), ComparePinInfo()); 613 std::sort(pin_infos.begin(), pin_infos.end(), ComparePinInfo());
612 614
613 // Pinned by policy apps appear first, if they were not shown before. 615 // Pinned by policy apps appear first, if they were not shown before.
614 syncer::StringOrdinal front_position = GetFirstPinPosition(helper->profile()); 616 syncer::StringOrdinal front_position = GetFirstPinPosition(helper->profile());
615 std::vector<std::string>::const_reverse_iterator it; 617 std::vector<std::string>::const_reverse_iterator it;
616 for (it = policy_apps.app_list().rbegin(); 618 for (it = policy_apps.app_list().rbegin();
617 it != policy_apps.app_list().rend(); ++it) { 619 it != policy_apps.app_list().rend(); ++it) {
618 const std::string& app_id = *it; 620 const std::string& app_id = *it;
619 if (app_id == kPinnedAppsPlaceholder) 621 if (app_id == kPinnedAppsPlaceholder)
620 continue; 622 continue;
621 623
622 // Check if we already processed current app. 624 // Check if we already processed current app.
623 if (app_service->GetPinPosition(app_id).IsValid()) 625 if (app_service->GetPinPosition(app_id).IsValid())
624 continue; 626 continue;
625 627
626 // Now move it to the front. 628 // Now move it to the front.
627 pin_infos.insert(pin_infos.begin(), PinInfo(app_id, front_position)); 629 pin_infos.insert(pin_infos.begin(),
630 PinInfo(AppLauncherId(app_id), front_position));
628 app_service->SetPinPosition(app_id, front_position); 631 app_service->SetPinPosition(app_id, front_position);
629 front_position = front_position.CreateBefore(); 632 front_position = front_position.CreateBefore();
630 } 633 }
631 634
632 // Now insert Chrome browser app if needed. 635 // Now insert Chrome browser app if needed.
633 if (!app_service->GetPinPosition(extension_misc::kChromeAppId).IsValid()) { 636 if (!app_service->GetPinPosition(extension_misc::kChromeAppId).IsValid()) {
634 pin_infos.insert(pin_infos.begin(), 637 pin_infos.insert(
635 PinInfo(extension_misc::kChromeAppId, front_position)); 638 pin_infos.begin(),
639 PinInfo(AppLauncherId(extension_misc::kChromeAppId), front_position));
636 app_service->SetPinPosition(extension_misc::kChromeAppId, front_position); 640 app_service->SetPinPosition(extension_misc::kChromeAppId, front_position);
637 } 641 }
638 642
639 if (helper->IsValidIDForCurrentUser(ArcSupportHost::kHostAppId)) { 643 if (helper->IsValidIDForCurrentUser(ArcSupportHost::kHostAppId)) {
640 if (!app_service->GetSyncItem(ArcSupportHost::kHostAppId)) { 644 if (!app_service->GetSyncItem(ArcSupportHost::kHostAppId)) {
641 const syncer::StringOrdinal arc_host_position = 645 const syncer::StringOrdinal arc_host_position =
642 GetLastPinPosition(helper->profile()); 646 GetLastPinPosition(helper->profile());
643 pin_infos.insert(pin_infos.begin(), 647 pin_infos.insert(pin_infos.begin(),
644 PinInfo(ArcSupportHost::kHostAppId, arc_host_position)); 648 PinInfo(AppLauncherId(ArcSupportHost::kHostAppId),
649 arc_host_position));
645 app_service->SetPinPosition(ArcSupportHost::kHostAppId, 650 app_service->SetPinPosition(ArcSupportHost::kHostAppId,
646 arc_host_position); 651 arc_host_position);
647 } 652 }
648 } 653 }
649 654
650 // Convert to string array. 655 // Convert to string array.
651 std::vector<std::string> pins(pin_infos.size()); 656 std::vector<std::string> pins(pin_infos.size());
652 for (size_t i = 0; i < pin_infos.size(); ++i) 657 for (size_t i = 0; i < pin_infos.size(); ++i)
653 pins[i] = pin_infos[i].app_id; 658 pins[i] = pin_infos[i].app_launcher_id;
654 659
655 return pins; 660 return pins;
656 } 661 }
657 662
658 void RemovePinPosition(Profile* profile, const std::string& app_id) { 663 void RemovePinPosition(Profile* profile, const AppLauncherId& app_launcher_id) {
659 DCHECK(profile); 664 DCHECK(profile);
660 DCHECK(!app_id.empty()); 665 const std::string launcher_id = app_launcher_id.GetAsString();
666 DCHECK(!launcher_id.empty());
661 app_list::AppListSyncableService* app_service = 667 app_list::AppListSyncableService* app_service =
662 app_list::AppListSyncableServiceFactory::GetForProfile(profile); 668 app_list::AppListSyncableServiceFactory::GetForProfile(profile);
663 app_service->SetPinPosition(app_id, syncer::StringOrdinal()); 669 app_service->SetPinPosition(launcher_id, syncer::StringOrdinal());
664 } 670 }
665 671
666 void SetPinPosition(Profile* profile, 672 void SetPinPosition(
667 const std::string& app_id, 673 Profile* profile,
668 const std::string& app_id_before, 674 const AppLauncherId& app_launcher_id,
669 const std::vector<std::string>& app_ids_after) { 675 const AppLauncherId& app_launcher_id_before,
676 const std::vector<std::unique_ptr<AppLauncherId>>& app_launcher_ids_after) {
670 DCHECK(profile); 677 DCHECK(profile);
671 DCHECK(!app_id.empty()); 678 const std::string launcher_id = app_launcher_id.GetAsString();
672 DCHECK_NE(app_id, app_id_before); 679 DCHECK(!launcher_id.empty());
680 const std::string launcher_id_before = app_launcher_id_before.GetAsString();
681 DCHECK_NE(launcher_id, launcher_id_before);
673 682
674 app_list::AppListSyncableService* app_service = 683 app_list::AppListSyncableService* app_service =
675 app_list::AppListSyncableServiceFactory::GetForProfile(profile); 684 app_list::AppListSyncableServiceFactory::GetForProfile(profile);
676 // Some unit tests may not have this service. 685 // Some unit tests may not have this service.
677 if (!app_service) 686 if (!app_service)
678 return; 687 return;
679 688
680 syncer::StringOrdinal position_before = 689 syncer::StringOrdinal position_before =
681 app_id_before.empty() ? syncer::StringOrdinal() 690 launcher_id_before.empty()
682 : app_service->GetPinPosition(app_id_before); 691 ? syncer::StringOrdinal()
692 : app_service->GetPinPosition(launcher_id_before);
683 syncer::StringOrdinal position_after; 693 syncer::StringOrdinal position_after;
684 for (const auto& app_id_after : app_ids_after) { 694 for (const auto& app_launcher_id_after : app_launcher_ids_after) {
685 DCHECK_NE(app_id_after, app_id); 695 const std::string launcher_id_after = app_launcher_id_after->GetAsString();
686 DCHECK_NE(app_id_after, app_id_before); 696 DCHECK_NE(launcher_id_after, launcher_id);
687 syncer::StringOrdinal position = app_service->GetPinPosition(app_id_after); 697 DCHECK_NE(launcher_id_after, launcher_id_before);
698 syncer::StringOrdinal position =
699 app_service->GetPinPosition(launcher_id_after);
688 DCHECK(position.IsValid()); 700 DCHECK(position.IsValid());
689 if (!position.IsValid()) { 701 if (!position.IsValid()) {
690 LOG(ERROR) << "Sync pin position was not found for " << app_id_after; 702 LOG(ERROR) << "Sync pin position was not found for " << launcher_id_after;
691 continue; 703 continue;
692 } 704 }
693 if (!position_before.IsValid() || !position.Equals(position_before)) { 705 if (!position_before.IsValid() || !position.Equals(position_before)) {
694 position_after = position; 706 position_after = position;
695 break; 707 break;
696 } 708 }
697 } 709 }
698 710
699 syncer::StringOrdinal pin_position; 711 syncer::StringOrdinal pin_position;
700 if (position_before.IsValid() && position_after.IsValid()) 712 if (position_before.IsValid() && position_after.IsValid())
701 pin_position = position_before.CreateBetween(position_after); 713 pin_position = position_before.CreateBetween(position_after);
702 else if (position_before.IsValid()) 714 else if (position_before.IsValid())
703 pin_position = position_before.CreateAfter(); 715 pin_position = position_before.CreateAfter();
704 else if (position_after.IsValid()) 716 else if (position_after.IsValid())
705 pin_position = position_after.CreateBefore(); 717 pin_position = position_after.CreateBefore();
706 else 718 else
707 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); 719 pin_position = syncer::StringOrdinal::CreateInitialOrdinal();
708 app_service->SetPinPosition(app_id, pin_position); 720 app_service->SetPinPosition(launcher_id, pin_position);
721 }
722
723 AppLauncherId::AppLauncherId(const std::string& app_id)
724 : app_launcher_id_(app_id) {}
725
726 AppLauncherId::AppLauncherId(const std::string& app_id,
727 const std::string& launch_id)
728 : app_launcher_id_(app_id + launch_id) {}
729
730 AppLauncherId::~AppLauncherId() {}
731
732 bool AppLauncherId::operator==(const AppLauncherId& app_launcher_id) const {
733 return app_launcher_id.GetAsString() == app_launcher_id_;
709 } 734 }
stevenjb 2016/09/27 16:42:36 These should match the order in the header (i.e be
Andra Paraschiv 2016/10/03 15:53:02 Done.
710 735
711 } // namespace launcher 736 } // namespace launcher
712 } // namespace ash 737 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698