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

Side by Side Diff: components/dom_distiller/core/distilled_content_store.cc

Issue 302163005: Change InMemoryContentStore to use MRUCache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated tests for expiry and fixed lint errors. Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/dom_distiller/core/distilled_content_store.h" 5 #include "components/dom_distiller/core/distilled_content_store.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 8
9 namespace dom_distiller { 9 namespace dom_distiller {
10 10
11 InMemoryContentStore::InMemoryContentStore() {} 11 InMemoryContentStore::InMemoryContentStore(const int max_num_entries)
12 InMemoryContentStore::~InMemoryContentStore() {} 12 : cache_(max_num_entries) {
13 }
14
15 InMemoryContentStore::~InMemoryContentStore() {
16 }
13 17
14 void InMemoryContentStore::SaveContent( 18 void InMemoryContentStore::SaveContent(
15 const ArticleEntry& entry, 19 const ArticleEntry& entry,
16 const DistilledArticleProto& proto, 20 const DistilledArticleProto& proto,
17 InMemoryContentStore::SaveCallback callback) { 21 InMemoryContentStore::SaveCallback callback) {
18 InjectContent(entry, proto); 22 InjectContent(entry, proto);
19 if (!callback.is_null()) { 23 if (!callback.is_null()) {
20 base::MessageLoop::current()->PostTask(FROM_HERE, 24 base::MessageLoop::current()->PostTask(FROM_HERE,
21 base::Bind(callback, true)); 25 base::Bind(callback, true));
22 } 26 }
23 } 27 }
24 28
25 void InMemoryContentStore::LoadContent( 29 void InMemoryContentStore::LoadContent(
26 const ArticleEntry& entry, 30 const ArticleEntry& entry,
27 InMemoryContentStore::LoadCallback callback) const { 31 InMemoryContentStore::LoadCallback callback) {
28 if (callback.is_null()) 32 if (callback.is_null())
29 return; 33 return;
30 34
31 ContentMap::const_iterator it = cache_.find(entry.entry_id()); 35 ContentMap::const_iterator it = cache_.Get(entry.entry_id());
32 bool success = it != cache_.end(); 36 bool success = it != cache_.end();
33 scoped_ptr<DistilledArticleProto> distilled_article; 37 scoped_ptr<DistilledArticleProto> distilled_article;
34 if (success) { 38 if (success) {
35 distilled_article.reset(new DistilledArticleProto(it->second)); 39 distilled_article.reset(new DistilledArticleProto(it->second));
36 } else { 40 } else {
37 distilled_article.reset(new DistilledArticleProto()); 41 distilled_article.reset(new DistilledArticleProto());
38 } 42 }
39 base::MessageLoop::current()->PostTask( 43 base::MessageLoop::current()->PostTask(
40 FROM_HERE, 44 FROM_HERE,
41 base::Bind(callback, success, base::Passed(&distilled_article))); 45 base::Bind(callback, success, base::Passed(&distilled_article)));
42 } 46 }
43 47
44 void InMemoryContentStore::InjectContent(const ArticleEntry& entry, 48 void InMemoryContentStore::InjectContent(const ArticleEntry& entry,
45 const DistilledArticleProto& proto) { 49 const DistilledArticleProto& proto) {
46 cache_[entry.entry_id()] = proto; 50 cache_.Put(entry.entry_id(), proto);
47 } 51 }
48 52
49 } // namespace dom_distiller 53 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698