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

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

Issue 2647763005: Store the distilled_url in Reading List entry in Reading List on iOS. (Closed)
Patch Set: feedback Created 3 years, 11 months 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 std::unique_ptr<net::BackoffEntry> backoff) 47 std::unique_ptr<net::BackoffEntry> backoff)
48 : ReadingListEntry(url, 48 : ReadingListEntry(url,
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 0, 58 0,
58 std::move(backoff)) {} 59 std::move(backoff)) {}
59 60
60 ReadingListEntry::ReadingListEntry( 61 ReadingListEntry::ReadingListEntry(
61 const GURL& url, 62 const GURL& url,
62 const std::string& title, 63 const std::string& title,
63 State state, 64 State state,
64 int64_t creation_time, 65 int64_t creation_time,
65 int64_t first_read_time, 66 int64_t first_read_time,
66 int64_t update_time, 67 int64_t update_time,
67 int64_t update_title_time, 68 int64_t update_title_time,
68 ReadingListEntry::DistillationState distilled_state, 69 ReadingListEntry::DistillationState distilled_state,
69 const base::FilePath& distilled_path, 70 const base::FilePath& distilled_path,
71 const GURL& distilled_url,
70 int failed_download_counter, 72 int failed_download_counter,
71 std::unique_ptr<net::BackoffEntry> backoff) 73 std::unique_ptr<net::BackoffEntry> backoff)
72 : url_(url), 74 : url_(url),
73 title_(title), 75 title_(title),
74 state_(state), 76 state_(state),
75 distilled_path_(distilled_path), 77 distilled_path_(distilled_path),
78 distilled_url_(distilled_url),
76 distilled_state_(distilled_state), 79 distilled_state_(distilled_state),
77 failed_download_counter_(failed_download_counter), 80 failed_download_counter_(failed_download_counter),
78 creation_time_us_(creation_time), 81 creation_time_us_(creation_time),
79 first_read_time_us_(first_read_time), 82 first_read_time_us_(first_read_time),
80 update_time_us_(update_time), 83 update_time_us_(update_time),
81 update_title_time_us_(update_title_time) { 84 update_title_time_us_(update_title_time) {
82 if (backoff) { 85 if (backoff) {
83 backoff_ = std::move(backoff); 86 backoff_ = std::move(backoff);
84 } else { 87 } else {
85 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); 88 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy);
86 } 89 }
87 if (creation_time_us_ == 0) { 90 if (creation_time_us_ == 0) {
88 DCHECK(update_time_us_ == 0); 91 DCHECK(update_time_us_ == 0);
89 DCHECK(update_title_time_us_ == 0); 92 DCHECK(update_title_time_us_ == 0);
90 creation_time_us_ = 93 creation_time_us_ =
91 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); 94 (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
92 update_time_us_ = creation_time_us_; 95 update_time_us_ = creation_time_us_;
93 update_title_time_us_ = creation_time_us_; 96 update_title_time_us_ = creation_time_us_;
94 } 97 }
95 DCHECK(!url.is_empty()); 98 DCHECK(!url.is_empty());
96 DCHECK(url.is_valid()); 99 DCHECK(url.is_valid());
97 } 100 }
98 101
99 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) 102 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry)
100 : url_(std::move(entry.url_)), 103 : url_(std::move(entry.url_)),
101 title_(std::move(entry.title_)), 104 title_(std::move(entry.title_)),
102 state_(std::move(entry.state_)), 105 state_(std::move(entry.state_)),
103 distilled_path_(std::move(entry.distilled_path_)), 106 distilled_path_(std::move(entry.distilled_path_)),
107 distilled_url_(std::move(entry.distilled_url_)),
104 distilled_state_(std::move(entry.distilled_state_)), 108 distilled_state_(std::move(entry.distilled_state_)),
105 backoff_(std::move(entry.backoff_)), 109 backoff_(std::move(entry.backoff_)),
106 failed_download_counter_(std::move(entry.failed_download_counter_)), 110 failed_download_counter_(std::move(entry.failed_download_counter_)),
107 creation_time_us_(std::move(entry.creation_time_us_)), 111 creation_time_us_(std::move(entry.creation_time_us_)),
108 first_read_time_us_(std::move(entry.first_read_time_us_)), 112 first_read_time_us_(std::move(entry.first_read_time_us_)),
109 update_time_us_(std::move(entry.update_time_us_)), 113 update_time_us_(std::move(entry.update_time_us_)),
110 update_title_time_us_(std::move(entry.update_title_time_us_)) {} 114 update_title_time_us_(std::move(entry.update_title_time_us_)) {}
111 115
112 ReadingListEntry::~ReadingListEntry() {} 116 ReadingListEntry::~ReadingListEntry() {}
113 117
114 const GURL& ReadingListEntry::URL() const { 118 const GURL& ReadingListEntry::URL() const {
115 return url_; 119 return url_;
116 } 120 }
117 121
118 const std::string& ReadingListEntry::Title() const { 122 const std::string& ReadingListEntry::Title() const {
119 return title_; 123 return title_;
120 } 124 }
121 125
122 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { 126 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const {
123 return distilled_state_; 127 return distilled_state_;
124 } 128 }
125 129
126 const base::FilePath& ReadingListEntry::DistilledPath() const { 130 const base::FilePath& ReadingListEntry::DistilledPath() const {
127 return distilled_path_; 131 return distilled_path_;
128 } 132 }
129 133
134 const GURL& ReadingListEntry::DistilledURL() const {
135 return distilled_url_;
136 }
137
130 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { 138 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const {
131 return backoff_->GetTimeUntilRelease(); 139 return backoff_->GetTimeUntilRelease();
132 } 140 }
133 141
134 int ReadingListEntry::FailedDownloadCounter() const { 142 int ReadingListEntry::FailedDownloadCounter() const {
135 return failed_download_counter_; 143 return failed_download_counter_;
136 } 144 }
137 145
138 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { 146 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) {
139 url_ = std::move(other.url_); 147 url_ = std::move(other.url_);
140 title_ = std::move(other.title_); 148 title_ = std::move(other.title_);
141 distilled_path_ = std::move(other.distilled_path_); 149 distilled_path_ = std::move(other.distilled_path_);
150 distilled_url_ = std::move(other.distilled_url_);
142 distilled_state_ = std::move(other.distilled_state_); 151 distilled_state_ = std::move(other.distilled_state_);
143 backoff_ = std::move(other.backoff_); 152 backoff_ = std::move(other.backoff_);
144 state_ = std::move(other.state_); 153 state_ = std::move(other.state_);
145 failed_download_counter_ = std::move(other.failed_download_counter_); 154 failed_download_counter_ = std::move(other.failed_download_counter_);
146 creation_time_us_ = std::move(other.creation_time_us_); 155 creation_time_us_ = std::move(other.creation_time_us_);
147 first_read_time_us_ = std::move(other.first_read_time_us_); 156 first_read_time_us_ = std::move(other.first_read_time_us_);
148 update_time_us_ = std::move(other.update_time_us_); 157 update_time_us_ = std::move(other.update_time_us_);
149 update_title_time_us_ = std::move(other.update_title_time_us_); 158 update_title_time_us_ = std::move(other.update_title_time_us_);
150 return *this; 159 return *this;
151 } 160 }
(...skipping 26 matching lines...) Expand all
178 } 187 }
179 188
180 bool ReadingListEntry::IsRead() const { 189 bool ReadingListEntry::IsRead() const {
181 return state_ == READ; 190 return state_ == READ;
182 } 191 }
183 192
184 bool ReadingListEntry::HasBeenSeen() const { 193 bool ReadingListEntry::HasBeenSeen() const {
185 return state_ != UNSEEN; 194 return state_ != UNSEEN;
186 } 195 }
187 196
188 void ReadingListEntry::SetDistilledPath(const base::FilePath& path) { 197 void ReadingListEntry::SetDistilledInfo(const base::FilePath& path,
198 const GURL& distilled_url) {
189 DCHECK(!path.empty()); 199 DCHECK(!path.empty());
200 DCHECK(distilled_url.is_valid());
190 distilled_path_ = path; 201 distilled_path_ = path;
191 distilled_state_ = PROCESSED; 202 distilled_state_ = PROCESSED;
203 distilled_url_ = distilled_url;
192 backoff_->Reset(); 204 backoff_->Reset();
193 failed_download_counter_ = 0; 205 failed_download_counter_ = 0;
194 } 206 }
195 207
196 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { 208 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) {
197 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. 209 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead.
198 DCHECK(distilled_state != WAITING); 210 DCHECK(distilled_state != WAITING);
199 // Increase time until next retry exponentially if the state change from a 211 // Increase time until next retry exponentially if the state change from a
200 // non-error state to an error state. 212 // non-error state to an error state.
201 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && 213 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) &&
202 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { 214 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) {
203 backoff_->InformOfRequest(false); 215 backoff_->InformOfRequest(false);
204 failed_download_counter_++; 216 failed_download_counter_++;
205 } 217 }
206 218
207 distilled_state_ = distilled_state; 219 distilled_state_ = distilled_state;
208 distilled_path_ = base::FilePath(); 220 distilled_path_ = base::FilePath();
221 distilled_url_ = GURL::EmptyGURL();
209 } 222 }
210 223
211 int64_t ReadingListEntry::UpdateTime() const { 224 int64_t ReadingListEntry::UpdateTime() const {
212 return update_time_us_; 225 return update_time_us_;
213 } 226 }
214 227
215 int64_t ReadingListEntry::UpdateTitleTime() const { 228 int64_t ReadingListEntry::UpdateTitleTime() const {
216 return update_title_time_us_; 229 return update_title_time_us_;
217 } 230 }
218 231
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 distillation_state = ReadingListEntry::ERROR; 312 distillation_state = ReadingListEntry::ERROR;
300 break; 313 break;
301 } 314 }
302 } 315 }
303 316
304 base::FilePath distilled_path; 317 base::FilePath distilled_path;
305 if (pb_entry.has_distilled_path()) { 318 if (pb_entry.has_distilled_path()) {
306 distilled_path = base::FilePath(pb_entry.distilled_path()); 319 distilled_path = base::FilePath(pb_entry.distilled_path());
307 } 320 }
308 321
322 GURL distilled_url;
323 if (pb_entry.has_distilled_url()) {
324 distilled_url = GURL(pb_entry.distilled_url());
325 }
326
309 int64_t failed_download_counter = 0; 327 int64_t failed_download_counter = 0;
310 if (pb_entry.has_failed_download_counter()) { 328 if (pb_entry.has_failed_download_counter()) {
311 failed_download_counter = pb_entry.failed_download_counter(); 329 failed_download_counter = pb_entry.failed_download_counter();
312 } 330 }
313 331
314 std::unique_ptr<net::BackoffEntry> backoff; 332 std::unique_ptr<net::BackoffEntry> backoff;
315 if (pb_entry.has_backoff()) { 333 if (pb_entry.has_backoff()) {
316 JSONStringValueDeserializer deserializer(pb_entry.backoff()); 334 JSONStringValueDeserializer deserializer(pb_entry.backoff());
317 std::unique_ptr<base::Value> value( 335 std::unique_ptr<base::Value> value(
318 deserializer.Deserialize(nullptr, nullptr)); 336 deserializer.Deserialize(nullptr, nullptr));
319 if (value) { 337 if (value) {
320 backoff = net::BackoffEntrySerializer::DeserializeFromValue( 338 backoff = net::BackoffEntrySerializer::DeserializeFromValue(
321 *value, &kBackoffPolicy, nullptr, base::Time::Now()); 339 *value, &kBackoffPolicy, nullptr, base::Time::Now());
322 } 340 }
323 } 341 }
324 342
325 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( 343 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry(
326 url, title, state, creation_time_us, first_read_time_us, update_time_us, 344 url, title, state, creation_time_us, first_read_time_us, update_time_us,
327 update_title_time_us, distillation_state, distilled_path, 345 update_title_time_us, distillation_state, distilled_path, distilled_url,
328 failed_download_counter, std::move(backoff))); 346 failed_download_counter, std::move(backoff)));
329 } 347 }
330 348
331 // static 349 // static
332 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics( 350 std::unique_ptr<ReadingListEntry> ReadingListEntry::FromReadingListSpecifics(
333 const sync_pb::ReadingListSpecifics& pb_entry) { 351 const sync_pb::ReadingListSpecifics& pb_entry) {
334 if (!pb_entry.has_url()) { 352 if (!pb_entry.has_url()) {
335 return nullptr; 353 return nullptr;
336 } 354 }
337 GURL url(pb_entry.url()); 355 GURL url(pb_entry.url());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 state = UNREAD; 391 state = UNREAD;
374 break; 392 break;
375 case sync_pb::ReadingListSpecifics::UNSEEN: 393 case sync_pb::ReadingListSpecifics::UNSEEN:
376 state = UNSEEN; 394 state = UNSEEN;
377 break; 395 break;
378 } 396 }
379 } 397 }
380 398
381 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry( 399 return base::WrapUnique<ReadingListEntry>(new ReadingListEntry(
382 url, title, state, creation_time_us, first_read_time_us, update_time_us, 400 url, title, state, creation_time_us, first_read_time_us, update_time_us,
383 update_title_time_us, WAITING, base::FilePath(), 0, nullptr)); 401 update_title_time_us, WAITING, base::FilePath(), GURL(), 0, nullptr));
384 } 402 }
385 403
386 void ReadingListEntry::MergeWithEntry(const ReadingListEntry& other) { 404 void ReadingListEntry::MergeWithEntry(const ReadingListEntry& other) {
387 #if !defined(NDEBUG) 405 #if !defined(NDEBUG)
388 // Checks that the result entry respects the sync order. 406 // Checks that the result entry respects the sync order.
389 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb( 407 std::unique_ptr<sync_pb::ReadingListSpecifics> old_this_pb(
390 AsReadingListSpecifics()); 408 AsReadingListSpecifics());
391 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb( 409 std::unique_ptr<sync_pb::ReadingListSpecifics> other_pb(
392 other.AsReadingListSpecifics()); 410 other.AsReadingListSpecifics());
393 #endif 411 #endif
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 distilation_state = reading_list::ReadingListLocal::WILL_RETRY; 495 distilation_state = reading_list::ReadingListLocal::WILL_RETRY;
478 break; 496 break;
479 case ReadingListEntry::ERROR: 497 case ReadingListEntry::ERROR:
480 distilation_state = reading_list::ReadingListLocal::ERROR; 498 distilation_state = reading_list::ReadingListLocal::ERROR;
481 break; 499 break;
482 } 500 }
483 pb_entry->set_distillation_state(distilation_state); 501 pb_entry->set_distillation_state(distilation_state);
484 if (!DistilledPath().empty()) { 502 if (!DistilledPath().empty()) {
485 pb_entry->set_distilled_path(DistilledPath().value()); 503 pb_entry->set_distilled_path(DistilledPath().value());
486 } 504 }
505 if (DistilledURL().is_valid()) {
506 pb_entry->set_distilled_url(DistilledURL().spec());
507 }
487 pb_entry->set_failed_download_counter(failed_download_counter_); 508 pb_entry->set_failed_download_counter(failed_download_counter_);
488 509
489 if (backoff_) { 510 if (backoff_) {
490 std::unique_ptr<base::Value> backoff = 511 std::unique_ptr<base::Value> backoff =
491 net::BackoffEntrySerializer::SerializeToValue(*backoff_, 512 net::BackoffEntrySerializer::SerializeToValue(*backoff_,
492 base::Time::Now()); 513 base::Time::Now());
493 514
494 std::string output; 515 std::string output;
495 JSONStringValueSerializer serializer(&output); 516 JSONStringValueSerializer serializer(&output);
496 serializer.Serialize(*backoff); 517 serializer.Serialize(*backoff);
(...skipping 24 matching lines...) Expand all
521 case UNREAD: 542 case UNREAD:
522 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); 543 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD);
523 break; 544 break;
524 case UNSEEN: 545 case UNSEEN:
525 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN); 546 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNSEEN);
526 break; 547 break;
527 } 548 }
528 549
529 return pb_entry; 550 return pb_entry;
530 } 551 }
OLDNEW
« no previous file with comments | « components/reading_list/ios/reading_list_entry.h ('k') | components/reading_list/ios/reading_list_entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698