Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / dom_distiller / core / article_attachments_data.cc
blob256bfad0e3434b725ebdd4cc4ab73f8a2787afbe
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.
5 #include "components/dom_distiller/core/article_attachments_data.h"
7 #include "base/logging.h"
9 namespace dom_distiller {
11 syncer::AttachmentIdList GetAttachmentIds(
12 const sync_pb::ArticleAttachments& attachments) {
13 syncer::AttachmentIdList ids;
14 ids.push_back(
15 syncer::AttachmentId::CreateFromProto(attachments.distilled_article()));
16 return ids;
19 scoped_ptr<ArticleAttachmentsData> ArticleAttachmentsData::GetFromAttachmentMap(
20 const sync_pb::ArticleAttachments& attachments_key,
21 const syncer::AttachmentMap& attachment_map) {
22 scoped_ptr<ArticleAttachmentsData> data(new ArticleAttachmentsData);
23 syncer::AttachmentMap::const_iterator iter =
24 attachment_map.find(syncer::AttachmentId::CreateFromProto(
25 attachments_key.distilled_article()));
26 CHECK(iter != attachment_map.end());
27 scoped_refptr<base::RefCountedMemory> attachment_bytes =
28 iter->second.GetData();
29 data->distilled_article_.ParseFromArray(attachment_bytes->front(),
30 attachment_bytes->size());
31 return data.Pass();
34 void ArticleAttachmentsData::CreateSyncAttachments(
35 syncer::AttachmentList* attachment_list,
36 sync_pb::ArticleAttachments* attachments_key) const {
37 CHECK(attachment_list);
38 CHECK(attachments_key);
39 std::string serialized_article(distilled_article_.SerializeAsString());
40 syncer::Attachment attachment(
41 syncer::Attachment::Create(make_scoped_refptr(
42 base::RefCountedString::TakeString(&serialized_article))));
43 *attachments_key->mutable_distilled_article() =
44 attachment.GetId().GetProto();
45 attachment_list->push_back(attachment);
48 std::string ArticleAttachmentsData::ToString() const {
49 return distilled_article_.SerializeAsString();
52 } // namespace dom_distiller