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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_entry.cc

Issue 2338133010: Add a TimeUntilNextTry to reading list (Closed)
Patch Set: fixes Created 4 years, 3 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 "ios/chrome/browser/reading_list/reading_list_entry.h" 5 #include "ios/chrome/browser/reading_list/reading_list_entry.h"
6 6
7 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) 7 ReadingListEntry::ReadingListEntry(const GURL& url,
8 : url_(url), title_(title), distilled_state_(WAITING) { 8 const std::string& title,
9 base::TickClock* clock)
10 : url_(url),
11 title_(title),
12 distilled_state_(WAITING),
13 time_to_retry_(),
14 current_waiting_time_(base::TimeDelta::FromSeconds(1)),
15 clock_(clock) {
9 DCHECK(!url.is_empty()); 16 DCHECK(!url.is_empty());
10 DCHECK(url.is_valid()); 17 DCHECK(url.is_valid());
11 } 18 }
12 ReadingListEntry::ReadingListEntry(const ReadingListEntry& entry) 19
13 : url_(entry.URL()), 20 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title)
14 title_(entry.Title()), 21 : ReadingListEntry(url, title, nullptr) {}
15 distilled_url_(entry.DistilledURL()), 22
16 distilled_state_(entry.DistilledState()) {} 23 ReadingListEntry::ReadingListEntry(const ReadingListEntry& entry) = default;
24
17 ReadingListEntry::~ReadingListEntry() {} 25 ReadingListEntry::~ReadingListEntry() {}
18 26
19 const GURL& ReadingListEntry::URL() const { 27 const GURL& ReadingListEntry::URL() const {
20 return url_; 28 return url_;
21 } 29 }
22 30
23 const std::string ReadingListEntry::Title() const { 31 const std::string& ReadingListEntry::Title() const {
24 return title_; 32 return title_;
25 } 33 }
26 34
27 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { 35 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const {
28 return distilled_state_; 36 return distilled_state_;
29 } 37 }
30 38
31 const GURL& ReadingListEntry::DistilledURL() const { 39 const GURL& ReadingListEntry::DistilledURL() const {
32 return distilled_url_; 40 return distilled_url_;
33 } 41 }
34 42
43 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const {
44 base::TimeTicks now = GetTimeTicksNow();
45 if (now > time_to_retry_)
46 return base::TimeDelta();
47 return time_to_retry_ - now;
48 }
49
35 ReadingListEntry& ReadingListEntry::operator=(const ReadingListEntry& other) { 50 ReadingListEntry& ReadingListEntry::operator=(const ReadingListEntry& other) {
36 url_ = other.url_; 51 url_ = other.url_;
37 title_ = other.title_; 52 title_ = other.title_;
38 distilled_url_ = other.distilled_url_; 53 distilled_url_ = other.distilled_url_;
39 distilled_state_ = other.distilled_state_; 54 distilled_state_ = other.distilled_state_;
55 time_to_retry_ = other.time_to_retry_;
56 current_waiting_time_ = other.current_waiting_time_;
57 clock_ = other.clock_;
gambard 2016/09/19 09:08:09 I am not sure about this pointer copy and the one
noyau (Ping after 24h) 2016/09/19 09:19:54 The ownership of clock is very unclear and needs f
gambard 2016/09/19 15:33:02 I moved to a different model.
40 return *this; 58 return *this;
41 } 59 }
42 60
43 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { 61 bool ReadingListEntry::operator==(const ReadingListEntry& other) const {
44 return url_ == other.url_; 62 return url_ == other.url_;
45 } 63 }
46 64
47 void ReadingListEntry::SetTitle(const std::string& title) { 65 void ReadingListEntry::SetTitle(const std::string& title) {
48 title_ = title; 66 title_ = title;
49 } 67 }
50 68
51 void ReadingListEntry::SetDistilledURL(const GURL& url) { 69 void ReadingListEntry::SetDistilledURL(const GURL& url) {
52 DCHECK(url.is_valid()); 70 DCHECK(url.is_valid());
53 distilled_url_ = url; 71 distilled_url_ = url;
54 distilled_state_ = PROCESSED; 72 distilled_state_ = PROCESSED;
73 time_to_retry_ = base::TimeTicks();
74 current_waiting_time_ = base::TimeDelta();
55 } 75 }
56 76
57 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { 77 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) {
58 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. 78 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead.
59 DCHECK(distilled_state != WAITING); 79 DCHECK(distilled_state != WAITING);
80 // Increase time until next retry exponentially if the state change from a
81 // non-error state to an error state.
82 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) &&
83 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) {
84 time_to_retry_ = GetTimeTicksNow() + current_waiting_time_;
85 current_waiting_time_ =
86 ReadingListEntry::NextWaitingTime(current_waiting_time_);
87 }
88
60 distilled_state_ = distilled_state; 89 distilled_state_ = distilled_state;
61 distilled_url_ = GURL(); 90 distilled_url_ = GURL();
62 } 91 }
92
93 base::TimeTicks ReadingListEntry::GetTimeTicksNow() const {
94 return clock_ ? clock_->NowTicks() : base::TimeTicks::Now();
95 }
96
97 base::TimeDelta ReadingListEntry::NextWaitingTime(
98 base::TimeDelta currentWaitingTime) {
99 return currentWaitingTime * 2;
100 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_entry.h ('k') | ios/chrome/browser/reading_list/reading_list_entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698