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 "chrome/browser/ui/app_list/app_list_prefs.h" | 5 #include "chrome/browser/ui/app_list/app_list_prefs.h" |
6 #include "chrome/browser/ui/app_list/app_list_prefs_factory.h" | 6 #include "chrome/browser/ui/app_list/app_list_prefs_factory.h" |
7 #include "components/pref_registry/pref_registry_syncable.h" | 7 #include "components/pref_registry/pref_registry_syncable.h" |
8 #include "components/prefs/pref_service.h" | 8 #include "components/prefs/pref_service.h" |
9 #include "components/prefs/scoped_user_pref_update.h" | 9 #include "components/prefs/scoped_user_pref_update.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 // AppListInfo | 25 // AppListInfo |
26 | 26 |
27 AppListPrefs::AppListInfo::AppListInfo() : item_type(ITEM_TYPE_INVALID) { | 27 AppListPrefs::AppListInfo::AppListInfo() : item_type(ITEM_TYPE_INVALID) { |
28 } | 28 } |
29 | 29 |
30 AppListPrefs::AppListInfo::AppListInfo(const AppListInfo& other) = default; | 30 AppListPrefs::AppListInfo::AppListInfo(const AppListInfo& other) = default; |
31 | 31 |
32 AppListPrefs::AppListInfo::~AppListInfo() { | 32 AppListPrefs::AppListInfo::~AppListInfo() { |
33 } | 33 } |
34 | 34 |
35 scoped_ptr<base::DictionaryValue> | 35 std::unique_ptr<base::DictionaryValue> |
36 AppListPrefs::AppListInfo::CreateDictFromAppListInfo() const { | 36 AppListPrefs::AppListInfo::CreateDictFromAppListInfo() const { |
37 scoped_ptr<base::DictionaryValue> item_dict(new base::DictionaryValue()); | 37 std::unique_ptr<base::DictionaryValue> item_dict(new base::DictionaryValue()); |
38 item_dict->SetString(kModelItemPosition, position.ToInternalValue()); | 38 item_dict->SetString(kModelItemPosition, position.ToInternalValue()); |
39 item_dict->SetString(kModelItemParentId, parent_id); | 39 item_dict->SetString(kModelItemParentId, parent_id); |
40 item_dict->SetString(kModelItemName, name); | 40 item_dict->SetString(kModelItemName, name); |
41 item_dict->SetInteger(kModelItemType, item_type); | 41 item_dict->SetInteger(kModelItemType, item_type); |
42 return item_dict; | 42 return item_dict; |
43 } | 43 } |
44 | 44 |
45 // static | 45 // static |
46 scoped_ptr<AppListPrefs::AppListInfo> | 46 std::unique_ptr<AppListPrefs::AppListInfo> |
47 AppListPrefs::AppListInfo::CreateAppListInfoFromDict( | 47 AppListPrefs::AppListInfo::CreateAppListInfoFromDict( |
48 const base::DictionaryValue* item_dict) { | 48 const base::DictionaryValue* item_dict) { |
49 std::string item_ordinal_string; | 49 std::string item_ordinal_string; |
50 scoped_ptr<AppListInfo> info(new AppListPrefs::AppListInfo()); | 50 std::unique_ptr<AppListInfo> info(new AppListPrefs::AppListInfo()); |
51 int item_type_int = -1; | 51 int item_type_int = -1; |
52 if (!item_dict || | 52 if (!item_dict || |
53 !item_dict->GetString(kModelItemPosition, &item_ordinal_string) || | 53 !item_dict->GetString(kModelItemPosition, &item_ordinal_string) || |
54 !item_dict->GetString(kModelItemParentId, &info->parent_id) || | 54 !item_dict->GetString(kModelItemParentId, &info->parent_id) || |
55 !item_dict->GetString(kModelItemName, &info->name) || | 55 !item_dict->GetString(kModelItemName, &info->name) || |
56 !item_dict->GetInteger(kModelItemType, &item_type_int) || | 56 !item_dict->GetInteger(kModelItemType, &item_type_int) || |
57 item_type_int < ITEM_TYPE_BEGIN || item_type_int > ITEM_TYPE_END) { | 57 item_type_int < ITEM_TYPE_BEGIN || item_type_int > ITEM_TYPE_END) { |
58 return scoped_ptr<AppListInfo>(); | 58 return std::unique_ptr<AppListInfo>(); |
59 } | 59 } |
60 | 60 |
61 info->position = syncer::StringOrdinal(item_ordinal_string); | 61 info->position = syncer::StringOrdinal(item_ordinal_string); |
62 info->item_type = static_cast<ItemType>(item_type_int); | 62 info->item_type = static_cast<ItemType>(item_type_int); |
63 return info; | 63 return info; |
64 } | 64 } |
65 | 65 |
66 // AppListPrefs | 66 // AppListPrefs |
67 | 67 |
68 AppListPrefs::AppListPrefs(PrefService* pref_service) | 68 AppListPrefs::AppListPrefs(PrefService* pref_service) |
(...skipping 18 matching lines...) Expand all Loading... |
87 AppListPrefs* AppListPrefs::Get(content::BrowserContext* context) { | 87 AppListPrefs* AppListPrefs::Get(content::BrowserContext* context) { |
88 return AppListPrefsFactory::GetInstance()->GetForBrowserContext(context); | 88 return AppListPrefsFactory::GetInstance()->GetForBrowserContext(context); |
89 } | 89 } |
90 | 90 |
91 void AppListPrefs::SetAppListInfo(const std::string& id, | 91 void AppListPrefs::SetAppListInfo(const std::string& id, |
92 const AppListInfo& info) { | 92 const AppListInfo& info) { |
93 DictionaryPrefUpdate update(pref_service_, kPrefModel); | 93 DictionaryPrefUpdate update(pref_service_, kPrefModel); |
94 update->Set(id, info.CreateDictFromAppListInfo().release()); | 94 update->Set(id, info.CreateDictFromAppListInfo().release()); |
95 } | 95 } |
96 | 96 |
97 scoped_ptr<AppListPrefs::AppListInfo> AppListPrefs::GetAppListInfo( | 97 std::unique_ptr<AppListPrefs::AppListInfo> AppListPrefs::GetAppListInfo( |
98 const std::string& id) const { | 98 const std::string& id) const { |
99 const base::DictionaryValue* model_dict = | 99 const base::DictionaryValue* model_dict = |
100 pref_service_->GetDictionary(kPrefModel); | 100 pref_service_->GetDictionary(kPrefModel); |
101 DCHECK(model_dict); | 101 DCHECK(model_dict); |
102 const base::DictionaryValue* item_dict = NULL; | 102 const base::DictionaryValue* item_dict = NULL; |
103 if (!model_dict->GetDictionary(id, &item_dict)) | 103 if (!model_dict->GetDictionary(id, &item_dict)) |
104 return scoped_ptr<AppListInfo>(); | 104 return std::unique_ptr<AppListInfo>(); |
105 | 105 |
106 return AppListInfo::CreateAppListInfoFromDict(item_dict); | 106 return AppListInfo::CreateAppListInfoFromDict(item_dict); |
107 } | 107 } |
108 | 108 |
109 void AppListPrefs::GetAllAppListInfos(AppListInfoMap* out) const { | 109 void AppListPrefs::GetAllAppListInfos(AppListInfoMap* out) const { |
110 out->clear(); | 110 out->clear(); |
111 const base::DictionaryValue* model_dict = | 111 const base::DictionaryValue* model_dict = |
112 pref_service_->GetDictionary(kPrefModel); | 112 pref_service_->GetDictionary(kPrefModel); |
113 DCHECK(model_dict); | 113 DCHECK(model_dict); |
114 | 114 |
115 for (base::DictionaryValue::Iterator it(*model_dict); !it.IsAtEnd(); | 115 for (base::DictionaryValue::Iterator it(*model_dict); !it.IsAtEnd(); |
116 it.Advance()) { | 116 it.Advance()) { |
117 const base::DictionaryValue* item_dict = NULL; | 117 const base::DictionaryValue* item_dict = NULL; |
118 it.value().GetAsDictionary(&item_dict); | 118 it.value().GetAsDictionary(&item_dict); |
119 DCHECK(item_dict); | 119 DCHECK(item_dict); |
120 (*out)[it.key()] = *AppListInfo::CreateAppListInfoFromDict(item_dict); | 120 (*out)[it.key()] = *AppListInfo::CreateAppListInfoFromDict(item_dict); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void AppListPrefs::DeleteAppListInfo(const std::string& id) { | 124 void AppListPrefs::DeleteAppListInfo(const std::string& id) { |
125 DictionaryPrefUpdate model_dict(pref_service_, kPrefModel); | 125 DictionaryPrefUpdate model_dict(pref_service_, kPrefModel); |
126 model_dict->Remove(id, NULL); | 126 model_dict->Remove(id, NULL); |
127 } | 127 } |
128 | 128 |
129 } // namespace app_list | 129 } // namespace app_list |
OLD | NEW |