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 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_CACHE_H_ | |
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_CACHE_H_ | |
7 | |
8 #include <utility> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/containers/mru_cache.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/time/time.h" | |
14 | |
15 namespace base { | |
16 class DictionaryValue; | |
17 } | |
18 | |
19 namespace app_list { | |
20 | |
21 // WebstoreCache manages the cache of webstore search results which should | |
22 // be valid during an input session. This will reduce unnecessary queries | |
23 // for typing backspace or so on. | |
24 class WebstoreCache { | |
25 public: | |
26 WebstoreCache(); | |
27 ~WebstoreCache(); | |
28 | |
29 // Checks the current cache and returns the value for the |query| if it's | |
30 // valid. Otherwise returns NULL. | |
31 const base::DictionaryValue* Get(const std::string& query); | |
32 | |
33 // Puts the new result to the query. | |
34 void Put(const std::string& query, scoped_ptr<base::DictionaryValue> result); | |
35 | |
36 private: | |
37 typedef std::pair<base::Time, base::DictionaryValue*> Payload; | |
38 class CacheDeletor { | |
39 public: | |
40 void operator()(Payload& payload); | |
41 }; | |
42 typedef base::MRUCacheBase<std::string, Payload, CacheDeletor> Cache; | |
43 | |
44 Cache cache_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(WebstoreCache); | |
47 }; | |
48 | |
49 } // namespace app_list | |
50 | |
51 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_CACHE_H_ | |
OLD | NEW |