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

Side by Side Diff: chrome/browser/ui/app_list/app_list_syncable_service.cc

Issue 2614803002: Prevent appearing INVALID position ordinal in sync. (Closed)
Patch Set: Created 3 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_list/app_list_syncable_service.h" 5 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 return CreateSyncItemFromAppItem(app_item); 560 return CreateSyncItemFromAppItem(app_item);
561 } 561 }
562 562
563 AppListSyncableService::SyncItem* 563 AppListSyncableService::SyncItem*
564 AppListSyncableService::CreateSyncItemFromAppItem(AppListItem* app_item) { 564 AppListSyncableService::CreateSyncItemFromAppItem(AppListItem* app_item) {
565 sync_pb::AppListSpecifics::AppListItemType type; 565 sync_pb::AppListSpecifics::AppListItemType type;
566 if (!GetAppListItemType(app_item, &type)) 566 if (!GetAppListItemType(app_item, &type))
567 return NULL; 567 return NULL;
568 VLOG(2) << this << " CreateSyncItemFromAppItem:" << app_item->ToDebugString(); 568 VLOG(2) << this << " CreateSyncItemFromAppItem:" << app_item->ToDebugString();
569 SyncItem* sync_item = CreateSyncItem(app_item->id(), type); 569 SyncItem* sync_item = CreateSyncItem(app_item->id(), type);
570 DCHECK(app_item->position().IsValid());
570 UpdateSyncItemFromAppItem(app_item, sync_item); 571 UpdateSyncItemFromAppItem(app_item, sync_item);
571 UpdateSyncItemInLocalStorage(profile_, sync_item); 572 UpdateSyncItemInLocalStorage(profile_, sync_item);
572 SendSyncChange(sync_item, SyncChange::ACTION_ADD); 573 SendSyncChange(sync_item, SyncChange::ACTION_ADD);
573 return sync_item; 574 return sync_item;
574 } 575 }
575 576
576 syncer::StringOrdinal AppListSyncableService::GetPinPosition( 577 syncer::StringOrdinal AppListSyncableService::GetPinPosition(
577 const std::string& app_id) { 578 const std::string& app_id) {
578 SyncItem* sync_item = FindSyncItem(app_id); 579 SyncItem* sync_item = FindSyncItem(app_id);
579 if (!sync_item) 580 if (!sync_item)
580 return syncer::StringOrdinal(); 581 return syncer::StringOrdinal();
581 return sync_item->item_pin_ordinal; 582 return sync_item->item_pin_ordinal;
582 } 583 }
583 584
584 void AppListSyncableService::SetPinPosition( 585 void AppListSyncableService::SetPinPosition(
585 const std::string& app_id, 586 const std::string& app_id,
586 const syncer::StringOrdinal& item_pin_ordinal) { 587 const syncer::StringOrdinal& item_pin_ordinal) {
588 // Pin position can be set only after model is built.
589 DCHECK(IsInitialized());
587 SyncItem* sync_item = FindSyncItem(app_id); 590 SyncItem* sync_item = FindSyncItem(app_id);
588 SyncChange::SyncChangeType sync_change_type; 591 SyncChange::SyncChangeType sync_change_type;
589 if (sync_item) { 592 if (sync_item) {
590 sync_change_type = SyncChange::ACTION_UPDATE; 593 sync_change_type = SyncChange::ACTION_UPDATE;
591 } else { 594 } else {
592 sync_item = CreateSyncItem(app_id, sync_pb::AppListSpecifics::TYPE_APP); 595 sync_item = CreateSyncItem(app_id, sync_pb::AppListSpecifics::TYPE_APP);
593 sync_change_type = SyncChange::ACTION_ADD; 596 sync_change_type = SyncChange::ACTION_ADD;
594 } 597 }
595 598
596 sync_item->item_pin_ordinal = item_pin_ordinal; 599 sync_item->item_pin_ordinal = item_pin_ordinal;
597 UpdateSyncItemInLocalStorage(profile_, sync_item); 600 UpdateSyncItemInLocalStorage(profile_, sync_item);
598 SendSyncChange(sync_item, sync_change_type); 601 SendSyncChange(sync_item, sync_change_type);
599 } 602 }
600 603
601 void AppListSyncableService::AddOrUpdateFromSyncItem(AppListItem* app_item) { 604 void AppListSyncableService::AddOrUpdateFromSyncItem(AppListItem* app_item) {
602 // Do not create a sync item for the OEM folder here, do that in 605 // Do not create a sync item for the OEM folder here, do that in
603 // ResolveFolderPositions once the position has been resolved. 606 // ResolveFolderPositions once the position has been resolved.
604 if (app_item->id() == kOemFolderId) 607 if (app_item->id() == kOemFolderId)
605 return; 608 return;
606 609
610 DCHECK(app_item->position().IsValid());
611
607 SyncItem* sync_item = FindSyncItem(app_item->id()); 612 SyncItem* sync_item = FindSyncItem(app_item->id());
608 if (sync_item) { 613 if (sync_item) {
609 UpdateAppItemFromSyncItem(sync_item, app_item); 614 UpdateAppItemFromSyncItem(sync_item, app_item);
615 if (!sync_item->item_ordinal.IsValid()) {
616 UpdateSyncItem(app_item);
617 VLOG(2) << "Flushing position to sync item " << sync_item;
618 }
610 return; 619 return;
611 } 620 }
612 CreateSyncItemFromAppItem(app_item); 621 CreateSyncItemFromAppItem(app_item);
613 } 622 }
614 623
615 bool AppListSyncableService::RemoveDefaultApp(AppListItem* item, 624 bool AppListSyncableService::RemoveDefaultApp(AppListItem* item,
616 SyncItem* sync_item) { 625 SyncItem* sync_item) {
617 CHECK_EQ(sync_item->item_type, 626 CHECK_EQ(sync_item->item_type,
618 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP); 627 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP);
619 628
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 SyncItem* sync_item = FindSyncItem(*iter); 842 SyncItem* sync_item = FindSyncItem(*iter);
834 // Sync can cause an item to change folders, causing an unsynced folder 843 // Sync can cause an item to change folders, causing an unsynced folder
835 // item to be removed. 844 // item to be removed.
836 if (!sync_item) 845 if (!sync_item)
837 continue; 846 continue;
838 VLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString(); 847 VLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString();
839 UpdateSyncItemInLocalStorage(profile_, sync_item); 848 UpdateSyncItemInLocalStorage(profile_, sync_item);
840 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD, 849 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD,
841 GetSyncDataFromSyncItem(sync_item))); 850 GetSyncDataFromSyncItem(sync_item)));
842 } 851 }
852
853 // Fix items that do not contain valid app list position, required for
854 // builds prior to M53.
stevenjb 2017/01/04 20:34:26 nit: reference crbug.
khmel 2017/01/04 21:15:12 Done.
855 for (const auto& sync_pair : sync_items_) {
856 SyncItem* sync_item = sync_pair.second.get();
857 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_APP ||
858 sync_item->item_ordinal.IsValid()) {
859 continue;
860 }
861 const AppListItem* app_item = model_->FindItem(sync_item->item_id);
862 if (app_item) {
863 if (UpdateSyncItemFromAppItem(app_item, sync_item)) {
864 VLOG(1) << "Fixing sync item from existing app " << sync_item;
865 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_UPDATE,
866 GetSyncDataFromSyncItem(sync_item)));
867 } else {
868 VLOG(1) << "Failed to fix sync item from existing app " << sync_item;
stevenjb 2017/01/04 20:34:26 Maybe use: sync_item->item_ordinal = syncer::Strin
khmel 2017/01/04 21:15:12 Good point!
869 }
870 } else {
871 sync_item->item_ordinal = syncer::StringOrdinal::CreateInitialOrdinal();
872 VLOG(1) << "Fixing sync item by generate new position ordinal "
stevenjb 2017/01/04 20:34:26 nit: s/generate/generating/ also: ":" separating s
khmel 2017/01/04 21:15:12 Done.
873 << sync_item;
874 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_UPDATE,
875 GetSyncDataFromSyncItem(sync_item)));
876 }
877 }
878
843 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); 879 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
844 880
845 HandleUpdateFinished(); 881 HandleUpdateFinished();
846 882
847 return result; 883 return result;
848 } 884 }
849 885
850 void AppListSyncableService::StopSyncing(syncer::ModelType type) { 886 void AppListSyncableService::StopSyncing(syncer::ModelType type) {
851 DCHECK_EQ(type, syncer::APP_LIST); 887 DCHECK_EQ(type, syncer::APP_LIST);
852 888
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 res += " { " + item_name + " }"; 1228 res += " { " + item_name + " }";
1193 res += " [" + item_ordinal.ToDebugString() + "]"; 1229 res += " [" + item_ordinal.ToDebugString() + "]";
1194 if (!parent_id.empty()) 1230 if (!parent_id.empty())
1195 res += " <" + parent_id.substr(0, 8) + ">"; 1231 res += " <" + parent_id.substr(0, 8) + ">";
1196 res += " [" + item_pin_ordinal.ToDebugString() + "]"; 1232 res += " [" + item_pin_ordinal.ToDebugString() + "]";
1197 } 1233 }
1198 return res; 1234 return res;
1199 } 1235 }
1200 1236
1201 } // namespace app_list 1237 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/app_list/chrome_app_list_item.cc » ('j') | chrome/browser/ui/app_list/chrome_app_list_item.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698