OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
shashi
2014/03/13 00:32:45
s/2013/2014
cjhopman
2014/03/18 16:06:10
Done.
| |
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 ContentMap::iterator it = cache_.find(entry.entry_id()); | |
29 | |
30 if (callback.is_null()) | |
shashi
2014/03/13 00:32:45
This null check should be before the lookup.
cjhopman
2014/03/18 16:06:10
Done.
| |
31 return; | |
32 | |
33 bool success = it != cache_.end(); | |
34 scoped_ptr<DistilledArticleProto> distilled_article; | |
35 if (success) { | |
36 distilled_article.reset(new DistilledArticleProto(it->second)); | |
37 } else { | |
38 distilled_article.reset(new DistilledArticleProto()); | |
39 } | |
40 base::MessageLoop::current()->PostTask( | |
41 FROM_HERE, | |
42 base::Bind(callback, success, base::Passed(&distilled_article))); | |
43 } | |
44 | |
45 void InMemoryContentStore::InjectContent(const ArticleEntry& entry, | |
46 const DistilledArticleProto& proto) { | |
47 cache_[entry.entry_id()] = proto; | |
48 } | |
49 | |
50 } // namespace dom_distiller | |
OLD | NEW |