| 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 "build/build_config.h" | |
| 8 #include "chrome/browser/ui/app_list/app_list_prefs.h" | |
| 9 #include "chrome/browser/ui/app_list/extension_app_item.h" | |
| 10 #include "ui/app_list/app_list_folder_item.h" | |
| 11 #include "ui/app_list/app_list_item.h" | |
| 12 #include "ui/app_list/app_list_model.h" | |
| 13 | |
| 14 #if defined(OS_CHROMEOS) | |
| 15 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace app_list { | |
| 19 | |
| 20 ModelPrefUpdater::ModelPrefUpdater(AppListPrefs* app_list_prefs, | |
| 21 AppListModel* model) | |
| 22 : app_list_prefs_(app_list_prefs), model_(model) { | |
| 23 model_->AddObserver(this); | |
| 24 } | |
| 25 | |
| 26 ModelPrefUpdater::~ModelPrefUpdater() { | |
| 27 model_->RemoveObserver(this); | |
| 28 } | |
| 29 | |
| 30 void ModelPrefUpdater::OnAppListItemAdded(AppListItem* item) { | |
| 31 UpdatePrefsFromAppListItem(item); | |
| 32 } | |
| 33 | |
| 34 void ModelPrefUpdater::OnAppListItemWillBeDeleted(AppListItem* item) { | |
| 35 app_list_prefs_->DeleteAppListInfo(item->id()); | |
| 36 } | |
| 37 | |
| 38 void ModelPrefUpdater::OnAppListItemUpdated(AppListItem* item) { | |
| 39 UpdatePrefsFromAppListItem(item); | |
| 40 } | |
| 41 | |
| 42 void ModelPrefUpdater::UpdatePrefsFromAppListItem(AppListItem* item) { | |
| 43 // Write synced data to local pref. | |
| 44 AppListPrefs::AppListInfo info; | |
| 45 if (item->GetItemType() == AppListFolderItem::kItemType) | |
| 46 info.item_type = AppListPrefs::AppListInfo::FOLDER_ITEM; | |
| 47 else if (item->GetItemType() == ExtensionAppItem::kItemType) | |
| 48 info.item_type = AppListPrefs::AppListInfo::APP_ITEM; | |
| 49 #if defined(OS_CHROMEOS) | |
| 50 else if (item->GetItemType() == ArcAppItem::kItemType) | |
| 51 info.item_type = AppListPrefs::AppListInfo::APP_ITEM; | |
| 52 #endif | |
| 53 else | |
| 54 NOTREACHED(); | |
| 55 | |
| 56 info.parent_id = item->folder_id(); | |
| 57 info.position = item->position(); | |
| 58 info.name = item->name(); | |
| 59 | |
| 60 app_list_prefs_->SetAppListInfo(item->id(), info); | |
| 61 } | |
| 62 | |
| 63 } // namespace app_list | |
| OLD | NEW |