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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/dom_distiller/core/article_attachments_data.h"
6
7 #include "base/logging.h"
8
9 namespace dom_distiller {
10
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;
17 }
18
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();
32 }
33
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);
46 }
47
48 std::string ArticleAttachmentsData::ToString() const {
49 return distilled_article_.SerializeAsString();
50 }
51
52 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698