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.
5 #include "chrome/browser/ui/app_list/search/webstore_cache.h"
7 #include "base/values.h"
12 const int kWebstoreCacheMaxSize
= 100;
13 const int kWebstoreCacheTimeLimitInMinutes
= 1;
17 void WebstoreCache::CacheDeletor::operator()(WebstoreCache::Payload
& payload
) {
18 delete payload
.second
;
21 WebstoreCache::WebstoreCache()
22 : cache_(kWebstoreCacheMaxSize
) {
25 WebstoreCache::~WebstoreCache() {
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
;
41 void WebstoreCache::Put(const std::string
& query
,
42 scoped_ptr
<base::DictionaryValue
> result
) {
44 cache_
.Put(query
, std::make_pair(base::Time::Now(), result
.release()));
47 } // namespace app_list