Chromium Code Reviews| 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 namespace { | |
| 10 // URL used to open offline pages. | |
|
jif-google
2016/11/10 15:48:24
To be more exact:
// Scheme and prefix used to ope
jif-google
2016/11/10 15:51:35
I'm wrong, "chrome://offline/" is actually a URL.
| |
| 11 // This variable will be moved to chrome_url_constants. | |
| 12 const char kChromeUIOfflineURL[] = "chrome://offline/"; | |
| 13 } | |
| 14 | |
| 9 // The backoff time is the following: 10min, 10min, 1h, 2h, 2h..., starting | 15 // The backoff time is the following: 10min, 10min, 1h, 2h, 2h..., starting |
| 10 // after the first failure. | 16 // after the first failure. |
| 11 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { | 17 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = { |
| 12 // Number of initial errors (in sequence) to ignore before applying | 18 // Number of initial errors (in sequence) to ignore before applying |
| 13 // exponential back-off rules. | 19 // exponential back-off rules. |
| 14 2, | 20 2, |
| 15 | 21 |
| 16 // Initial delay for exponential back-off in ms. | 22 // Initial delay for exponential back-off in ms. |
| 17 10 * 60 * 1000, // 10 minutes. | 23 10 * 60 * 1000, // 10 minutes. |
| 18 | 24 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 48 } else { | 54 } else { |
| 49 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); | 55 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy); |
| 50 } | 56 } |
| 51 DCHECK(!url.is_empty()); | 57 DCHECK(!url.is_empty()); |
| 52 DCHECK(url.is_valid()); | 58 DCHECK(url.is_valid()); |
| 53 } | 59 } |
| 54 | 60 |
| 55 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) | 61 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) |
| 56 : url_(std::move(entry.url_)), | 62 : url_(std::move(entry.url_)), |
| 57 title_(std::move(entry.title_)), | 63 title_(std::move(entry.title_)), |
| 58 distilled_url_(std::move(entry.distilled_url_)), | 64 distilled_path_(std::move(entry.distilled_path_)), |
| 59 distilled_state_(std::move(entry.distilled_state_)), | 65 distilled_state_(std::move(entry.distilled_state_)), |
| 60 backoff_(std::move(entry.backoff_)), | 66 backoff_(std::move(entry.backoff_)), |
| 61 failed_download_counter_(std::move(entry.failed_download_counter_)) {} | 67 failed_download_counter_(std::move(entry.failed_download_counter_)) {} |
| 62 | 68 |
| 63 ReadingListEntry::~ReadingListEntry() {} | 69 ReadingListEntry::~ReadingListEntry() {} |
| 64 | 70 |
| 65 const GURL& ReadingListEntry::URL() const { | 71 const GURL& ReadingListEntry::URL() const { |
| 66 return url_; | 72 return url_; |
| 67 } | 73 } |
| 68 | 74 |
| 69 const std::string& ReadingListEntry::Title() const { | 75 const std::string& ReadingListEntry::Title() const { |
| 70 return title_; | 76 return title_; |
| 71 } | 77 } |
| 72 | 78 |
| 73 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { | 79 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { |
| 74 return distilled_state_; | 80 return distilled_state_; |
| 75 } | 81 } |
| 76 | 82 |
| 77 const GURL& ReadingListEntry::DistilledURL() const { | 83 const base::FilePath& ReadingListEntry::DistilledPath() const { |
| 78 return distilled_url_; | 84 return distilled_path_; |
| 85 } | |
| 86 | |
| 87 const GURL ReadingListEntry::DistilledURL() const { | |
| 88 if (distilled_path_.empty()) { | |
| 89 return GURL(); | |
| 90 } | |
| 91 return GURL(kChromeUIOfflineURL + distilled_path_.value()); | |
| 79 } | 92 } |
| 80 | 93 |
| 81 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { | 94 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const { |
| 82 return backoff_->GetTimeUntilRelease(); | 95 return backoff_->GetTimeUntilRelease(); |
| 83 } | 96 } |
| 84 | 97 |
| 85 int ReadingListEntry::FailedDownloadCounter() const { | 98 int ReadingListEntry::FailedDownloadCounter() const { |
| 86 return failed_download_counter_; | 99 return failed_download_counter_; |
| 87 } | 100 } |
| 88 | 101 |
| 89 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { | 102 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { |
| 90 url_ = std::move(other.url_); | 103 url_ = std::move(other.url_); |
| 91 title_ = std::move(other.title_); | 104 title_ = std::move(other.title_); |
| 92 distilled_url_ = std::move(other.distilled_url_); | 105 distilled_path_ = std::move(other.distilled_path_); |
| 93 distilled_state_ = std::move(other.distilled_state_); | 106 distilled_state_ = std::move(other.distilled_state_); |
| 94 backoff_ = std::move(other.backoff_); | 107 backoff_ = std::move(other.backoff_); |
| 95 failed_download_counter_ = std::move(other.failed_download_counter_); | 108 failed_download_counter_ = std::move(other.failed_download_counter_); |
| 96 return *this; | 109 return *this; |
| 97 } | 110 } |
| 98 | 111 |
| 99 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { | 112 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { |
| 100 return url_ == other.url_; | 113 return url_ == other.url_; |
| 101 } | 114 } |
| 102 | 115 |
| 103 void ReadingListEntry::SetTitle(const std::string& title) { | 116 void ReadingListEntry::SetTitle(const std::string& title) { |
| 104 title_ = title; | 117 title_ = title; |
| 105 } | 118 } |
| 106 | 119 |
| 107 void ReadingListEntry::SetDistilledURL(const GURL& url) { | 120 void ReadingListEntry::SetDistilledPath(const base::FilePath& path) { |
| 108 DCHECK(url.is_valid()); | 121 DCHECK(!path.empty()); |
| 109 distilled_url_ = url; | 122 distilled_path_ = path; |
| 110 distilled_state_ = PROCESSED; | 123 distilled_state_ = PROCESSED; |
| 111 backoff_->Reset(); | 124 backoff_->Reset(); |
| 112 failed_download_counter_ = 0; | 125 failed_download_counter_ = 0; |
| 113 } | 126 } |
| 114 | 127 |
| 115 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { | 128 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { |
| 116 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. | 129 DCHECK(distilled_state != PROCESSED); // use SetDistilledPath instead. |
| 117 DCHECK(distilled_state != WAITING); | 130 DCHECK(distilled_state != WAITING); |
| 118 // Increase time until next retry exponentially if the state change from a | 131 // Increase time until next retry exponentially if the state change from a |
| 119 // non-error state to an error state. | 132 // non-error state to an error state. |
| 120 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && | 133 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) && |
| 121 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { | 134 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) { |
| 122 backoff_->InformOfRequest(false); | 135 backoff_->InformOfRequest(false); |
| 123 failed_download_counter_++; | 136 failed_download_counter_++; |
| 124 } | 137 } |
| 125 | 138 |
| 126 distilled_state_ = distilled_state; | 139 distilled_state_ = distilled_state; |
| 127 distilled_url_ = GURL(); | 140 distilled_path_ = base::FilePath(); |
| 128 } | 141 } |
| OLD | NEW |