Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/browser/ui/app_list/search/common/webservice_cache.h

Issue 1763273002: base: Remove OwningMRUCache in favor of scoped_ptrs in MRUCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + fix Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_ 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_ 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/containers/mru_cache.h" 10 #include "base/containers/mru_cache.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // mixing of the queries. 57 // mixing of the queries.
58 const CacheResult Get(QueryType type, const std::string& query); 58 const CacheResult Get(QueryType type, const std::string& query);
59 59
60 // Puts the new result to the query. 60 // Puts the new result to the query.
61 void Put(QueryType type, 61 void Put(QueryType type,
62 const std::string& query, 62 const std::string& query,
63 scoped_ptr<base::DictionaryValue> result); 63 scoped_ptr<base::DictionaryValue> result);
64 64
65 private: 65 private:
66 struct Payload { 66 struct Payload {
67 Payload(const base::Time& time, 67 Payload(const base::Time& time, scoped_ptr<base::DictionaryValue> result);
68 const base::DictionaryValue* result) 68 Payload();
69 : time(time), result(result) {} 69 ~Payload();
70 Payload() {} 70
71 Payload& operator=(Payload&& other);
71 72
72 base::Time time; 73 base::Time time;
73 const base::DictionaryValue* result; 74 scoped_ptr<base::DictionaryValue> result;
74 }; 75 };
75 76
76 class CacheDeletor { 77 using Cache = base::MRUCache<std::string, scoped_ptr<Payload>>;
77 public:
78 void operator()(const Payload& payload);
79 };
80 typedef base::
81 MRUCacheBase<std::string, Payload, std::less<std::string>, CacheDeletor>
82 Cache;
83 78
84 // Callback for when the cache is loaded from the dictionary data store. 79 // Callback for when the cache is loaded from the dictionary data store.
85 void OnCacheLoaded(scoped_ptr<base::DictionaryValue>); 80 void OnCacheLoaded(scoped_ptr<base::DictionaryValue>);
86 81
87 // Populates the payload parameter with the corresponding payload stored 82 // Populates the payload parameter with the corresponding payload stored
88 // in the given dictionary. If the dictionary is invalid for any reason, 83 // in the given dictionary. If the dictionary is invalid for any reason,
89 // this method will return false. 84 // this method will return false.
90 bool PayloadFromDict(const base::DictionaryValue* dict, 85 bool PayloadFromDict(const base::DictionaryValue* dict, Payload* payload);
91 Payload* payload);
92 86
93 // Returns a dictionary value for a given payload. The returned dictionary 87 // Returns a dictionary value for a given payload. The returned dictionary
94 // will be owned by the data_store_ cached_dict, and freed on the destruction 88 // will be owned by the data_store_ cached_dict, and freed on the destruction
95 // of our dictionary datastore. 89 // of our dictionary datastore.
96 base::DictionaryValue* DictFromPayload(const Payload& payload); 90 base::DictionaryValue* DictFromPayload(const Payload& payload);
97 91
98 // Trims our MRU cache, making sure that any element that is removed is also 92 // Trims our MRU cache, making sure that any element that is removed is also
99 // removed from the dictionary data store. 93 // removed from the dictionary data store.
100 void TrimCache(); 94 void TrimCache();
101 95
102 // Prepends a type string to the given query and returns a new query string. 96 // Prepends a type string to the given query and returns a new query string.
103 std::string PrependType(QueryType type, const std::string& query); 97 std::string PrependType(QueryType type, const std::string& query);
104 98
105 Cache cache_; 99 Cache cache_;
106 scoped_refptr<DictionaryDataStore> data_store_; 100 scoped_refptr<DictionaryDataStore> data_store_;
107 101
108 bool cache_loaded_; 102 bool cache_loaded_;
109 103
110 DISALLOW_COPY_AND_ASSIGN(WebserviceCache); 104 DISALLOW_COPY_AND_ASSIGN(WebserviceCache);
111 }; 105 };
112 106
113 } // namespace app_list 107 } // namespace app_list
114 108
115 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_ 109 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698