OLD | NEW |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 title, | 49 title, |
50 UNSEEN, | 50 UNSEEN, |
51 0, | 51 0, |
52 0, | 52 0, |
53 0, | 53 0, |
54 0, | 54 0, |
55 WAITING, | 55 WAITING, |
56 base::FilePath(), | 56 base::FilePath(), |
57 GURL(), | 57 GURL(), |
58 0, | 58 0, |
| 59 0, |
| 60 0, |
59 std::move(backoff)) {} | 61 std::move(backoff)) {} |
60 | 62 |
61 ReadingListEntry::ReadingListEntry( | 63 ReadingListEntry::ReadingListEntry( |
62 const GURL& url, | 64 const GURL& url, |
63 const std::string& title, | 65 const std::string& title, |
64 State state, | 66 State state, |
65 int64_t creation_time, | 67 int64_t creation_time, |
66 int64_t first_read_time, | 68 int64_t first_read_time, |
67 int64_t update_time, | 69 int64_t update_time, |
68 int64_t update_title_time, | 70 int64_t update_title_time, |
69 ReadingListEntry::DistillationState distilled_state, | 71 ReadingListEntry::DistillationState distilled_state, |
70 const base::FilePath& distilled_path, | 72 const base::FilePath& distilled_path, |
71 const GURL& distilled_url, | 73 const GURL& distilled_url, |
| 74 int64_t distillation_time, |
| 75 int64_t distillation_size, |
72 int failed_download_counter, | 76 int failed_download_counter, |
73 std::unique_ptr<net::BackoffEntry> backoff) | 77 std::unique_ptr<net::BackoffEntry> backoff) |
74 : url_(url), | 78 : url_(url), |
75 title_(title), | 79 title_(title), |
76 state_(state), | 80 state_(state), |
77 distilled_path_(distilled_path), | 81 distilled_path_(distilled_path), |
78 distilled_url_(distilled_url), | 82 distilled_url_(distilled_url), |
79 distilled_state_(distilled_state), | 83 distilled_state_(distilled_state), |
80 failed_download_counter_(failed_download_counter), | 84 failed_download_counter_(failed_download_counter), |
81 creation_time_us_(creation_time), | 85 creation_time_us_(creation_time), |
82 first_read_time_us_(first_read_time), | 86 first_read_time_us_(first_read_time), |
83 update_time_us_(update_time), | 87 update_time_us_(update_time), |
84 update_title_time_us_(update_title_time) { | 88 update_title_time_us_(update_title_time), |
| 89 distillation_time_us_(distillation_time), |
| 90 distillation_size_(distillation_size) { |
85 if (backoff) { | 91 if (backoff) { |
86 backoff_ = std::move(backoff); | 92 backoff_ = std::move(backoff); |
87 } else { | 93 } else { |
88 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); | 94 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); |
89 } | 95 } |
90 if (creation_time_us_ == 0) { | 96 if (creation_time_us_ == 0) { |
91 DCHECK(update_time_us_ == 0); | 97 DCHECK(update_time_us_ == 0); |
92 DCHECK(update_title_time_us_ == 0); | 98 DCHECK(update_title_time_us_ == 0); |
93 creation_time_us_ = | 99 creation_time_us_ = |
94 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); | 100 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); |
95 update_time_us_ = creation_time_us_; | 101 update_time_us_ = creation_time_us_; |
96 update_title_time_us_ = creation_time_us_; | 102 update_title_time_us_ = creation_time_us_; |
97 } | 103 } |
98 DCHECK(!url.is_empty()); | 104 DCHECK(!url.is_empty()); |
99 DCHECK(url.is_valid()); | 105 DCHECK(url.is_valid()); |
100 } | 106 } |
101 | 107 |
102 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) | 108 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) |
103 : url_(std::move(entry.url_)), | 109 : url_(std::move(entry.url_)), |
104 title_(std::move(entry.title_)), | 110 title_(std::move(entry.title_)), |
105 state_(std::move(entry.state_)), | 111 state_(std::move(entry.state_)), |
106 distilled_path_(std::move(entry.distilled_path_)), | 112 distilled_path_(std::move(entry.distilled_path_)), |
107 distilled_url_(std::move(entry.distilled_url_)), | 113 distilled_url_(std::move(entry.distilled_url_)), |
108 distilled_state_(std::move(entry.distilled_state_)), | 114 distilled_state_(std::move(entry.distilled_state_)), |
109 backoff_(std::move(entry.backoff_)), | 115 backoff_(std::move(entry.backoff_)), |
110 failed_download_counter_(std::move(entry.failed_download_counter_)), | 116 failed_download_counter_(std::move(entry.failed_download_counter_)), |
111 creation_time_us_(std::move(entry.creation_time_us_)), | 117 creation_time_us_(std::move(entry.creation_time_us_)), |
112 first_read_time_us_(std::move(entry.first_read_time_us_)), | 118 first_read_time_us_(std::move(entry.first_read_time_us_)), |
113 update_time_us_(std::move(entry.update_time_us_)), | 119 update_time_us_(std::move(entry.update_time_us_)), |
114 update_title_time_us_(std::move(entry.update_title_time_us_)) {} | 120 update_title_time_us_(std::move(entry.update_title_time_us_)), |
| 121 distillation_time_us_(std::move(entry.distillation_time_us_)), |
| 122 distillation_size_(std::move(entry.distillation_size_)) {} |
115 | 123 |
116 ReadingListEntry::~ReadingListEntry() {} | 124 ReadingListEntry::~ReadingListEntry() {} |
117 | 125 |
118 const GURL& ReadingListEntry::URL() const { | 126 const GURL& ReadingListEntry::URL() const { |
119 return url_; | 127 return url_; |
120 } | 128 } |
121 | 129 |
122 const std::string& ReadingListEntry::Title() const { | 130 const std::string& ReadingListEntry::Title() const { |
123 return title_; | 131 return title_; |
124 } | 132 } |
125 | 133 |
126 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { | 134 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { |
127 return distilled_state_; | 135 return distilled_state_; |
128 } | 136 } |
129 | 137 |
130 const base::FilePath& ReadingListEntry::DistilledPath() const { | 138 const base::FilePath& ReadingListEntry::DistilledPath() const { |
131 return distilled_path_; | 139 return distilled_path_; |
132 } | 140 } |
133 | 141 |
134 const GURL& ReadingListEntry::DistilledURL() const { | 142 const GURL& ReadingListEntry::DistilledURL() const { |
135 return distilled_url_; | 143 return distilled_url_; |
136 } | 144 } |
137 | 145 |
| 146 int64_t ReadingListEntry::DistillationTime() const { |
| 147 return distillation_time_us_; |
| 148 } |
| 149 |
| 150 int64_t ReadingListEntry::DistillationSize() const { |
| 151 return distillation_size_; |
| 152 } |
| 153 |
138 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { | 154 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { |
139 return backoff_->GetTimeUntilRelease(); | 155 return backoff_->GetTimeUntilRelease(); |
140 } | 156 } |
141 | 157 |
142 int ReadingListEntry::FailedDownloadCounter() const { | 158 int ReadingListEntry::FailedDownloadCounter() const { |
143 return failed_download_counter_; | 159 return failed_download_counter_; |
144 } | 160 } |
145 | 161 |
146 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { | 162 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { |
147 url_ = std::move(other.url_); | 163 url_ = std::move(other.url_); |
148 title_ = std::move(other.title_); | 164 title_ = std::move(other.title_); |
149 distilled_path_ = std::move(other.distilled_path_); | 165 distilled_path_ = std::move(other.distilled_path_); |
150 distilled_url_ = std::move(other.distilled_url_); | 166 distilled_url_ = std::move(other.distilled_url_); |
151 distilled_state_ = std::move(other.distilled_state_); | 167 distilled_state_ = std::move(other.distilled_state_); |
152 backoff_ = std::move(other.backoff_); | 168 backoff_ = std::move(other.backoff_); |
153 state_ = std::move(other.state_); | 169 state_ = std::move(other.state_); |
154 failed_download_counter_ = std::move(other.failed_download_counter_); | 170 failed_download_counter_ = std::move(other.failed_download_counter_); |
155 creation_time_us_ = std::move(other.creation_time_us_); | 171 creation_time_us_ = std::move(other.creation_time_us_); |
156 first_read_time_us_ = std::move(other.first_read_time_us_); | 172 first_read_time_us_ = std::move(other.first_read_time_us_); |
157 update_time_us_ = std::move(other.update_time_us_); | 173 update_time_us_ = std::move(other.update_time_us_); |
158 update_title_time_us_ = std::move(other.update_title_time_us_); | 174 update_title_time_us_ = std::move(other.update_title_time_us_); |
| 175 distillation_time_us_ = std::move(other.distillation_time_us_); |
| 176 distillation_size_ = std::move(other.distillation_size_); |
159 return *this; | 177 return *this; |
160 } | 178 } |
161 | 179 |
162 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { | 180 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { |
163 return url_ == other.url_; | 181 return url_ == other.url_; |
164 } | 182 } |
165 | 183 |
166 void ReadingListEntry::SetTitle(const std::string& title) { | 184 void ReadingListEntry::SetTitle(const std::string& title) { |
167 title_ = title; | 185 title_ = title; |
168 update_title_time_us_ = | 186 update_title_time_us_ = |
(...skipping 19 matching lines...) Expand all Loading... |
188 | 206 |
189 bool ReadingListEntry::IsRead() const { | 207 bool ReadingListEntry::IsRead() const { |
190 return state_ == READ; | 208 return state_ == READ; |
191 } | 209 } |
192 | 210 |
193 bool ReadingListEntry::HasBeenSeen() const { | 211 bool ReadingListEntry::HasBeenSeen() const { |
194 return state_ != UNSEEN; | 212 return state_ != UNSEEN; |
195 } | 213 } |
196 | 214 |
197 void ReadingListEntry::SetDistilledInfo(const base::FilePath& path, | 215 void ReadingListEntry::SetDistilledInfo(const base::FilePath& path, |
198 const GURL& distilled_url) { | 216 const GURL& distilled_url, |
| 217 int64_t distilation_size, |
| 218 int64_t distilation_time) { |
199 DCHECK(!path.empty()); | 219 DCHECK(!path.empty()); |
200 DCHECK(distilled_url.is_valid()); | 220 DCHECK(distilled_url.is_valid()); |
201 distilled_path_ = path; | 221 distilled_path_ = path; |
202 distilled_state_ = PROCESSED; | 222 distilled_state_ = PROCESSED; |
203 distilled_url_ = distilled_url; | 223 distilled_url_ = distilled_url; |
| 224 distillation_time_us_ = distilation_time; |
| 225 ; |
| 226 distillation_size_ = distilation_size; |
204 backoff_->Reset(); | 227 backoff_->Reset(); |
205 failed_download_counter_ = 0; | 228 failed_download_counter_ = 0; |
206 } | 229 } |
207 | 230 |
208 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { | 231 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { |
209 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. | 232 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. |
210 DCHECK(distilled_state != WAITING); | 233 DCHECK(distilled_state != WAITING); |
211 // Increase time until next retry exponentially if the state change from a | 234 // Increase time until next retry exponentially if the state change from a |
212 // non-error state to an error state. | 235 // non-error state to an error state. |
213 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && | 236 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 base::FilePath distilled_path; | 340 base::FilePath distilled_path; |
318 if (pb_entry.has_distilled_path()) { | 341 if (pb_entry.has_distilled_path()) { |
319 distilled_path = base::FilePath(pb_entry.distilled_path()); | 342 distilled_path = base::FilePath(pb_entry.distilled_path()); |
320 } | 343 } |
321 | 344 |
322 GURL distilled_url; | 345 GURL distilled_url; |
323 if (pb_entry.has_distilled_url()) { | 346 if (pb_entry.has_distilled_url()) { |
324 distilled_url = GURL(pb_entry.distilled_url()); | 347 distilled_url = GURL(pb_entry.distilled_url()); |
325 } | 348 } |
326 | 349 |
| 350 int64_t distillation_time_us = 0; |
| 351 if (pb_entry.has_distillation_time_us()) { |
| 352 distillation_time_us = pb_entry.distillation_time_us(); |
| 353 } |
| 354 |
| 355 int64_t distillation_size = 0; |
| 356 if (pb_entry.has_distillation_size()) { |
| 357 distillation_size = pb_entry.distillation_size(); |
| 358 } |
| 359 |
327 int64_t failed_download_counter = 0; | 360 int64_t failed_download_counter = 0; |
328 if (pb_entry.has_failed_download_counter()) { | 361 if (pb_entry.has_failed_download_counter()) { |
329 failed_download_counter = pb_entry.failed_download_counter(); | 362 failed_download_counter = pb_entry.failed_download_counter(); |
330 } | 363 } |
331 | 364 |
332 std::unique_ptr<net::BackoffEntry> backoff; | 365 std::unique_ptr<net::BackoffEntry> backoff; |
333 if (pb_entry.has_backoff()) { | 366 if (pb_entry.has_backoff()) { |
334 JSONStringValueDeserializer deserializer(pb_entry.backoff()); | 367 JSONStringValueDeserializer deserializer(pb_entry.backoff()); |
335 std::unique_ptr<base::Value> value( | 368 std::unique_ptr<base::Value> value( |
336 deserializer.Deserialize(nullptr, nullptr)); | 369 deserializer.Deserialize(nullptr, nullptr)); |
337 if (value) { | 370 if (value) { |
338 backoff = net::BackoffEntrySerializer::DeserializeFromValue( | 371 backoff = net::BackoffEntrySerializer::DeserializeFromValue( |
339 *value, &kBackoffPolicy, nullptr, base::Time::Now()); | 372 *value, &kBackoffPolicy, nullptr, base::Time::Now()); |
340 } | 373 } |
341 } | 374 } |
342 | 375 |
343 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( | 376 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( |
344 url, title, state, creation_time_us, first_read_time_us, update_time_us, | 377 url, title, state, creation_time_us, first_read_time_us, update_time_us, |
345 update_title_time_us, distillation_state, distilled_path, distilled_url, | 378 update_title_time_us, distillation_state, distilled_path, distilled_url, |
346 failed_download_counter, std::move(backoff))); | 379 distillation_time_us, distillation_size, failed_download_counter, |
| 380 std::move(backoff))); |
347 } | 381 } |
348 | 382 |
349 // static | 383 // static |
350 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics( | 384 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics( |
351 const sync_pb::ReadingListSpecifics& pb_entry) { | 385 const sync_pb::ReadingListSpecifics& pb_entry) { |
352 if (!pb_entry.has_url()) { | 386 if (!pb_entry.has_url()) { |
353 return nullptr; | 387 return nullptr; |
354 } | 388 } |
355 GURL url(pb_entry.url()); | 389 GURL url(pb_entry.url()); |
356 if (url.is_empty() || !url.is_valid()) { | 390 if (url.is_empty() || !url.is_valid()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 state = UNREAD; | 425 state = UNREAD; |
392 break; | 426 break; |
393 case sync_pb::ReadingListSpecifics::UNSEEN: | 427 case sync_pb::ReadingListSpecifics::UNSEEN: |
394 state = UNSEEN; | 428 state = UNSEEN; |
395 break; | 429 break; |
396 } | 430 } |
397 } | 431 } |
398 | 432 |
399 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( | 433 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( |
400 url, title, state, creation_time_us, first_read_time_us, update_time_us, | 434 url, title, state, creation_time_us, first_read_time_us, update_time_us, |
401 update_title_time_us, WAITING, base::FilePath(), GURL(), 0, nullptr)); | 435 update_title_time_us, WAITING, base::FilePath(), GURL(), 0, 0, 0, |
| 436 nullptr)); |
402 } | 437 } |
403 | 438 |
404 void ReadingListEntry::MergeWithEntry(const ReadingListEntry& other) { | 439 void ReadingListEntry::MergeWithEntry(const ReadingListEntry& other) { |
405 #if !defined(NDEBUG) | 440 #if !defined(NDEBUG) |
406 // Checks that the result entry respects the sync order. | 441 // Checks that the result entry respects the sync order. |
407 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb( | 442 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb( |
408 AsReadingListSpecifics()); | 443 AsReadingListSpecifics()); |
409 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb( | 444 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb( |
410 other.AsReadingListSpecifics()); | 445 other.AsReadingListSpecifics()); |
411 #endif | 446 #endif |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 distilation_state = reading_list::ReadingListLocal::ERROR; | 533 distilation_state = reading_list::ReadingListLocal::ERROR; |
499 break; | 534 break; |
500 } | 535 } |
501 pb_entry->set_distillation_state(distilation_state); | 536 pb_entry->set_distillation_state(distilation_state); |
502 if (!DistilledPath().empty()) { | 537 if (!DistilledPath().empty()) { |
503 pb_entry->set_distilled_path(DistilledPath().value()); | 538 pb_entry->set_distilled_path(DistilledPath().value()); |
504 } | 539 } |
505 if (DistilledURL().is_valid()) { | 540 if (DistilledURL().is_valid()) { |
506 pb_entry->set_distilled_url(DistilledURL().spec()); | 541 pb_entry->set_distilled_url(DistilledURL().spec()); |
507 } | 542 } |
| 543 if (DistillationTime()) { |
| 544 pb_entry->set_distillation_time_us(DistillationTime()); |
| 545 } |
| 546 if (DistillationSize()) { |
| 547 pb_entry->set_distillation_size(DistillationSize()); |
| 548 } |
| 549 |
508 pb_entry->set_failed_download_counter(failed_download_counter_); | 550 pb_entry->set_failed_download_counter(failed_download_counter_); |
509 | 551 |
510 if (backoff_) { | 552 if (backoff_) { |
511 std::unique_ptr<base::Value> backoff = | 553 std::unique_ptr<base::Value> backoff = |
512 net::BackoffEntrySerializer::SerializeToValue(*backoff_, | 554 net::BackoffEntrySerializer::SerializeToValue(*backoff_, |
513 base::Time::Now()); | 555 base::Time::Now()); |
514 | 556 |
515 std::string output; | 557 std::string output; |
516 JSONStringValueSerializer serializer(&output); | 558 JSONStringValueSerializer serializer(&output); |
517 serializer.Serialize(*backoff); | 559 serializer.Serialize(*backoff); |
(...skipping 24 matching lines...) Expand all Loading... |
542 case UNREAD: | 584 case UNREAD: |
543 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 585 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
544 break; | 586 break; |
545 case UNSEEN: | 587 case UNSEEN: |
546 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); | 588 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); |
547 break; | 589 break; |
548 } | 590 } |
549 | 591 |
550 return pb_entry; | 592 return pb_entry; |
551 } | 593 } |
OLD | NEW |