| 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 "ios/chrome/browser/reading_list/reading_list_entry.h" | 5 #include "ios/chrome/browser/reading_list/reading_list_entry.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 | 8 |
| 9 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { | 9 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { |
| 10 // Number of initial errors (in sequence) to ignore before applying | 10 // Number of initial errors (in sequence) to ignore before applying |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 false, // Don't use initial delay unless the last request was an error. | 31 false, // Don't use initial delay unless the last request was an error. |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) | 34 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) |
| 35 : ReadingListEntry(url, title, nullptr){}; | 35 : ReadingListEntry(url, title, nullptr){}; |
| 36 | 36 |
| 37 ReadingListEntry::ReadingListEntry(const GURL& url, | 37 ReadingListEntry::ReadingListEntry(const GURL& url, |
| 38 const std::string& title, | 38 const std::string& title, |
| 39 std::unique_ptr<net::BackoffEntry> backoff) | 39 std::unique_ptr<net::BackoffEntry> backoff) |
| 40 : url_(url), title_(title), distilled_state_(WAITING) { | 40 : url_(url), |
| 41 title_(title), |
| 42 distilled_state_(WAITING), |
| 43 failed_download_counter_(0) { |
| 41 if (backoff) { | 44 if (backoff) { |
| 42 backoff_ = std::move(backoff); | 45 backoff_ = std::move(backoff); |
| 43 } else { | 46 } else { |
| 44 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); | 47 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); |
| 45 } | 48 } |
| 46 DCHECK(!url.is_empty()); | 49 DCHECK(!url.is_empty()); |
| 47 DCHECK(url.is_valid()); | 50 DCHECK(url.is_valid()); |
| 48 } | 51 } |
| 49 | 52 |
| 50 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) | 53 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) |
| 51 : url_(std::move(entry.url_)), | 54 : url_(std::move(entry.url_)), |
| 52 title_(std::move(entry.title_)), | 55 title_(std::move(entry.title_)), |
| 53 distilled_url_(std::move(entry.distilled_url_)), | 56 distilled_url_(std::move(entry.distilled_url_)), |
| 54 distilled_state_(std::move(entry.distilled_state_)), | 57 distilled_state_(std::move(entry.distilled_state_)), |
| 55 backoff_(std::move(entry.backoff_)) {} | 58 backoff_(std::move(entry.backoff_)), |
| 59 failed_download_counter_(std::move(entry.failed_download_counter_)) {} |
| 56 | 60 |
| 57 ReadingListEntry::~ReadingListEntry() {} | 61 ReadingListEntry::~ReadingListEntry() {} |
| 58 | 62 |
| 59 const GURL& ReadingListEntry::URL() const { | 63 const GURL& ReadingListEntry::URL() const { |
| 60 return url_; | 64 return url_; |
| 61 } | 65 } |
| 62 | 66 |
| 63 const std::string& ReadingListEntry::Title() const { | 67 const std::string& ReadingListEntry::Title() const { |
| 64 return title_; | 68 return title_; |
| 65 } | 69 } |
| 66 | 70 |
| 67 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { | 71 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { |
| 68 return distilled_state_; | 72 return distilled_state_; |
| 69 } | 73 } |
| 70 | 74 |
| 71 const GURL& ReadingListEntry::DistilledURL() const { | 75 const GURL& ReadingListEntry::DistilledURL() const { |
| 72 return distilled_url_; | 76 return distilled_url_; |
| 73 } | 77 } |
| 74 | 78 |
| 75 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { | 79 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { |
| 76 return backoff_->GetTimeUntilRelease(); | 80 return backoff_->GetTimeUntilRelease(); |
| 77 } | 81 } |
| 78 | 82 |
| 83 int ReadingListEntry::FailedDownloadCounter() const { |
| 84 return failed_download_counter_; |
| 85 } |
| 86 |
| 79 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { | 87 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { |
| 80 url_ = std::move(other.url_); | 88 url_ = std::move(other.url_); |
| 81 title_ = std::move(other.title_); | 89 title_ = std::move(other.title_); |
| 82 distilled_url_ = std::move(other.distilled_url_); | 90 distilled_url_ = std::move(other.distilled_url_); |
| 83 distilled_state_ = std::move(other.distilled_state_); | 91 distilled_state_ = std::move(other.distilled_state_); |
| 84 backoff_ = std::move(other.backoff_); | 92 backoff_ = std::move(other.backoff_); |
| 93 failed_download_counter_ = std::move(other.failed_download_counter_); |
| 85 return *this; | 94 return *this; |
| 86 } | 95 } |
| 87 | 96 |
| 88 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { | 97 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { |
| 89 return url_ == other.url_; | 98 return url_ == other.url_; |
| 90 } | 99 } |
| 91 | 100 |
| 92 void ReadingListEntry::SetTitle(const std::string& title) { | 101 void ReadingListEntry::SetTitle(const std::string& title) { |
| 93 title_ = title; | 102 title_ = title; |
| 94 } | 103 } |
| 95 | 104 |
| 96 void ReadingListEntry::SetDistilledURL(const GURL& url) { | 105 void ReadingListEntry::SetDistilledURL(const GURL& url) { |
| 97 DCHECK(url.is_valid()); | 106 DCHECK(url.is_valid()); |
| 98 distilled_url_ = url; | 107 distilled_url_ = url; |
| 99 distilled_state_ = PROCESSED; | 108 distilled_state_ = PROCESSED; |
| 100 backoff_->Reset(); | 109 backoff_->Reset(); |
| 110 failed_download_counter_ = 0; |
| 101 } | 111 } |
| 102 | 112 |
| 103 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { | 113 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { |
| 104 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. | 114 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. |
| 105 DCHECK(distilled_state != WAITING); | 115 DCHECK(distilled_state != WAITING); |
| 106 // Increase time until next retry exponentially if the state change from a | 116 // Increase time until next retry exponentially if the state change from a |
| 107 // non-error state to an error state. | 117 // non-error state to an error state. |
| 108 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && | 118 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && |
| 109 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { | 119 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { |
| 110 backoff_->InformOfRequest(false); | 120 backoff_->InformOfRequest(false); |
| 121 failed_download_counter_++; |
| 111 } | 122 } |
| 112 | 123 |
| 113 distilled_state_ = distilled_state; | 124 distilled_state_ = distilled_state; |
| 114 distilled_url_ = GURL(); | 125 distilled_url_ = GURL(); |
| 115 } | 126 } |
| OLD | NEW |