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.
5 #include "chrome/browser/ui/app_list/model_pref_updater.h"
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"
15 ModelPrefUpdater::ModelPrefUpdater(AppListPrefs
* app_list_prefs
,
17 : app_list_prefs_(app_list_prefs
), model_(model
) {
18 model_
->AddObserver(this);
21 ModelPrefUpdater::~ModelPrefUpdater() {
22 model_
->RemoveObserver(this);
25 void ModelPrefUpdater::OnAppListItemAdded(AppListItem
* item
) {
26 UpdatePrefsFromAppListItem(item
);
29 void ModelPrefUpdater::OnAppListItemWillBeDeleted(AppListItem
* item
) {
30 app_list_prefs_
->DeleteAppListInfo(item
->id());
33 void ModelPrefUpdater::OnAppListItemUpdated(AppListItem
* item
) {
34 UpdatePrefsFromAppListItem(item
);
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
;
47 info
.parent_id
= item
->folder_id();
48 info
.position
= item
->position();
49 info
.name
= item
->name();
51 app_list_prefs_
->SetAppListInfo(item
->id(), info
);
54 } // namespace app_list