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..58b532bd935eea17f7a22ecdf2861944dc3dafac 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) { |
stevenjb
2014/09/26 16:22:16
one line per arg
Matt Giuca
2014/09/30 02:49:47
I think this is fine, as long as they are all on o
calamity
2014/09/30 05:40:08
Yeah, this is ClangFormat's doing.
stevenjb
2014/09/30 18:16:23
Hm, we should probably update the style guide then
|
+ 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.folder_id = item->folder_id(); |
+ info.position = item->position(); |
+ info.name = item->name(); |
+ |
+ app_list_prefs_->SetAppListInfo(item->id(), info); |
+ } |
+ |
+ // Overridden from AppListModelObserver: |
+ void OnAppListItemAdded(AppListItem* item) override { |
+ UpdatePrefsFromAppListItem(item); |
+ } |
+ |
+ void OnAppListItemWillBeDeleted(AppListItem* item) override { |
+ app_list_prefs_->DeleteAppListInfo(item->id()); |
+ } |
+ |
+ void OnAppListItemUpdated(AppListItem* item) override { |
+ UpdatePrefsFromAppListItem(item); |
+ } |
+ |
+ AppListPrefs* app_list_prefs_; |
+ AppListModel* model_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PrefUpdater); |
+}; |
stevenjb
2014/09/26 16:22:16
This appears to be entirely independent of AppList
Matt Giuca
2014/09/30 02:49:47
It's simple and could be considered an implementat
calamity
2014/09/30 05:40:08
I also think of it as a utility class that allows
stevenjb
2014/09/30 18:16:23
The reason I don't especially like it here is that
calamity
2014/10/01 08:46:14
Done.
FYI, I think our conflict resolution plan i
stevenjb
2014/10/01 16:29:33
There are a couple of things that concern me off t
|
+ |
// 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_)); |
} |