| Index: chrome/browser/ui/app_list/search/common/webservice_cache.cc
|
| diff --git a/chrome/browser/ui/app_list/search/common/webservice_cache.cc b/chrome/browser/ui/app_list/search/common/webservice_cache.cc
|
| index 8fa41cad55ff6c3623698ad76363bbc1453b0f2f..d1c745a420178d693c26a7fda7ffd8d5cb16c167 100644
|
| --- a/chrome/browser/ui/app_list/search/common/webservice_cache.cc
|
| +++ b/chrome/browser/ui/app_list/search/common/webservice_cache.cc
|
| @@ -26,10 +26,6 @@ const char kPeopleQueryPrefix[] = "people:";
|
|
|
| } // namespace
|
|
|
| -void WebserviceCache::CacheDeletor::operator()(const Payload& payload) {
|
| - delete payload.result;
|
| -}
|
| -
|
| WebserviceCache::WebserviceCache(content::BrowserContext* context)
|
| : cache_(Cache::NO_AUTO_EVICT),
|
| cache_loaded_(false) {
|
| @@ -49,11 +45,11 @@ const CacheResult WebserviceCache::Get(QueryType type,
|
| std::string typed_query = PrependType(type, query);
|
| Cache::iterator iter = cache_.Get(typed_query);
|
| if (iter != cache_.end()) {
|
| - if (base::Time::Now() - iter->second.time <=
|
| + if (base::Time::Now() - iter->second->time <=
|
| base::TimeDelta::FromMinutes(kWebserviceCacheTimeLimitInMinutes)) {
|
| - return std::make_pair(FRESH, iter->second.result);
|
| + return std::make_pair(FRESH, iter->second->result.get());
|
| } else {
|
| - return std::make_pair(STALE, iter->second.result);
|
| + return std::make_pair(STALE, iter->second->result.get());
|
| }
|
| }
|
| return std::make_pair(STALE, static_cast<base::DictionaryValue*>(NULL));
|
| @@ -64,15 +60,17 @@ void WebserviceCache::Put(QueryType type,
|
| scoped_ptr<base::DictionaryValue> result) {
|
| if (result) {
|
| std::string typed_query = PrependType(type, query);
|
| - Payload payload(base::Time::Now(), result.release());
|
| + scoped_ptr<Payload> scoped_payload(
|
| + new Payload(base::Time::Now(), std::move(result)));
|
| + Payload* payload = scoped_payload.get();
|
|
|
| - cache_.Put(typed_query, payload);
|
| + cache_.Put(typed_query, std::move(scoped_payload));
|
| // If the cache isn't loaded yet, we're fine with losing queries since
|
| // a 1000 entry cache should load really quickly so the chance of a user
|
| // already having typed a 3 character search before the cache has loaded is
|
| // very unlikely.
|
| if (cache_loaded_) {
|
| - data_store_->cached_dict()->Set(typed_query, DictFromPayload(payload));
|
| + data_store_->cached_dict()->Set(typed_query, DictFromPayload(*payload));
|
| data_store_->ScheduleWrite();
|
| if (cache_.size() > kWebserviceCacheMaxSize)
|
| TrimCache();
|
| @@ -89,16 +87,16 @@ void WebserviceCache::OnCacheLoaded(scoped_ptr<base::DictionaryValue>) {
|
| !it.IsAtEnd();
|
| it.Advance()) {
|
| const base::DictionaryValue* payload_dict;
|
| - Payload payload;
|
| + scoped_ptr<Payload> payload(new Payload);
|
| if (!it.value().GetAsDictionary(&payload_dict) ||
|
| !payload_dict ||
|
| - !PayloadFromDict(payload_dict, &payload)) {
|
| + !PayloadFromDict(payload_dict, payload.get())) {
|
| // In case we don't have a valid payload associated with a given query,
|
| // clean up that query from our data store.
|
| cleanup_keys.push_back(it.key());
|
| continue;
|
| }
|
| - cache_.Put(it.key(), payload);
|
| + cache_.Put(it.key(), std::move(payload));
|
| }
|
|
|
| if (!cleanup_keys.empty()) {
|
| @@ -125,7 +123,7 @@ bool WebserviceCache::PayloadFromDict(const base::DictionaryValue* dict,
|
| // instead of returning the original reference. The new dictionary will be
|
| // owned by our MRU cache.
|
| *payload = Payload(base::Time::FromInternalValue(time_val),
|
| - result->DeepCopy());
|
| + make_scoped_ptr(result->DeepCopy()));
|
| return true;
|
| }
|
|
|
| @@ -163,4 +161,18 @@ std::string WebserviceCache::PrependType(
|
| }
|
| }
|
|
|
| +WebserviceCache::Payload::Payload(const base::Time& time,
|
| + scoped_ptr<base::DictionaryValue> result)
|
| + : time(time), result(std::move(result)) {}
|
| +
|
| +WebserviceCache::Payload::Payload() = default;
|
| +
|
| +WebserviceCache::Payload::~Payload() = default;
|
| +
|
| +WebserviceCache::Payload& WebserviceCache::Payload::operator=(Payload&& other) {
|
| + time = std::move(other.time);
|
| + result = std::move(other.result);
|
| + return *this;
|
| +}
|
| +
|
| } // namespace app_list
|
|
|