Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / search / webstore_cache.cc
blobbe130e4c7b86a03668079459b75dd207aa36f56b
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"
9 namespace app_list {
10 namespace {
12 const int kWebstoreCacheMaxSize = 100;
13 const int kWebstoreCacheTimeLimitInMinutes = 1;
15 } // namespace
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;
34 } else {
35 cache_.Erase(iter);
38 return NULL;
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()));
47 } // namespace app_list