| 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..d4be2a7b1d2feb8d64533eba137537ac468c6718 100644
|
| --- a/chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| +++ b/chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| @@ -15,6 +15,7 @@
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/app_list/app_list_prefs.h"
|
| #include "chrome/browser/ui/app_list/app_list_service.h"
|
| +#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
|
| #include "chrome/browser/ui/app_list/extension_app_item.h"
|
| #include "chrome/browser/ui/app_list/extension_app_model_builder.h"
|
| #include "chrome/browser/ui/app_list/model_pref_updater.h"
|
| @@ -66,6 +67,8 @@ 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());
|
| + item->item_pin_by_policy = specifics.item_pin_by_policy();
|
| }
|
|
|
| bool UpdateSyncItemFromAppItem(const AppListItem* app_item,
|
| @@ -98,6 +101,9 @@ void GetSyncSpecificsFromSyncItem(const AppListSyncableService::SyncItem* item,
|
| specifics->set_parent_id(item->parent_id);
|
| if (item->item_ordinal.IsValid())
|
| specifics->set_item_ordinal(item->item_ordinal.ToInternalValue());
|
| + specifics->set_item_pin_ordinal(item->item_pin_ordinal.IsValid() ?
|
| + item->item_pin_ordinal.ToInternalValue() : std::string());
|
| + specifics->set_item_pin_by_policy(item->item_pin_by_policy);
|
| }
|
|
|
| syncer::SyncData GetSyncDataFromSyncItem(
|
| @@ -173,7 +179,8 @@ AppListSyncableService::SyncItem::SyncItem(
|
| const std::string& id,
|
| sync_pb::AppListSpecifics::AppListItemType type)
|
| : item_id(id),
|
| - item_type(type) {
|
| + item_type(type),
|
| + item_pin_by_policy(false) {
|
| }
|
|
|
| AppListSyncableService::SyncItem::~SyncItem() {
|
| @@ -235,6 +242,12 @@ class AppListSyncableService::ModelObserver : public AppListModelObserver {
|
|
|
| // AppListSyncableService
|
|
|
| +// static
|
| +AppListSyncableService* AppListSyncableService::Get(Profile* profile) {
|
| + return AppListSyncableServiceFactory::GetForProfile(profile);
|
| +}
|
| +
|
| +
|
| AppListSyncableService::AppListSyncableService(
|
| Profile* profile,
|
| extensions::ExtensionSystem* extension_system)
|
| @@ -298,6 +311,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 +448,39 @@ AppListSyncableService::CreateSyncItemFromAppItem(AppListItem* app_item) {
|
| return sync_item;
|
| }
|
|
|
| +bool AppListSyncableService::GetPinByPolicy(const std::string& app_id) {
|
| + SyncItem* sync_item = FindSyncItem(app_id);
|
| + if (!sync_item)
|
| + return false;
|
| + return sync_item->item_pin_by_policy;
|
| +}
|
| +
|
| +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,
|
| + bool pinned_by_policy) {
|
| + 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;
|
| + sync_item->item_pin_by_policy = pinned_by_policy;
|
| + 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 +727,8 @@ syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing(
|
| // Start observing app list model changes.
|
| model_observer_.reset(new ModelObserver(this));
|
|
|
| + NotifyObserversSyncUpdated();
|
| +
|
| return result;
|
| }
|
|
|
| @@ -726,6 +787,8 @@ syncer::SyncError AppListSyncableService::ProcessSyncChanges(
|
| // Continue observing app list model changes.
|
| model_observer_.reset(new ModelObserver(this));
|
|
|
| + NotifyObserversSyncUpdated();
|
| +
|
| return syncer::SyncError();
|
| }
|
|
|
| @@ -834,7 +897,8 @@ 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() &&
|
| @@ -874,10 +938,11 @@ void AppListSyncableService::SendSyncChange(
|
| << sync_item->ToString();
|
| return;
|
| }
|
| - if (sync_change_type == SyncChange::ACTION_ADD)
|
| + if (sync_change_type == SyncChange::ACTION_ADD) {
|
| VLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString();
|
| - else
|
| + } else {
|
| VLOG(2) << this << " -> SYNC UPDATE: " << sync_item->ToString();
|
| + }
|
| SyncChange sync_change(FROM_HERE, sync_change_type,
|
| GetSyncDataFromSyncItem(sync_item));
|
| sync_processor_->ProcessSyncChanges(
|
| @@ -1013,6 +1078,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;
|
| }
|
|
|