1 // Copyright 2017 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/offline_items_collection/core/offline_item.h"
6 
7 #include <utility>
8 
9 namespace offline_items_collection {
10 
11 // -----------------------------------------------------------------------------
12 // ContentId.
13 ContentId::ContentId() = default;
14 
15 ContentId::ContentId(const ContentId& other) = default;
16 
ContentId(const std::string & name_space,const std::string & id)17 ContentId::ContentId(const std::string& name_space, const std::string& id)
18     : name_space(name_space), id(id) {
19   DCHECK_EQ(std::string::npos, name_space.find_first_of(","));
20 }
21 
22 ContentId::~ContentId() = default;
23 
operator ==(const ContentId & content_id) const24 bool ContentId::operator==(const ContentId& content_id) const {
25   return name_space == content_id.name_space && id == content_id.id;
26 }
27 
operator <(const ContentId & content_id) const28 bool ContentId::operator<(const ContentId& content_id) const {
29   return std::tie(name_space, id) <
30          std::tie(content_id.name_space, content_id.id);
31 }
32 
33 // -----------------------------------------------------------------------------
34 // OfflineItemSchedule.
OfflineItemSchedule(bool only_on_wifi,base::Optional<base::Time> start_time)35 OfflineItemSchedule::OfflineItemSchedule(bool only_on_wifi,
36                                          base::Optional<base::Time> start_time)
37     : only_on_wifi(only_on_wifi), start_time(std::move(start_time)) {}
38 
39 OfflineItemSchedule::OfflineItemSchedule(const OfflineItemSchedule& other) =
40     default;
41 
42 OfflineItemSchedule& OfflineItemSchedule::operator=(
43     const OfflineItemSchedule& other) = default;
44 
45 OfflineItemSchedule::~OfflineItemSchedule() = default;
46 
operator ==(const OfflineItemSchedule & other) const47 bool OfflineItemSchedule::operator==(const OfflineItemSchedule& other) const {
48   return only_on_wifi == other.only_on_wifi && start_time == other.start_time;
49 }
50 
51 // -----------------------------------------------------------------------------
52 // OfflineItem.
Progress()53 OfflineItem::Progress::Progress()
54     : value(0), unit(OfflineItemProgressUnit::BYTES) {}
55 
56 OfflineItem::Progress::Progress(const OfflineItem::Progress& other) = default;
57 
58 OfflineItem::Progress::~Progress() = default;
59 
operator ==(const OfflineItem::Progress & other) const60 bool OfflineItem::Progress::operator==(
61     const OfflineItem::Progress& other) const {
62   return value == other.value && max == other.max && unit == other.unit;
63 }
64 
OfflineItem()65 OfflineItem::OfflineItem()
66     : filter(OfflineItemFilter::FILTER_OTHER),
67       is_transient(false),
68       is_suggested(false),
69       is_accelerated(false),
70       promote_origin(false),
71       can_rename(false),
72       ignore_visuals(false),
73       content_quality_score(0),
74       total_size_bytes(0),
75       externally_removed(false),
76       is_openable(false),
77       is_off_the_record(false),
78       state(OfflineItemState::COMPLETE),
79       fail_state(FailState::NO_FAILURE),
80       pending_state(PendingState::NOT_PENDING),
81       is_resumable(false),
82       allow_metered(false),
83       received_bytes(0),
84       time_remaining_ms(0),
85       is_dangerous(false) {}
86 
87 OfflineItem::OfflineItem(const OfflineItem& other) = default;
88 
89 OfflineItem& OfflineItem::operator=(const OfflineItem& other) = default;
90 
OfflineItem(const ContentId & id)91 OfflineItem::OfflineItem(const ContentId& id) : OfflineItem() {
92   this->id = id;
93 }
94 
95 OfflineItem::~OfflineItem() = default;
96 
operator ==(const OfflineItem & offline_item) const97 bool OfflineItem::operator==(const OfflineItem& offline_item) const {
98   return id == offline_item.id && title == offline_item.title &&
99          description == offline_item.description &&
100          filter == offline_item.filter &&
101          is_transient == offline_item.is_transient &&
102          is_suggested == offline_item.is_suggested &&
103          is_accelerated == offline_item.is_accelerated &&
104          promote_origin == offline_item.promote_origin &&
105          can_rename == offline_item.can_rename &&
106          ignore_visuals == offline_item.ignore_visuals &&
107          content_quality_score == offline_item.content_quality_score &&
108          total_size_bytes == offline_item.total_size_bytes &&
109          externally_removed == offline_item.externally_removed &&
110          creation_time == offline_item.creation_time &&
111          completion_time == offline_item.completion_time &&
112          last_accessed_time == offline_item.last_accessed_time &&
113          is_openable == offline_item.is_openable &&
114          file_path == offline_item.file_path &&
115          mime_type == offline_item.mime_type &&
116          page_url == offline_item.page_url &&
117          original_url == offline_item.original_url &&
118          is_off_the_record == offline_item.is_off_the_record &&
119          attribution == offline_item.attribution &&
120          state == offline_item.state && fail_state == offline_item.fail_state &&
121          pending_state == offline_item.pending_state &&
122          is_resumable == offline_item.is_resumable &&
123          allow_metered == offline_item.allow_metered &&
124          received_bytes == offline_item.received_bytes &&
125          progress == offline_item.progress &&
126          time_remaining_ms == offline_item.time_remaining_ms &&
127          is_dangerous == offline_item.is_dangerous &&
128          schedule == offline_item.schedule;
129 }
130 
131 OfflineItemVisuals::OfflineItemVisuals() = default;
OfflineItemVisuals(const gfx::Image & icon,const gfx::Image & custom_favicon)132 OfflineItemVisuals::OfflineItemVisuals(const gfx::Image& icon,
133                                        const gfx::Image& custom_favicon)
134     : icon(icon), custom_favicon(custom_favicon) {}
135 OfflineItemVisuals::OfflineItemVisuals(const OfflineItemVisuals& other) =
136     default;
137 OfflineItemVisuals::~OfflineItemVisuals() = default;
138 
139 OfflineItemShareInfo::OfflineItemShareInfo() = default;
140 OfflineItemShareInfo::OfflineItemShareInfo(const OfflineItemShareInfo& other) =
141     default;
142 OfflineItemShareInfo::~OfflineItemShareInfo() = default;
143 
144 }  // namespace offline_items_collection
145