Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / dom_distiller / core / article_entry.cc
blob1550caf2b8039fbd73a7f37eb4756548ad88b782
1 // Copyright 2013 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_entry.h"
7 #include "base/logging.h"
8 #include "sync/api/sync_change.h"
10 using sync_pb::EntitySpecifics;
11 using sync_pb::ArticlePage;
12 using sync_pb::ArticleSpecifics;
14 namespace dom_distiller {
16 bool IsEntryPageValid(const ArticleEntryPage& page) { return page.has_url(); }
18 bool IsEntryValid(const ArticleEntry& entry) {
19 if (!entry.has_entry_id())
20 return false;
21 for (int i = 0; i < entry.pages_size(); ++i) {
22 if (!IsEntryPageValid(entry.pages(i)))
23 return false;
25 return true;
28 bool AreEntriesEqual(const ArticleEntry& left, const ArticleEntry& right) {
29 DCHECK(IsEntryValid(left));
30 DCHECK(IsEntryValid(right));
31 return left.SerializeAsString() == right.SerializeAsString();
34 ArticleEntry EntryFromSpecifics(const EntitySpecifics& specifics) {
35 DCHECK(specifics.has_article());
36 const ArticleSpecifics& article_specifics = specifics.article();
37 ArticleEntry entry = article_specifics;
38 DCHECK(IsEntryValid(entry));
39 return entry;
42 EntitySpecifics SpecificsFromEntry(const ArticleEntry& entry) {
43 DCHECK(IsEntryValid(entry));
44 EntitySpecifics specifics;
45 *specifics.mutable_article() = entry;
46 return specifics;
49 ArticleEntry GetEntryFromChange(const syncer::SyncChange& change) {
50 DCHECK(change.IsValid());
51 DCHECK(change.sync_data().IsValid());
52 return EntryFromSpecifics(change.sync_data().GetSpecifics());
55 std::string GetEntryIdFromSyncData(const syncer::SyncData& data) {
56 const EntitySpecifics& entity = data.GetSpecifics();
57 DCHECK(entity.has_article());
58 const ArticleSpecifics& specifics = entity.article();
59 DCHECK(specifics.has_entry_id());
60 return specifics.entry_id();
63 syncer::SyncData CreateLocalData(const ArticleEntry& entry) {
64 EntitySpecifics specifics = SpecificsFromEntry(entry);
65 const std::string& entry_id = entry.entry_id();
66 return syncer::SyncData::CreateLocalData(entry_id, entry_id, specifics);
69 } // namespace dom_distiller