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

Unified Diff: chrome/browser/ui/app_list/model_pref_updater.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: add unit test Created 6 years, 2 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/model_pref_updater.cc
diff --git a/chrome/browser/ui/app_list/model_pref_updater.cc b/chrome/browser/ui/app_list/model_pref_updater.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea79bd9d58473968ea12092466fc45a41178b885
--- /dev/null
+++ b/chrome/browser/ui/app_list/model_pref_updater.cc
@@ -0,0 +1,54 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/app_list/model_pref_updater.h"
+
+#include "chrome/browser/ui/app_list/app_list_prefs.h"
+#include "chrome/browser/ui/app_list/extension_app_item.h"
+#include "ui/app_list/app_list_folder_item.h"
+#include "ui/app_list/app_list_item.h"
+#include "ui/app_list/app_list_model.h"
+
+namespace app_list {
+
+ModelPrefUpdater::ModelPrefUpdater(AppListPrefs* app_list_prefs,
+ AppListModel* model)
+ : app_list_prefs_(app_list_prefs), model_(model) {
+ model_->AddObserver(this);
+}
+
+ModelPrefUpdater::~ModelPrefUpdater() {
+ model_->RemoveObserver(this);
+}
+
+void ModelPrefUpdater::OnAppListItemAdded(AppListItem* item) {
+ UpdatePrefsFromAppListItem(item);
+}
+
+void ModelPrefUpdater::OnAppListItemWillBeDeleted(AppListItem* item) {
+ app_list_prefs_->DeleteAppListInfo(item->id());
+}
+
+void ModelPrefUpdater::OnAppListItemUpdated(AppListItem* item) {
+ UpdatePrefsFromAppListItem(item);
+}
+
+void ModelPrefUpdater::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);
+}
+
+} // namespace app_list
« no previous file with comments | « chrome/browser/ui/app_list/model_pref_updater.h ('k') | chrome/browser/ui/app_list/model_pref_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698