OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "base/prefs/scoped_user_pref_update.h" | 6 #include "base/prefs/scoped_user_pref_update.h" |
7 #include "chrome/browser/ui/app_list/app_list_prefs.h" | 7 #include "chrome/browser/ui/app_list/app_list_prefs.h" |
8 #include "chrome/browser/ui/app_list/app_list_prefs_factory.h" | 8 #include "chrome/browser/ui/app_list/app_list_prefs_factory.h" |
9 #include "components/pref_registry/pref_registry_syncable.h" | 9 #include "components/pref_registry/pref_registry_syncable.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 AppListPrefs::AppListInfo::~AppListInfo() { | 30 AppListPrefs::AppListInfo::~AppListInfo() { |
31 } | 31 } |
32 | 32 |
33 scoped_ptr<base::DictionaryValue> | 33 scoped_ptr<base::DictionaryValue> |
34 AppListPrefs::AppListInfo::CreateDictFromAppListInfo() const { | 34 AppListPrefs::AppListInfo::CreateDictFromAppListInfo() const { |
35 scoped_ptr<base::DictionaryValue> item_dict(new base::DictionaryValue()); | 35 scoped_ptr<base::DictionaryValue> item_dict(new base::DictionaryValue()); |
36 item_dict->SetString(kModelItemPosition, position.ToInternalValue()); | 36 item_dict->SetString(kModelItemPosition, position.ToInternalValue()); |
37 item_dict->SetString(kModelItemParentId, parent_id); | 37 item_dict->SetString(kModelItemParentId, parent_id); |
38 item_dict->SetString(kModelItemName, name); | 38 item_dict->SetString(kModelItemName, name); |
39 item_dict->SetInteger(kModelItemType, item_type); | 39 item_dict->SetInteger(kModelItemType, item_type); |
40 return item_dict.Pass(); | 40 return item_dict; |
41 } | 41 } |
42 | 42 |
43 // static | 43 // static |
44 scoped_ptr<AppListPrefs::AppListInfo> | 44 scoped_ptr<AppListPrefs::AppListInfo> |
45 AppListPrefs::AppListInfo::CreateAppListInfoFromDict( | 45 AppListPrefs::AppListInfo::CreateAppListInfoFromDict( |
46 const base::DictionaryValue* item_dict) { | 46 const base::DictionaryValue* item_dict) { |
47 std::string item_ordinal_string; | 47 std::string item_ordinal_string; |
48 scoped_ptr<AppListInfo> info(new AppListPrefs::AppListInfo()); | 48 scoped_ptr<AppListInfo> info(new AppListPrefs::AppListInfo()); |
49 int item_type_int = -1; | 49 int item_type_int = -1; |
50 if (!item_dict || | 50 if (!item_dict || |
51 !item_dict->GetString(kModelItemPosition, &item_ordinal_string) || | 51 !item_dict->GetString(kModelItemPosition, &item_ordinal_string) || |
52 !item_dict->GetString(kModelItemParentId, &info->parent_id) || | 52 !item_dict->GetString(kModelItemParentId, &info->parent_id) || |
53 !item_dict->GetString(kModelItemName, &info->name) || | 53 !item_dict->GetString(kModelItemName, &info->name) || |
54 !item_dict->GetInteger(kModelItemType, &item_type_int) || | 54 !item_dict->GetInteger(kModelItemType, &item_type_int) || |
55 item_type_int < ITEM_TYPE_BEGIN || item_type_int > ITEM_TYPE_END) { | 55 item_type_int < ITEM_TYPE_BEGIN || item_type_int > ITEM_TYPE_END) { |
56 return scoped_ptr<AppListInfo>(); | 56 return scoped_ptr<AppListInfo>(); |
57 } | 57 } |
58 | 58 |
59 info->position = syncer::StringOrdinal(item_ordinal_string); | 59 info->position = syncer::StringOrdinal(item_ordinal_string); |
60 info->item_type = static_cast<ItemType>(item_type_int); | 60 info->item_type = static_cast<ItemType>(item_type_int); |
61 return info.Pass(); | 61 return info; |
62 } | 62 } |
63 | 63 |
64 // AppListPrefs | 64 // AppListPrefs |
65 | 65 |
66 AppListPrefs::AppListPrefs(PrefService* pref_service) | 66 AppListPrefs::AppListPrefs(PrefService* pref_service) |
67 : pref_service_(pref_service) { | 67 : pref_service_(pref_service) { |
68 } | 68 } |
69 | 69 |
70 AppListPrefs::~AppListPrefs() { | 70 AppListPrefs::~AppListPrefs() { |
71 } | 71 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 (*out)[it.key()] = *AppListInfo::CreateAppListInfoFromDict(item_dict); | 118 (*out)[it.key()] = *AppListInfo::CreateAppListInfoFromDict(item_dict); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void AppListPrefs::DeleteAppListInfo(const std::string& id) { | 122 void AppListPrefs::DeleteAppListInfo(const std::string& id) { |
123 DictionaryPrefUpdate model_dict(pref_service_, kPrefModel); | 123 DictionaryPrefUpdate model_dict(pref_service_, kPrefModel); |
124 model_dict->Remove(id, NULL); | 124 model_dict->Remove(id, NULL); |
125 } | 125 } |
126 | 126 |
127 } // namespace app_list | 127 } // namespace app_list |
OLD | NEW |