Chromium Code Reviews| 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..e4f101f71d186a82f6bc6c0a2fd9eca357e1d248 |
| --- /dev/null |
| +++ b/components/dom_distiller/core/article_attachments_data.cc |
| @@ -0,0 +1,50 @@ |
| +// 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 { |
| + 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(); |
| +} |
| + |
| +} |
|
maniscalco
2014/11/12 18:59:43
nit: // namespace dom_distiller
cjhopman
2014/11/14 02:45:15
Done.
|