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

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

Issue 2338133010: Add a TimeUntilNextTry to reading list (Closed)
Patch Set: Fix comments and tests 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 #include "base/memory/ptr_util.h"
8
9 const net::BackoffEntry::Policy ReadingListEntry::kBackoffPolicy = {
10 // Number of initial errors (in sequence) to ignore before applying
11 // exponential back-off rules.
12 0,
13
14 // Initial delay for exponential back-off in ms.
15 1000, // 1 second.
16
17 // Factor by which the waiting time will be multiplied.
18 2,
19
20 // Fuzzing percentage. ex: 10% will spread requests randomly
21 // between 90%-100% of the calculated time.
22 0, // 0%.
23
24 // Maximum amount of time we are willing to delay our request in ms.
25 120 * 1000, // 2 minutes.
26
27 // Time to keep an entry from being discarded even when it
28 // has no significant state, -1 to never discard.
29 -1,
30
31 false, // Don't use initial delay unless the last request was an error.
32 };
33
7 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title) 34 ReadingListEntry::ReadingListEntry(const GURL& url, const std::string& title)
35 : ReadingListEntry(url, title, nullptr){};
36
37 ReadingListEntry::ReadingListEntry(const GURL& url,
38 const std::string& title,
39 std::unique_ptr<net::BackoffEntry> backoff)
8 : url_(url), title_(title), distilled_state_(WAITING) { 40 : url_(url), title_(title), distilled_state_(WAITING) {
41 if (backoff) {
42 backoff_ = std::move(backoff);
43 } else {
44 backoff_ = base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy);
45 }
9 DCHECK(!url.is_empty()); 46 DCHECK(!url.is_empty());
10 DCHECK(url.is_valid()); 47 DCHECK(url.is_valid());
11 } 48 }
49
12 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry) 50 ReadingListEntry::ReadingListEntry(ReadingListEntry&& entry)
13 : url_(entry.URL()), 51 : url_(std::move(entry.url_)),
14 title_(entry.Title()), 52 title_(std::move(entry.title_)),
15 distilled_url_(entry.DistilledURL()), 53 distilled_url_(std::move(entry.distilled_url_)),
16 distilled_state_(entry.DistilledState()) {} 54 distilled_state_(std::move(entry.distilled_state_)),
55 backoff_(std::move(entry.backoff_)) {}
56
17 ReadingListEntry::~ReadingListEntry() {} 57 ReadingListEntry::~ReadingListEntry() {}
18 58
19 const GURL& ReadingListEntry::URL() const { 59 const GURL& ReadingListEntry::URL() const {
20 return url_; 60 return url_;
21 } 61 }
22 62
23 const std::string ReadingListEntry::Title() const { 63 const std::string& ReadingListEntry::Title() const {
24 return title_; 64 return title_;
25 } 65 }
26 66
27 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const { 67 ReadingListEntry::DistillationState ReadingListEntry::DistilledState() const {
28 return distilled_state_; 68 return distilled_state_;
29 } 69 }
30 70
31 const GURL& ReadingListEntry::DistilledURL() const { 71 const GURL& ReadingListEntry::DistilledURL() const {
32 return distilled_url_; 72 return distilled_url_;
33 } 73 }
34 74
75 base::TimeDelta ReadingListEntry::TimeUntilNextTry() const {
76 return backoff_->GetTimeUntilRelease();
77 }
78
35 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) { 79 ReadingListEntry& ReadingListEntry::operator=(ReadingListEntry&& other) {
36 url_ = other.url_; 80 url_ = std::move(other.url_);
37 title_ = other.title_; 81 title_ = std::move(other.title_);
38 distilled_url_ = other.distilled_url_; 82 distilled_url_ = std::move(other.distilled_url_);
39 distilled_state_ = other.distilled_state_; 83 distilled_state_ = std::move(other.distilled_state_);
84 backoff_ = std::move(other.backoff_);
40 return *this; 85 return *this;
41 } 86 }
42 87
43 bool ReadingListEntry::operator==(const ReadingListEntry& other) const { 88 bool ReadingListEntry::operator==(const ReadingListEntry& other) const {
44 return url_ == other.url_; 89 return url_ == other.url_;
45 } 90 }
46 91
47 void ReadingListEntry::SetTitle(const std::string& title) { 92 void ReadingListEntry::SetTitle(const std::string& title) {
48 title_ = title; 93 title_ = title;
49 } 94 }
50 95
51 void ReadingListEntry::SetDistilledURL(const GURL& url) { 96 void ReadingListEntry::SetDistilledURL(const GURL& url) {
52 DCHECK(url.is_valid()); 97 DCHECK(url.is_valid());
53 distilled_url_ = url; 98 distilled_url_ = url;
54 distilled_state_ = PROCESSED; 99 distilled_state_ = PROCESSED;
100 backoff_->Reset();
55 } 101 }
56 102
57 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { 103 void ReadingListEntry::SetDistilledState(DistillationState distilled_state) {
58 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead. 104 DCHECK(distilled_state != PROCESSED); // use SetDistilledURL instead.
59 DCHECK(distilled_state != WAITING); 105 DCHECK(distilled_state != WAITING);
106 // Increase time until next retry exponentially if the state change from a
107 // non-error state to an error state.
108 if ((distilled_state == WILL_RETRY || distilled_state == ERROR) &&
109 distilled_state_ != WILL_RETRY && distilled_state_ != ERROR) {
110 backoff_->InformOfRequest(false);
111 }
112
60 distilled_state_ = distilled_state; 113 distilled_state_ = distilled_state;
61 distilled_url_ = GURL(); 114 distilled_url_ = GURL();
62 } 115 }
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