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

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

Issue 599343002: Mirror app list hierarchy data in profile prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_list_folder_pref
Patch Set: address comments Created 6 years, 3 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 f4d38d99435653204034badc8b1bda7df44e83f4..1cee4246acf247cc5ed76d6dd7a648b5f2a0bbef 100644
--- a/chrome/browser/ui/app_list/app_list_syncable_service.cc
+++ b/chrome/browser/ui/app_list/app_list_syncable_service.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#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/extension_app_item.h"
#include "chrome/browser/ui/app_list/extension_app_model_builder.h"
@@ -203,6 +204,54 @@ class AppListSyncableService::ModelObserver : public AppListModelObserver {
DISALLOW_COPY_AND_ASSIGN(ModelObserver);
};
+// AppListSyncableService::PrefUpdater
+
+class AppListSyncableService::PrefUpdater : public AppListModelObserver {
+ public:
+ explicit PrefUpdater(AppListPrefs* app_list_prefs, AppListModel* model)
+ : app_list_prefs_(app_list_prefs), model_(model) {
+ model_->AddObserver(this);
+ }
+
+ virtual ~PrefUpdater() { model_->RemoveObserver(this); }
+
+ private:
+ void UpdatePrefsFromAppListItem(AppListItem* item) {
+ // Write synced data to local pref.
+ AppListPrefs::AppListInfo info;
+ if (item->GetItemType() == AppListFolderItem::kItemType)
+ info.item_type = AppListPrefs::AppListInfo::FOLDER_ITEM;
+ else if (item->GetItemType() == ExtensionAppItem::kItemType)
+ info.item_type = AppListPrefs::AppListInfo::APP_ITEM;
+ else
+ NOTREACHED();
+
+ info.parent_id = item->folder_id();
+ info.position = item->position();
+ info.name = item->name();
+
+ app_list_prefs_->SetAppListInfo(item->id(), info);
+ }
+
+ // Overridden from AppListModelObserver:
+ virtual void OnAppListItemAdded(AppListItem* item) OVERRIDE {
+ UpdatePrefsFromAppListItem(item);
+ }
+
+ virtual void OnAppListItemWillBeDeleted(AppListItem* item) OVERRIDE {
+ app_list_prefs_->DeleteAppListInfo(item->id());
+ }
+
+ virtual void OnAppListItemUpdated(AppListItem* item) OVERRIDE {
+ UpdatePrefsFromAppListItem(item);
+ }
+
+ AppListPrefs* app_list_prefs_;
+ AppListModel* model_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefUpdater);
+};
+
// AppListSyncableService
AppListSyncableService::AppListSyncableService(
@@ -264,6 +313,9 @@ void AppListSyncableService::BuildModel() {
apps_builder_->InitializeWithProfile(profile_, model_.get());
}
+ pref_updater_.reset(
+ new PrefUpdater(AppListPrefs::Get(profile_), model_.get()));
+
if (app_list::switches::IsDriveAppsInAppListEnabled())
drive_app_provider_.reset(new DriveAppProvider(profile_));
}

Powered by Google App Engine
This is Rietveld 408576698