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

Unified Diff: components/dom_distiller/core/article_attachments_data.cc

Issue 717793007: Add attachments support to DomDistillerStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/article_attachments_data.cc
diff --git a/components/dom_distiller/core/article_attachments_data.cc b/components/dom_distiller/core/article_attachments_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..256bfad0e3434b725ebdd4cc4ab73f8a2787afbe
--- /dev/null
+++ b/components/dom_distiller/core/article_attachments_data.cc
@@ -0,0 +1,52 @@
+// 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/article_attachments_data.h"
+
+#include "base/logging.h"
+
+namespace dom_distiller {
+
+syncer::AttachmentIdList GetAttachmentIds(
+ const sync_pb::ArticleAttachments& attachments) {
+ syncer::AttachmentIdList ids;
+ ids.push_back(
+ syncer::AttachmentId::CreateFromProto(attachments.distilled_article()));
+ return ids;
+}
+
+scoped_ptr<ArticleAttachmentsData> ArticleAttachmentsData::GetFromAttachmentMap(
+ const sync_pb::ArticleAttachments& attachments_key,
+ const syncer::AttachmentMap& attachment_map) {
+ scoped_ptr<ArticleAttachmentsData> data(new ArticleAttachmentsData);
+ syncer::AttachmentMap::const_iterator iter =
+ attachment_map.find(syncer::AttachmentId::CreateFromProto(
+ attachments_key.distilled_article()));
+ CHECK(iter != attachment_map.end());
+ scoped_refptr<base::RefCountedMemory> attachment_bytes =
+ iter->second.GetData();
+ data->distilled_article_.ParseFromArray(attachment_bytes->front(),
+ attachment_bytes->size());
+ return data.Pass();
+}
+
+void ArticleAttachmentsData::CreateSyncAttachments(
+ syncer::AttachmentList* attachment_list,
+ sync_pb::ArticleAttachments* attachments_key) const {
+ CHECK(attachment_list);
+ CHECK(attachments_key);
+ std::string serialized_article(distilled_article_.SerializeAsString());
+ syncer::Attachment attachment(
+ syncer::Attachment::Create(make_scoped_refptr(
+ base::RefCountedString::TakeString(&serialized_article))));
+ *attachments_key->mutable_distilled_article() =
+ attachment.GetId().GetProto();
+ attachment_list->push_back(attachment);
+}
+
+std::string ArticleAttachmentsData::ToString() const {
+ return distilled_article_.SerializeAsString();
+}
+
+} // namespace dom_distiller
« no previous file with comments | « components/dom_distiller/core/article_attachments_data.h ('k') | components/dom_distiller/core/article_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698