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

Side by Side Diff: chrome/browser/ui/app_list/search/common/webservice_cache.cc

Issue 2812953002: Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: No ListValue::SetDouble Created 3 years, 8 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
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 "chrome/browser/ui/app_list/search/common/webservice_cache.h" 5 #include "chrome/browser/ui/app_list/search/common/webservice_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::StringToInt64(time_string, &time_val); 121 base::StringToInt64(time_string, &time_val);
122 122
123 // The result dictionary will be owned by the cache, hence create a copy 123 // The result dictionary will be owned by the cache, hence create a copy
124 // instead of returning the original reference. The new dictionary will be 124 // instead of returning the original reference. The new dictionary will be
125 // owned by our MRU cache. 125 // owned by our MRU cache.
126 *payload = Payload(base::Time::FromInternalValue(time_val), 126 *payload = Payload(base::Time::FromInternalValue(time_val),
127 base::WrapUnique(result->DeepCopy())); 127 base::WrapUnique(result->DeepCopy()));
128 return true; 128 return true;
129 } 129 }
130 130
131 base::DictionaryValue* WebserviceCache::DictFromPayload( 131 std::unique_ptr<base::DictionaryValue> WebserviceCache::DictFromPayload(
132 const Payload& payload) { 132 const Payload& payload) {
133 base::DictionaryValue* dict = new base::DictionaryValue(); 133 auto dict = base::MakeUnique<base::DictionaryValue>();
134 dict->SetString(kKeyResultTime, base::Int64ToString( 134 dict->SetString(kKeyResultTime, base::Int64ToString(
135 payload.time.ToInternalValue())); 135 payload.time.ToInternalValue()));
136 // The payload will still keep ownership of it's result dict, hence put a 136 // The payload will still keep ownership of it's result dict, hence put a
137 // a copy of the result dictionary here. This dictionary will be owned by 137 // a copy of the result dictionary here. This dictionary will be owned by
138 // data_store_->cached_dict(). 138 // data_store_->cached_dict().
139 dict->Set(kKeyResult, payload.result->DeepCopy()); 139 dict->Set(kKeyResult, base::MakeUnique<base::Value>(*payload.result));
140 140
141 return dict; 141 return dict;
142 } 142 }
143 143
144 void WebserviceCache::TrimCache() { 144 void WebserviceCache::TrimCache() {
145 for (Cache::size_type i = cache_.size(); i > kWebserviceCacheMaxSize; i--) { 145 for (Cache::size_type i = cache_.size(); i > kWebserviceCacheMaxSize; i--) {
146 Cache::reverse_iterator rbegin = cache_.rbegin(); 146 Cache::reverse_iterator rbegin = cache_.rbegin();
147 data_store_->cached_dict()->Remove(rbegin->first, NULL); 147 data_store_->cached_dict()->Remove(rbegin->first, NULL);
148 cache_.Erase(rbegin); 148 cache_.Erase(rbegin);
149 } 149 }
(...skipping 20 matching lines...) Expand all
170 170
171 WebserviceCache::Payload::~Payload() = default; 171 WebserviceCache::Payload::~Payload() = default;
172 172
173 WebserviceCache::Payload& WebserviceCache::Payload::operator=(Payload&& other) { 173 WebserviceCache::Payload& WebserviceCache::Payload::operator=(Payload&& other) {
174 time = std::move(other.time); 174 time = std::move(other.time);
175 result = std::move(other.result); 175 result = std::move(other.result);
176 return *this; 176 return *this;
177 } 177 }
178 178
179 } // namespace app_list 179 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/common/webservice_cache.h ('k') | chrome/browser/ui/ash/chrome_launcher_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698