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

Side by Side Diff: components/reading_list/ios/reading_list_entry.cc

Issue 2557443003: Add Unseen state to Reading List Entry (Closed)
Patch Set: Wire ReadingListEntry Created 4 years 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/reading_list/ios/reading_list_entry.h" 5 #include "components/reading_list/ios/reading_list_entry.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "components/reading_list/ios/offline_url_utils.h" 9 #include "components/reading_list/ios/offline_url_utils.h"
10 #include "components/reading_list/ios/proto/reading_list.pb.h" 10 #include "components/reading_list/ios/proto/reading_list.pb.h"
(...skipping 28 matching lines...) Expand all
39 }; 39 };
40 40
41 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) 41 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title)
42 : ReadingListEntry(url, title, nullptr){}; 42 : ReadingListEntry(url, title, nullptr){};
43 43
44 ReadingListEntry::ReadingListEntry(const GURL& url, 44 ReadingListEntry::ReadingListEntry(const GURL& url,
45 const std::string& title, 45 const std::string& title,
46 std::unique_ptr<net::BackoffEntry> backoff) 46 std::unique_ptr<net::BackoffEntry> backoff)
47 : ReadingListEntry(url, 47 : ReadingListEntry(url,
48 title, 48 title,
49 false, 49 UNSEEN,
50 0, 50 0,
51 0, 51 0,
52 WAITING, 52 WAITING,
53 base::FilePath(), 53 base::FilePath(),
54 0, 54 0,
55 std::move(backoff)) {} 55 std::move(backoff)) {}
56 56
57 ReadingListEntry::ReadingListEntry( 57 ReadingListEntry::ReadingListEntry(
58 const GURL& url, 58 const GURL& url,
59 const std::string& title, 59 const std::string& title,
60 bool read, 60 State state,
61 int64_t creation_time, 61 int64_t creation_time,
62 int64_t update_time, 62 int64_t update_time,
63 ReadingListEntry::DistillationState distilled_state, 63 ReadingListEntry::DistillationState distilled_state,
64 const base::FilePath& distilled_path, 64 const base::FilePath& distilled_path,
65 int failed_download_counter, 65 int failed_download_counter,
66 std::unique_ptr<net::BackoffEntry> backoff) 66 std::unique_ptr<net::BackoffEntry> backoff)
67 : url_(url), 67 : url_(url),
68 title_(title), 68 title_(title),
69 read_(read), 69 state_(state),
70 distilled_path_(distilled_path), 70 distilled_path_(distilled_path),
71 distilled_state_(distilled_state), 71 distilled_state_(distilled_state),
72 failed_download_counter_(failed_download_counter), 72 failed_download_counter_(failed_download_counter),
73 creation_time_us_(creation_time), 73 creation_time_us_(creation_time),
74 update_time_us_(update_time) { 74 update_time_us_(update_time) {
75 if (backoff) { 75 if (backoff) {
76 backoff_ = std::move(backoff); 76 backoff_ = std::move(backoff);
77 } else { 77 } else {
78 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); 78 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy);
79 } 79 }
80 if (creation_time_us_ == 0) { 80 if (creation_time_us_ == 0) {
81 DCHECK(update_time_us_ == 0); 81 DCHECK(update_time_us_ == 0);
82 creation_time_us_ = 82 creation_time_us_ =
83 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); 83 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
84 update_time_us_ = creation_time_us_; 84 update_time_us_ = creation_time_us_;
85 } 85 }
86 DCHECK(!url.is_empty()); 86 DCHECK(!url.is_empty());
87 DCHECK(url.is_valid()); 87 DCHECK(url.is_valid());
88 } 88 }
89 89
90 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) 90 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry)
91 : url_(std::move(entry.url_)), 91 : url_(std::move(entry.url_)),
92 title_(std::move(entry.title_)), 92 title_(std::move(entry.title_)),
93 read_(std::move(entry.read_)), 93 state_(std::move(entry.state_)),
94 distilled_path_(std::move(entry.distilled_path_)), 94 distilled_path_(std::move(entry.distilled_path_)),
95 distilled_state_(std::move(entry.distilled_state_)), 95 distilled_state_(std::move(entry.distilled_state_)),
96 backoff_(std::move(entry.backoff_)), 96 backoff_(std::move(entry.backoff_)),
97 failed_download_counter_(std::move(entry.failed_download_counter_)), 97 failed_download_counter_(std::move(entry.failed_download_counter_)),
98 creation_time_us_(std::move(entry.creation_time_us_)), 98 creation_time_us_(std::move(entry.creation_time_us_)),
99 update_time_us_(std::move(entry.update_time_us_)) {} 99 update_time_us_(std::move(entry.update_time_us_)) {}
100 100
101 ReadingListEntry::~ReadingListEntry() {} 101 ReadingListEntry::~ReadingListEntry() {}
102 102
103 const GURL& ReadingListEntry::URL() const { 103 const GURL& ReadingListEntry::URL() const {
(...skipping 19 matching lines...) Expand all
123 int ReadingListEntry::FailedDownloadCounter() const { 123 int ReadingListEntry::FailedDownloadCounter() const {
124 return failed_download_counter_; 124 return failed_download_counter_;
125 } 125 }
126 126
127 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { 127 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) {
128 url_ = std::move(other.url_); 128 url_ = std::move(other.url_);
129 title_ = std::move(other.title_); 129 title_ = std::move(other.title_);
130 distilled_path_ = std::move(other.distilled_path_); 130 distilled_path_ = std::move(other.distilled_path_);
131 distilled_state_ = std::move(other.distilled_state_); 131 distilled_state_ = std::move(other.distilled_state_);
132 backoff_ = std::move(other.backoff_); 132 backoff_ = std::move(other.backoff_);
133 read_ = std::move(other.read_); 133 state_ = std::move(other.state_);
134 failed_download_counter_ = std::move(other.failed_download_counter_); 134 failed_download_counter_ = std::move(other.failed_download_counter_);
135 creation_time_us_ = std::move(other.creation_time_us_); 135 creation_time_us_ = std::move(other.creation_time_us_);
136 update_time_us_ = std::move(other.update_time_us_); 136 update_time_us_ = std::move(other.update_time_us_);
137 return *this; 137 return *this;
138 } 138 }
139 139
140 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { 140 bool ReadingListEntry::operator==(const ReadingListEntry& other) const {
141 return url_ == other.url_; 141 return url_ == other.url_;
142 } 142 }
143 143
144 void ReadingListEntry::SetTitle(const std::string& title) { 144 void ReadingListEntry::SetTitle(const std::string& title) {
145 title_ = title; 145 title_ = title;
146 } 146 }
147 147
148 void ReadingListEntry::SetRead(bool read) { 148 void ReadingListEntry::SetRead(bool read) {
149 read_ = read; 149 state_ = read ? READ : UNREAD;
150 MarkEntryUpdated(); 150 MarkEntryUpdated();
151 } 151 }
152 152
153 bool ReadingListEntry::IsRead() const { 153 bool ReadingListEntry::IsRead() const {
154 return read_; 154 return state_ == READ;
155 }
156
157 bool ReadingListEntry::HasBeenSeen() const {
158 return state_ != UNSEEN;
155 } 159 }
156 160
157 void ReadingListEntry::SetDistilledPath(const base::FilePath& path) { 161 void ReadingListEntry::SetDistilledPath(const base::FilePath& path) {
158 DCHECK(!path.empty()); 162 DCHECK(!path.empty());
159 distilled_path_ = path; 163 distilled_path_ = path;
160 distilled_state_ = PROCESSED; 164 distilled_state_ = PROCESSED;
161 backoff_->Reset(); 165 backoff_->Reset();
162 failed_download_counter_ = 0; 166 failed_download_counter_ = 0;
163 } 167 }
164 168
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 int64_t creation_time_us = 0; 212 int64_t creation_time_us = 0;
209 if (pb_entry.has_creation_time_us()) { 213 if (pb_entry.has_creation_time_us()) {
210 creation_time_us = pb_entry.creation_time_us(); 214 creation_time_us = pb_entry.creation_time_us();
211 } 215 }
212 216
213 int64_t update_time_us = 0; 217 int64_t update_time_us = 0;
214 if (pb_entry.has_update_time_us()) { 218 if (pb_entry.has_update_time_us()) {
215 update_time_us = pb_entry.update_time_us(); 219 update_time_us = pb_entry.update_time_us();
216 } 220 }
217 221
218 bool read = false; 222 State state = UNSEEN;
pavely 2016/12/05 19:10:31 Absent status is the same as UNSEEN. Is it worth a
Olivier 2016/12/06 09:59:29 Done.
219 if (pb_entry.has_status()) { 223 if (pb_entry.has_status()) {
220 read = pb_entry.status() == reading_list::ReadingListLocal::READ; 224 if (pb_entry.status() == reading_list::ReadingListLocal::READ) {
225 state = READ;
226 } else if (pb_entry.status() == reading_list::ReadingListLocal::UNREAD) {
227 state = UNREAD;
228 }
221 } 229 }
222 230
223 ReadingListEntry::DistillationState distillation_state = 231 ReadingListEntry::DistillationState distillation_state =
224 ReadingListEntry::WAITING; 232 ReadingListEntry::WAITING;
225 if (pb_entry.has_distillation_state()) { 233 if (pb_entry.has_distillation_state()) {
226 switch (pb_entry.distillation_state()) { 234 switch (pb_entry.distillation_state()) {
227 case reading_list::ReadingListLocal::WAITING: 235 case reading_list::ReadingListLocal::WAITING:
228 distillation_state = ReadingListEntry::WAITING; 236 distillation_state = ReadingListEntry::WAITING;
229 break; 237 break;
230 case reading_list::ReadingListLocal::PROCESSING: 238 case reading_list::ReadingListLocal::PROCESSING:
(...skipping 26 matching lines...) Expand all
257 JSONStringValueDeserializer deserializer(pb_entry.backoff()); 265 JSONStringValueDeserializer deserializer(pb_entry.backoff());
258 std::unique_ptr<base::Value> value( 266 std::unique_ptr<base::Value> value(
259 deserializer.Deserialize(nullptr, nullptr)); 267 deserializer.Deserialize(nullptr, nullptr));
260 if (value) { 268 if (value) {
261 backoff = net::BackoffEntrySerializer::DeserializeFromValue( 269 backoff = net::BackoffEntrySerializer::DeserializeFromValue(
262 *value, &kBackoffPolicy, nullptr, base::Time::Now()); 270 *value, &kBackoffPolicy, nullptr, base::Time::Now());
263 } 271 }
264 } 272 }
265 273
266 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( 274 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry(
267 url, title, read, creation_time_us, update_time_us, distillation_state, 275 url, title, state, creation_time_us, update_time_us, distillation_state,
268 distilled_path, failed_download_counter, std::move(backoff))); 276 distilled_path, failed_download_counter, std::move(backoff)));
269 } 277 }
270 278
271 // static 279 // static
272 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics( 280 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics(
273 const sync_pb::ReadingListSpecifics& pb_entry) { 281 const sync_pb::ReadingListSpecifics& pb_entry) {
274 if (!pb_entry.has_url()) { 282 if (!pb_entry.has_url()) {
275 return nullptr; 283 return nullptr;
276 } 284 }
277 GURL url(pb_entry.url()); 285 GURL url(pb_entry.url());
278 if (url.is_empty() || !url.is_valid()) { 286 if (url.is_empty() || !url.is_valid()) {
279 return nullptr; 287 return nullptr;
280 } 288 }
281 std::string title; 289 std::string title;
282 if (pb_entry.has_title()) { 290 if (pb_entry.has_title()) {
283 title = pb_entry.title(); 291 title = pb_entry.title();
284 } 292 }
285 293
286 int64_t creation_time_us = 0; 294 int64_t creation_time_us = 0;
287 if (pb_entry.has_creation_time_us()) { 295 if (pb_entry.has_creation_time_us()) {
288 creation_time_us = pb_entry.creation_time_us(); 296 creation_time_us = pb_entry.creation_time_us();
289 } 297 }
290 298
291 int64_t update_time_us = 0; 299 int64_t update_time_us = 0;
292 if (pb_entry.has_update_time_us()) { 300 if (pb_entry.has_update_time_us()) {
293 update_time_us = pb_entry.update_time_us(); 301 update_time_us = pb_entry.update_time_us();
294 } 302 }
295 303
296 bool read = false; 304 State state = UNSEEN;
297 if (pb_entry.has_status()) { 305 if (pb_entry.has_status()) {
298 read = pb_entry.status() == sync_pb::ReadingListSpecifics::READ; 306 if (pb_entry.status() == sync_pb::ReadingListSpecifics::READ) {
307 state = READ;
308 } else if (pb_entry.status() == sync_pb::ReadingListSpecifics::UNREAD) {
309 state = UNREAD;
310 }
299 } 311 }
300 312
301 return base::WrapUnique<ReadingListEntry>( 313 return base::WrapUnique<ReadingListEntry>(
302 new ReadingListEntry(url, title, read, creation_time_us, update_time_us, 314 new ReadingListEntry(url, title, state, creation_time_us, update_time_us,
303 WAITING, base::FilePath(), 0, nullptr)); 315 WAITING, base::FilePath(), 0, nullptr));
304 } 316 }
305 317
306 void ReadingListEntry::MergeLocalStateFrom(ReadingListEntry& other) { 318 void ReadingListEntry::MergeLocalStateFrom(ReadingListEntry& other) {
307 distilled_path_ = std::move(other.distilled_path_); 319 distilled_path_ = std::move(other.distilled_path_);
308 distilled_state_ = std::move(other.distilled_state_); 320 distilled_state_ = std::move(other.distilled_state_);
309 backoff_ = std::move(other.backoff_); 321 backoff_ = std::move(other.backoff_);
310 failed_download_counter_ = std::move(other.failed_download_counter_); 322 failed_download_counter_ = std::move(other.failed_download_counter_);
311 } 323 }
312 324
313 std::unique_ptr<reading_list::ReadingListLocal> 325 std::unique_ptr<reading_list::ReadingListLocal>
314 ReadingListEntry::AsReadingListLocal() const { 326 ReadingListEntry::AsReadingListLocal() const {
315 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = 327 std::unique_ptr<reading_list::ReadingListLocal> pb_entry =
316 base::MakeUnique<reading_list::ReadingListLocal>(); 328 base::MakeUnique<reading_list::ReadingListLocal>();
317 329
318 // URL is used as the key for the database and sync as there is only one entry 330 // URL is used as the key for the database and sync as there is only one entry
319 // per URL. 331 // per URL.
320 pb_entry->set_entry_id(URL().spec()); 332 pb_entry->set_entry_id(URL().spec());
321 pb_entry->set_title(Title()); 333 pb_entry->set_title(Title());
322 pb_entry->set_url(URL().spec()); 334 pb_entry->set_url(URL().spec());
323 pb_entry->set_creation_time_us(CreationTime()); 335 pb_entry->set_creation_time_us(CreationTime());
324 pb_entry->set_update_time_us(UpdateTime()); 336 pb_entry->set_update_time_us(UpdateTime());
325 337
326 if (read_) { 338 if (state_== READ) {
pavely 2016/12/05 19:10:31 When handling enum values, it is better to to use
327 pb_entry->set_status(reading_list::ReadingListLocal::READ); 339 pb_entry->set_status(reading_list::ReadingListLocal::READ);
340 } else if (state_== UNREAD) {
341 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD);
328 } else { 342 } else {
329 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); 343 pb_entry->set_status(reading_list::ReadingListLocal::UNSEEN);
330 } 344 }
331 345
332 reading_list::ReadingListLocal::DistillationState distilation_state; 346 reading_list::ReadingListLocal::DistillationState distilation_state;
333 switch (DistilledState()) { 347 switch (DistilledState()) {
334 case ReadingListEntry::WAITING: 348 case ReadingListEntry::WAITING:
335 distilation_state = reading_list::ReadingListLocal::WAITING; 349 distilation_state = reading_list::ReadingListLocal::WAITING;
336 break; 350 break;
337 case ReadingListEntry::PROCESSING: 351 case ReadingListEntry::PROCESSING:
338 distilation_state = reading_list::ReadingListLocal::PROCESSING; 352 distilation_state = reading_list::ReadingListLocal::PROCESSING;
339 break; 353 break;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 base::MakeUnique<sync_pb::ReadingListSpecifics>(); 386 base::MakeUnique<sync_pb::ReadingListSpecifics>();
373 387
374 // URL is used as the key for the database and sync as there is only one entry 388 // URL is used as the key for the database and sync as there is only one entry
375 // per URL. 389 // per URL.
376 pb_entry->set_entry_id(URL().spec()); 390 pb_entry->set_entry_id(URL().spec());
377 pb_entry->set_title(Title()); 391 pb_entry->set_title(Title());
378 pb_entry->set_url(URL().spec()); 392 pb_entry->set_url(URL().spec());
379 pb_entry->set_creation_time_us(CreationTime()); 393 pb_entry->set_creation_time_us(CreationTime());
380 pb_entry->set_update_time_us(UpdateTime()); 394 pb_entry->set_update_time_us(UpdateTime());
381 395
382 if (read_) { 396 if (state_== READ) {
383 pb_entry->set_status(sync_pb::ReadingListSpecifics::READ); 397 pb_entry->set_status(sync_pb::ReadingListSpecifics::READ);
398 } else if (state_== UNREAD) {
399 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD);
384 } else { 400 } else {
385 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); 401 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN);
386 } 402 }
387 403
388 return pb_entry; 404 return pb_entry;
389 } 405 }
390 406
391 bool ReadingListEntry::CompareEntryUpdateTime(const ReadingListEntry& lhs, 407 bool ReadingListEntry::CompareEntryUpdateTime(const ReadingListEntry& lhs,
392 const ReadingListEntry& rhs) { 408 const ReadingListEntry& rhs) {
393 return lhs.UpdateTime() > rhs.UpdateTime(); 409 return lhs.UpdateTime() > rhs.UpdateTime();
394 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698