Chromium Code Reviews| Index: components/dom_distiller/core/distilled_content_store.cc |
| diff --git a/components/dom_distiller/core/distilled_content_store.cc b/components/dom_distiller/core/distilled_content_store.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b058bd3843cb6f1d819fa14885fd0b8cfb85443 |
| --- /dev/null |
| +++ b/components/dom_distiller/core/distilled_content_store.cc |
| @@ -0,0 +1,50 @@ |
| +// 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.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/dom_distiller/core/distilled_content_store.h" |
| + |
| +#include "base/message_loop/message_loop.h" |
| + |
| +namespace dom_distiller { |
| + |
| +InMemoryContentStore::InMemoryContentStore() {} |
| +InMemoryContentStore::~InMemoryContentStore() {} |
| + |
| +void InMemoryContentStore::SaveContent( |
| + const ArticleEntry& entry, |
| + const DistilledArticleProto& proto, |
| + InMemoryContentStore::SaveCallback callback) { |
| + InjectContent(entry, proto); |
| + if (!callback.is_null()) { |
| + base::MessageLoop::current()->PostTask(FROM_HERE, |
| + base::Bind(callback, true)); |
| + } |
| +} |
| + |
| +void InMemoryContentStore::LoadContent( |
| + const ArticleEntry& entry, |
| + InMemoryContentStore::LoadCallback callback) { |
| + ContentMap::iterator it = cache_.find(entry.entry_id()); |
| + |
| + 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.
|
| + return; |
| + |
| + bool success = it != cache_.end(); |
| + scoped_ptr<DistilledArticleProto> distilled_article; |
| + if (success) { |
| + distilled_article.reset(new DistilledArticleProto(it->second)); |
| + } else { |
| + distilled_article.reset(new DistilledArticleProto()); |
| + } |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(callback, success, base::Passed(&distilled_article))); |
| +} |
| + |
| +void InMemoryContentStore::InjectContent(const ArticleEntry& entry, |
| + const DistilledArticleProto& proto) { |
| + cache_[entry.entry_id()] = proto; |
| +} |
| + |
| +} // namespace dom_distiller |