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

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: cleanup and update 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..cc57b3355bfa7a846d5af930ef9bd8026e249d98 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());
stevenjb 2016/06/10 18:00:40 We should modify the logic lines 102/103 to match
khmel 2016/06/10 22:08:10 Done.
+ 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,11 @@ class AppListSyncableService::ModelObserver : public AppListModelObserver {
// AppListSyncableService
+// static
+AppListSyncableService* AppListSyncableService::Get(Profile* profile) {
+ return AppListSyncableServiceFactory::GetForProfile(profile);
+}
stevenjb 2016/06/10 18:00:40 This is unnecessary, we should just use AppListSyn
khmel 2016/06/10 22:08:10 Sorry, I just added this helper similar to some ot
stevenjb 2016/06/14 22:44:08 It's not inherently wrong, but we do try to go by
+
AppListSyncableService::AppListSyncableService(
Profile* profile,
extensions::ExtensionSystem* extension_system)
@@ -298,6 +310,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 +447,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 +726,8 @@ syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing(
// Start observing app list model changes.
model_observer_.reset(new ModelObserver(this));
+ NotifyObserversSyncUpdated();
+
return result;
}
@@ -726,6 +786,8 @@ syncer::SyncError AppListSyncableService::ProcessSyncChanges(
// Continue observing app list model changes.
model_observer_.reset(new ModelObserver(this));
+ NotifyObserversSyncUpdated();
+
return syncer::SyncError();
}
@@ -834,7 +896,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);
stevenjb 2016/06/10 18:00:40 {}
khmel 2016/06/10 22:08:10 Done.
// Only update the item name if it is a Folder or the name is empty.
if (sync_item->item_name != app_item->name() &&
@@ -1013,6 +1076,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;
}

Powered by Google App Engine
This is Rietveld 408576698