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

Unified 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 side-by-side diff with in-line comments
Download patch
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..28d7a728b6bdc4991430ad83eabaea89aa452f51
--- /dev/null
+++ b/components/dom_distiller/core/distilled_content_store.cc
@@ -0,0 +1,49 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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) {
+ if (callback.is_null())
+ return;
+
+ 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.
+ 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

Powered by Google App Engine
This is Rietveld 408576698