Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_syncable_service.cc |
| diff --git a/chrome/browser/ui/app_list/app_list_syncable_service.cc b/chrome/browser/ui/app_list/app_list_syncable_service.cc |
| index 261b361ff62c4902f0e0c1ba9637c7eb2e9b48c0..63bc4fc5d665a6452b956e2eecef98da113837f2 100644 |
| --- a/chrome/browser/ui/app_list/app_list_syncable_service.cc |
| +++ b/chrome/browser/ui/app_list/app_list_syncable_service.cc |
| @@ -66,6 +66,7 @@ void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics, |
| item->parent_id = specifics.parent_id(); |
| if (!specifics.item_ordinal().empty()) |
| item->item_ordinal = syncer::StringOrdinal(specifics.item_ordinal()); |
| + item->item_pin_ordinal = syncer::StringOrdinal(specifics.item_pin_ordinal()); |
|
stevenjb
2016/06/14 22:44:08
An unfortunate side effect of this is that if an o
khmel
2016/06/15 17:01:19
That is great point. I missed this possibility, th
|
| } |
| bool UpdateSyncItemFromAppItem(const AppListItem* app_item, |
| @@ -96,8 +97,10 @@ void GetSyncSpecificsFromSyncItem(const AppListSyncableService::SyncItem* item, |
| specifics->set_item_type(item->item_type); |
| specifics->set_item_name(item->item_name); |
| specifics->set_parent_id(item->parent_id); |
| - if (item->item_ordinal.IsValid()) |
| - specifics->set_item_ordinal(item->item_ordinal.ToInternalValue()); |
| + specifics->set_item_ordinal(item->item_ordinal.IsValid() ? |
| + item->item_ordinal.ToInternalValue() : std::string()); |
| + specifics->set_item_pin_ordinal(item->item_pin_ordinal.IsValid() ? |
| + item->item_pin_ordinal.ToInternalValue() : std::string()); |
| } |
| syncer::SyncData GetSyncDataFromSyncItem( |
| @@ -298,6 +301,19 @@ void AppListSyncableService::BuildModel() { |
| drive_app_provider_.reset(new DriveAppProvider(profile_, this)); |
| } |
| +void AppListSyncableService::AddObserverAndStart(Observer* observer) { |
| + observer_list_.AddObserver(observer); |
| + SyncStarted(); |
| +} |
| + |
| +void AppListSyncableService::RemoveObserver(Observer* observer) { |
| + observer_list_.RemoveObserver(observer); |
| +} |
| + |
| +void AppListSyncableService::NotifyObserversSyncUpdated() { |
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnSyncModelUpdated()); |
| +} |
| + |
| size_t AppListSyncableService::GetNumSyncItemsForTest() { |
| // If the model isn't built yet, there will be no sync items. |
| GetModel(); |
| @@ -422,6 +438,30 @@ AppListSyncableService::CreateSyncItemFromAppItem(AppListItem* app_item) { |
| return sync_item; |
| } |
| +syncer::StringOrdinal AppListSyncableService::GetPinPosition( |
| + const std::string& app_id) { |
| + SyncItem* sync_item = FindSyncItem(app_id); |
| + if (!sync_item) |
| + return syncer::StringOrdinal(); |
| + return sync_item->item_pin_ordinal; |
| +} |
| + |
| +void AppListSyncableService::SetPinPosition( |
| + const std::string& app_id, |
| + const syncer::StringOrdinal& item_pin_ordinal) { |
| + SyncItem* sync_item = FindSyncItem(app_id); |
| + SyncChange::SyncChangeType sync_change_type; |
| + if (sync_item) { |
| + sync_change_type = SyncChange::ACTION_UPDATE; |
| + } else { |
| + sync_item = CreateSyncItem(app_id, sync_pb::AppListSpecifics::TYPE_APP); |
| + sync_change_type = SyncChange::ACTION_ADD; |
| + } |
| + |
| + sync_item->item_pin_ordinal = item_pin_ordinal; |
| + SendSyncChange(sync_item, sync_change_type); |
| +} |
| + |
| void AppListSyncableService::AddOrUpdateFromSyncItem(AppListItem* app_item) { |
| // Do not create a sync item for the OEM folder here, do that in |
| // ResolveFolderPositions once the position has been resolved. |
| @@ -668,6 +708,8 @@ syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing( |
| // Start observing app list model changes. |
| model_observer_.reset(new ModelObserver(this)); |
| + NotifyObserversSyncUpdated(); |
| + |
| return result; |
| } |
| @@ -726,6 +768,8 @@ syncer::SyncError AppListSyncableService::ProcessSyncChanges( |
| // Continue observing app list model changes. |
| model_observer_.reset(new ModelObserver(this)); |
| + NotifyObserversSyncUpdated(); |
| + |
| return syncer::SyncError(); |
| } |
| @@ -834,8 +878,10 @@ void AppListSyncableService::UpdateAppItemFromSyncItem( |
| const AppListSyncableService::SyncItem* sync_item, |
| AppListItem* app_item) { |
| VLOG(2) << this << " UpdateAppItemFromSyncItem: " << sync_item->ToString(); |
| - if (!app_item->position().Equals(sync_item->item_ordinal)) |
| + if (sync_item->item_ordinal.IsValid() && |
| + !app_item->position().Equals(sync_item->item_ordinal)) { |
| model_->SetItemPosition(app_item, sync_item->item_ordinal); |
| + } |
| // Only update the item name if it is a Folder or the name is empty. |
| if (sync_item->item_name != app_item->name() && |
| sync_item->item_id != kOemFolderId && |
| @@ -1013,6 +1059,7 @@ std::string AppListSyncableService::SyncItem::ToString() const { |
| res += " [" + item_ordinal.ToDebugString() + "]"; |
| if (!parent_id.empty()) |
| res += " <" + parent_id.substr(0, 8) + ">"; |
| + res += " [" + item_pin_ordinal.ToDebugString() + "]"; |
| } |
| return res; |
| } |