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

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

Issue 189833002: Add a DistilledContentStore (and an in-memory impl) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/dom_distiller/core/distilled_content_store.h"
6
7 #include "base/message_loop/message_loop.h"
8
9 namespace dom_distiller {
10
11 InMemoryContentStore::InMemoryContentStore() {}
12 InMemoryContentStore::~InMemoryContentStore() {}
13
14 void InMemoryContentStore::SaveContent(
15 const ArticleEntry& entry,
16 const DistilledArticleProto& proto,
17 InMemoryContentStore::SaveCallback callback) {
18 InjectContent(entry, proto);
19 if (!callback.is_null()) {
20 base::MessageLoop::current()->PostTask(FROM_HERE,
21 base::Bind(callback, true));
22 }
23 }
24
25 void InMemoryContentStore::LoadContent(
26 const ArticleEntry& entry,
27 InMemoryContentStore::LoadCallback callback) {
28 if (callback.is_null())
29 return;
30
31 ContentMap::iterator it = cache_.find(entry.entry_id());
shashi 2014/03/18 21:14:57 nit: const_iterator?
cjhopman 2014/04/11 22:37:21 Done.
32 bool success = it != cache_.end();
33 scoped_ptr<DistilledArticleProto> distilled_article;
34 if (success) {
35 distilled_article.reset(new DistilledArticleProto(it->second));
36 } else {
37 distilled_article.reset(new DistilledArticleProto());
38 }
39 base::MessageLoop::current()->PostTask(
40 FROM_HERE,
41 base::Bind(callback, success, base::Passed(&distilled_article)));
42 }
43
44 void InMemoryContentStore::InjectContent(const ArticleEntry& entry,
45 const DistilledArticleProto& proto) {
46 cache_[entry.entry_id()] = proto;
47 }
48
49 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698