OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/app_list/model_pref_updater.h" |
| 6 |
| 7 #include "chrome/browser/ui/app_list/app_list_prefs.h" |
| 8 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 9 #include "ui/app_list/app_list_folder_item.h" |
| 10 #include "ui/app_list/app_list_item.h" |
| 11 #include "ui/app_list/app_list_model.h" |
| 12 |
| 13 namespace app_list { |
| 14 |
| 15 ModelPrefUpdater::ModelPrefUpdater(AppListPrefs* app_list_prefs, |
| 16 AppListModel* model) |
| 17 : app_list_prefs_(app_list_prefs), model_(model) { |
| 18 model_->AddObserver(this); |
| 19 } |
| 20 |
| 21 ModelPrefUpdater::~ModelPrefUpdater() { |
| 22 model_->RemoveObserver(this); |
| 23 } |
| 24 |
| 25 void ModelPrefUpdater::OnAppListItemAdded(AppListItem* item) { |
| 26 UpdatePrefsFromAppListItem(item); |
| 27 } |
| 28 |
| 29 void ModelPrefUpdater::OnAppListItemWillBeDeleted(AppListItem* item) { |
| 30 app_list_prefs_->DeleteAppListInfo(item->id()); |
| 31 } |
| 32 |
| 33 void ModelPrefUpdater::OnAppListItemUpdated(AppListItem* item) { |
| 34 UpdatePrefsFromAppListItem(item); |
| 35 } |
| 36 |
| 37 void ModelPrefUpdater::UpdatePrefsFromAppListItem(AppListItem* item) { |
| 38 // Write synced data to local pref. |
| 39 AppListPrefs::AppListInfo info; |
| 40 if (item->GetItemType() == AppListFolderItem::kItemType) |
| 41 info.item_type = AppListPrefs::AppListInfo::FOLDER_ITEM; |
| 42 else if (item->GetItemType() == ExtensionAppItem::kItemType) |
| 43 info.item_type = AppListPrefs::AppListInfo::APP_ITEM; |
| 44 else |
| 45 NOTREACHED(); |
| 46 |
| 47 info.parent_id = item->folder_id(); |
| 48 info.position = item->position(); |
| 49 info.name = item->name(); |
| 50 |
| 51 app_list_prefs_->SetAppListInfo(item->id(), info); |
| 52 } |
| 53 |
| 54 } // namespace app_list |
OLD | NEW |