OLD | NEW |
(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) const { |
| 28 if (callback.is_null()) |
| 29 return; |
| 30 |
| 31 ContentMap::const_iterator it = cache_.find(entry.entry_id()); |
| 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 |
OLD | NEW |