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

Unified Diff: chrome/browser/ui/app_list/app_list_syncable_service.cc

Issue 2055553004: arc: Support pinned apps across Arc-enabled and Arc-disabled platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome_mash_shelf_controller.cc update due namespace renaming Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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..6737a65303b01c7e47f120ce0f1fdb68e7661d64 100644
--- a/chrome/browser/ui/app_list/app_list_syncable_service.cc
+++ b/chrome/browser/ui/app_list/app_list_syncable_service.cc
@@ -64,8 +64,12 @@ void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics,
item->item_type = specifics.item_type();
item->item_name = specifics.item_name();
item->parent_id = specifics.parent_id();
- if (!specifics.item_ordinal().empty())
+ if (specifics.has_item_ordinal())
item->item_ordinal = syncer::StringOrdinal(specifics.item_ordinal());
+ if (specifics.has_item_pin_ordinal()) {
+ item->item_pin_ordinal =
+ syncer::StringOrdinal(specifics.item_pin_ordinal());
+ }
}
bool UpdateSyncItemFromAppItem(const AppListItem* app_item,
@@ -96,8 +100,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 +304,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 +441,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 +711,8 @@ syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing(
// Start observing app list model changes.
model_observer_.reset(new ModelObserver(this));
+ NotifyObserversSyncUpdated();
+
return result;
}
@@ -726,6 +771,8 @@ syncer::SyncError AppListSyncableService::ProcessSyncChanges(
// Continue observing app list model changes.
model_observer_.reset(new ModelObserver(this));
+ NotifyObserversSyncUpdated();
+
return syncer::SyncError();
}
@@ -834,8 +881,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 +1062,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;
}
« no previous file with comments | « chrome/browser/ui/app_list/app_list_syncable_service.h ('k') | chrome/browser/ui/app_list/app_list_syncable_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698