Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ui/app_list/search/history_data_store.cc

Issue 1924743005: Move away from deprecated base::Value methods in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/search/dictionary_data_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "ui/app_list/search/history_data_store.h" 5 #include "ui/app_list/search/history_data_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 else 138 else
139 on_flushed.Run(); 139 on_flushed.Run();
140 } 140 }
141 141
142 void HistoryDataStore::Load( 142 void HistoryDataStore::Load(
143 const HistoryDataStore::OnLoadedCallback& on_loaded) { 143 const HistoryDataStore::OnLoadedCallback& on_loaded) {
144 if (data_store_.get()) { 144 if (data_store_.get()) {
145 data_store_->Load(base::Bind( 145 data_store_->Load(base::Bind(
146 &HistoryDataStore::OnDictionaryLoadedCallback, this, on_loaded)); 146 &HistoryDataStore::OnDictionaryLoadedCallback, this, on_loaded));
147 } else { 147 } else {
148 OnDictionaryLoadedCallback(on_loaded, 148 OnDictionaryLoadedCallback(on_loaded, cached_dict_->CreateDeepCopy());
149 base::WrapUnique(cached_dict_->DeepCopy()));
150 } 149 }
151 } 150 }
152 151
153 void HistoryDataStore::SetPrimary(const std::string& query, 152 void HistoryDataStore::SetPrimary(const std::string& query,
154 const std::string& result) { 153 const std::string& result) {
155 base::DictionaryValue* entry_dict = GetEntryDict(query); 154 base::DictionaryValue* entry_dict = GetEntryDict(query);
156 entry_dict->SetWithoutPathExpansion(kKeyPrimary, 155 entry_dict->SetStringWithoutPathExpansion(kKeyPrimary, result);
157 new base::StringValue(result));
158 if (data_store_.get()) 156 if (data_store_.get())
159 data_store_->ScheduleWrite(); 157 data_store_->ScheduleWrite();
160 } 158 }
161 159
162 void HistoryDataStore::SetSecondary( 160 void HistoryDataStore::SetSecondary(
163 const std::string& query, 161 const std::string& query,
164 const HistoryData::SecondaryDeque& results) { 162 const HistoryData::SecondaryDeque& results) {
165 std::unique_ptr<base::ListValue> results_list(new base::ListValue); 163 std::unique_ptr<base::ListValue> results_list(new base::ListValue);
166 for (size_t i = 0; i < results.size(); ++i) 164 for (size_t i = 0; i < results.size(); ++i)
167 results_list->AppendString(results[i]); 165 results_list->AppendString(results[i]);
168 166
169 base::DictionaryValue* entry_dict = GetEntryDict(query); 167 base::DictionaryValue* entry_dict = GetEntryDict(query);
170 entry_dict->SetWithoutPathExpansion(kKeySecondary, results_list.release()); 168 entry_dict->SetWithoutPathExpansion(kKeySecondary, results_list.release());
171 if (data_store_.get()) 169 if (data_store_.get())
172 data_store_->ScheduleWrite(); 170 data_store_->ScheduleWrite();
173 } 171 }
174 172
175 void HistoryDataStore::SetUpdateTime(const std::string& query, 173 void HistoryDataStore::SetUpdateTime(const std::string& query,
176 const base::Time& update_time) { 174 const base::Time& update_time) {
177 base::DictionaryValue* entry_dict = GetEntryDict(query); 175 base::DictionaryValue* entry_dict = GetEntryDict(query);
178 entry_dict->SetWithoutPathExpansion(kKeyUpdateTime, 176 entry_dict->SetStringWithoutPathExpansion(
179 new base::StringValue(base::Int64ToString( 177 kKeyUpdateTime, base::Int64ToString(update_time.ToInternalValue()));
180 update_time.ToInternalValue())));
181 if (data_store_.get()) 178 if (data_store_.get())
182 data_store_->ScheduleWrite(); 179 data_store_->ScheduleWrite();
183 } 180 }
184 181
185 void HistoryDataStore::Delete(const std::string& query) { 182 void HistoryDataStore::Delete(const std::string& query) {
186 base::DictionaryValue* assoc_dict = GetAssociationDict(); 183 base::DictionaryValue* assoc_dict = GetAssociationDict();
187 assoc_dict->RemoveWithoutPathExpansion(query, NULL); 184 assoc_dict->RemoveWithoutPathExpansion(query, NULL);
188 if (data_store_.get()) 185 if (data_store_.get())
189 data_store_->ScheduleWrite(); 186 data_store_->ScheduleWrite();
190 } 187 }
191 188
192 base::DictionaryValue* HistoryDataStore::GetAssociationDict() { 189 base::DictionaryValue* HistoryDataStore::GetAssociationDict() {
193 base::DictionaryValue* cached_dict = 190 base::DictionaryValue* cached_dict =
194 cached_dict_ ? cached_dict_.get() : data_store_->cached_dict(); 191 cached_dict_ ? cached_dict_.get() : data_store_->cached_dict();
195 DCHECK(cached_dict); 192 DCHECK(cached_dict);
196 193
197 base::DictionaryValue* assoc_dict = NULL; 194 base::DictionaryValue* assoc_dict = NULL;
198 CHECK(cached_dict->GetDictionary(kKeyAssociations, &assoc_dict) && 195 CHECK(cached_dict->GetDictionary(kKeyAssociations, &assoc_dict) &&
199 assoc_dict); 196 assoc_dict);
200 197
201 return assoc_dict; 198 return assoc_dict;
202 } 199 }
203 200
204 base::DictionaryValue* HistoryDataStore::GetEntryDict( 201 base::DictionaryValue* HistoryDataStore::GetEntryDict(
205 const std::string& query) { 202 const std::string& query) {
206 base::DictionaryValue* assoc_dict = GetAssociationDict(); 203 base::DictionaryValue* assoc_dict = GetAssociationDict();
207 204
208 base::DictionaryValue* entry_dict = NULL; 205 base::DictionaryValue* entry_dict = nullptr;
209 if (!assoc_dict->GetDictionaryWithoutPathExpansion(query, &entry_dict)) { 206 if (!assoc_dict->GetDictionaryWithoutPathExpansion(query, &entry_dict)) {
210 // Creates one if none exists. Ownership is taken in the set call after. 207 // Creates one if none exists. Ownership is taken in the set call after.
211 entry_dict = new base::DictionaryValue; 208 entry_dict = new base::DictionaryValue;
212 assoc_dict->SetWithoutPathExpansion(query, entry_dict); 209 assoc_dict->SetWithoutPathExpansion(query, base::WrapUnique(entry_dict));
213 } 210 }
214 211
215 return entry_dict; 212 return entry_dict;
216 } 213 }
217 214
218 void HistoryDataStore::OnDictionaryLoadedCallback( 215 void HistoryDataStore::OnDictionaryLoadedCallback(
219 OnLoadedCallback callback, 216 OnLoadedCallback callback,
220 std::unique_ptr<base::DictionaryValue> dict) { 217 std::unique_ptr<base::DictionaryValue> dict) {
221 if (!dict) { 218 if (!dict) {
222 callback.Run(nullptr); 219 callback.Run(nullptr);
223 } else { 220 } else {
224 callback.Run(Parse(std::move(dict))); 221 callback.Run(Parse(std::move(dict)));
225 } 222 }
226 } 223 }
227 224
228 } // namespace app_list 225 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search/dictionary_data_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698