| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #include "chrome/browser/ui/app_list/search/webstore_cache.h" |  | 
| 6 |  | 
| 7 #include "base/values.h" |  | 
| 8 |  | 
| 9 namespace app_list { |  | 
| 10 namespace { |  | 
| 11 |  | 
| 12 const int kWebstoreCacheMaxSize = 100; |  | 
| 13 const int kWebstoreCacheTimeLimitInMinutes = 1; |  | 
| 14 |  | 
| 15 }  // namespace |  | 
| 16 |  | 
| 17 void WebstoreCache::CacheDeletor::operator()(WebstoreCache::Payload& payload) { |  | 
| 18   delete payload.second; |  | 
| 19 } |  | 
| 20 |  | 
| 21 WebstoreCache::WebstoreCache() |  | 
| 22     : cache_(kWebstoreCacheMaxSize) { |  | 
| 23 } |  | 
| 24 |  | 
| 25 WebstoreCache::~WebstoreCache() { |  | 
| 26 } |  | 
| 27 |  | 
| 28 const base::DictionaryValue* WebstoreCache::Get(const std::string& query) { |  | 
| 29   Cache::iterator iter = cache_.Get(query); |  | 
| 30   if (iter != cache_.end()) { |  | 
| 31     if (base::Time::Now() - iter->second.first <= |  | 
| 32         base::TimeDelta::FromMinutes(kWebstoreCacheTimeLimitInMinutes)) { |  | 
| 33       return iter->second.second; |  | 
| 34     } else { |  | 
| 35       cache_.Erase(iter); |  | 
| 36     } |  | 
| 37   } |  | 
| 38   return NULL; |  | 
| 39 } |  | 
| 40 |  | 
| 41 void WebstoreCache::Put(const std::string& query, |  | 
| 42                         scoped_ptr<base::DictionaryValue> result) { |  | 
| 43   if (result) |  | 
| 44     cache_.Put(query, std::make_pair(base::Time::Now(), result.release())); |  | 
| 45 } |  | 
| 46 |  | 
| 47 }  // namespace app_list |  | 
| OLD | NEW | 
|---|