Chromium Code Reviews| Index: ios/chrome/browser/reading_list/reading_list_entry.cc |
| diff --git a/ios/chrome/browser/reading_list/reading_list_entry.cc b/ios/chrome/browser/reading_list/reading_list_entry.cc |
| index 62fa14300bc4f9b724d7bb7152295b44d6878eb9..64b618f1505687a7954b035a5bcce89d5ac8865f 100644 |
| --- a/ios/chrome/browser/reading_list/reading_list_entry.cc |
| +++ b/ios/chrome/browser/reading_list/reading_list_entry.cc |
| @@ -4,23 +4,31 @@ |
| #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| -ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) |
| - : url_(url), title_(title), distilled_state_(WAITING) { |
| +ReadingListEntry::ReadingListEntry(const GURL& url, |
| + const std::string& title, |
| + base::TickClock* clock) |
| + : url_(url), |
| + title_(title), |
| + distilled_state_(WAITING), |
| + time_to_retry_(), |
| + current_waiting_time_(base::TimeDelta::FromSeconds(1)), |
| + clock_(clock) { |
| DCHECK(!url.is_empty()); |
| DCHECK(url.is_valid()); |
| } |
| -ReadingListEntry::ReadingListEntry(const ReadingListEntry& entry) |
| - : url_(entry.URL()), |
| - title_(entry.Title()), |
| - distilled_url_(entry.DistilledURL()), |
| - distilled_state_(entry.DistilledState()) {} |
| + |
| +ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) |
| + : ReadingListEntry(url, title, nullptr) {} |
| + |
| +ReadingListEntry::ReadingListEntry(const ReadingListEntry& entry) = default; |
| + |
| ReadingListEntry::~ReadingListEntry() {} |
| const GURL& ReadingListEntry::URL() const { |
| return url_; |
| } |
| -const std::string ReadingListEntry::Title() const { |
| +const std::string& ReadingListEntry::Title() const { |
| return title_; |
| } |
| @@ -32,11 +40,21 @@ const GURL& ReadingListEntry::DistilledURL() const { |
| return distilled_url_; |
| } |
| +base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { |
| + base::TimeTicks now = GetTimeTicksNow(); |
| + if (now > time_to_retry_) |
| + return base::TimeDelta(); |
| + return time_to_retry_ - now; |
| +} |
| + |
| ReadingListEntry& ReadingListEntry::operator=(const ReadingListEntry& other) { |
| url_ = other.url_; |
| title_ = other.title_; |
| distilled_url_ = other.distilled_url_; |
| distilled_state_ = other.distilled_state_; |
| + time_to_retry_ = other.time_to_retry_; |
| + current_waiting_time_ = other.current_waiting_time_; |
| + 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.
|
| return *this; |
| } |
| @@ -52,11 +70,31 @@ void ReadingListEntry::SetDistilledURL(const GURL& url) { |
| DCHECK(url.is_valid()); |
| distilled_url_ = url; |
| distilled_state_ = PROCESSED; |
| + time_to_retry_ = base::TimeTicks(); |
| + current_waiting_time_ = base::TimeDelta(); |
| } |
| void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { |
| DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. |
| DCHECK(distilled_state != WAITING); |
| + // Increase time until next retry exponentially if the state change from a |
| + // non-error state to an error state. |
| + if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && |
| + distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { |
| + time_to_retry_ = GetTimeTicksNow() + current_waiting_time_; |
| + current_waiting_time_ = |
| + ReadingListEntry::NextWaitingTime(current_waiting_time_); |
| + } |
| + |
| distilled_state_ = distilled_state; |
| distilled_url_ = GURL(); |
| } |
| + |
| +base::TimeTicks ReadingListEntry::GetTimeTicksNow() const { |
| + return clock_ ? clock_->NowTicks() : base::TimeTicks::Now(); |
| +} |
| + |
| +base::TimeDelta ReadingListEntry::NextWaitingTime( |
| + base::TimeDelta currentWaitingTime) { |
| + return currentWaitingTime * 2; |
| +} |