| 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 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "net/base/backoff_entry.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 // An entry in the reading list. The URL is a unique identifier for an entry, as | 14 // An entry in the reading list. The URL is a unique identifier for an entry, as |
| 14 // such it should not be empty and is the only thing considered when comparing | 15 // such it should not be empty and is the only thing considered when comparing |
| 15 // entries. | 16 // entries. |
| 16 class ReadingListEntry { | 17 class ReadingListEntry { |
| 17 public: | 18 public: |
| 18 ReadingListEntry(const GURL& url, const std::string& title); | 19 ReadingListEntry(const GURL& url, const std::string& title); |
| 20 ReadingListEntry(const GURL& url, |
| 21 const std::string& title, |
| 22 std::unique_ptr<net::BackoffEntry> backoff); |
| 19 ReadingListEntry(ReadingListEntry&& entry); | 23 ReadingListEntry(ReadingListEntry&& entry); |
| 20 ~ReadingListEntry(); | 24 ~ReadingListEntry(); |
| 21 | 25 |
| 22 // Entries are created in WAITING state. At some point they will be PROCESSING | 26 // Entries are created in WAITING state. At some point they will be PROCESSING |
| 23 // into one of the three state: PROCESSED, the only state a distilled URL | 27 // into one of the three state: PROCESSED, the only state a distilled URL |
| 24 // would be set, WILL_RETRY, similar to wait, but with exponential delays or | 28 // would be set, WILL_RETRY, similar to wait, but with exponential delays or |
| 25 // ERROR where the system will not retry at all. | 29 // ERROR where the system will not retry at all. |
| 26 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; | 30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; |
| 27 | 31 |
| 32 static const net::BackoffEntry::Policy kBackoffPolicy; |
| 33 |
| 28 // The URL of the page the user would like to read later. | 34 // The URL of the page the user would like to read later. |
| 29 const GURL& URL() const; | 35 const GURL& URL() const; |
| 30 // The title of the entry. Might be empty. | 36 // The title of the entry. Might be empty. |
| 31 const std::string Title() const; | 37 const std::string& Title() const; |
| 32 // What state this entry is in. | 38 // What state this entry is in. |
| 33 DistillationState DistilledState() const; | 39 DistillationState DistilledState() const; |
| 34 // The local file URL for the distilled version of the page. This should only | 40 // The local file URL for the distilled version of the page. This should only |
| 35 // be called if the state is "PROCESSED". | 41 // be called if the state is "PROCESSED". |
| 36 const GURL& DistilledURL() const; | 42 const GURL& DistilledURL() const; |
| 43 // The time before the next try. This is automatically increased when the |
| 44 // state is set to WILL_RETRY or ERROR from a non-error state. |
| 45 base::TimeDelta TimeUntilNextTry() const; |
| 37 | 46 |
| 38 ReadingListEntry& operator=(ReadingListEntry&& other); | 47 ReadingListEntry& operator=(ReadingListEntry&& other); |
| 39 bool operator==(const ReadingListEntry& other) const; | 48 bool operator==(const ReadingListEntry& other) const; |
| 40 | 49 |
| 41 // Sets the title. | 50 // Sets the title. |
| 42 void SetTitle(const std::string& title); | 51 void SetTitle(const std::string& title); |
| 43 // Sets the distilled URL and switch the state to PROCESSED. | 52 // Sets the distilled URL and switch the state to PROCESSED and reset the time |
| 53 // until the next try. |
| 44 void SetDistilledURL(const GURL& url); | 54 void SetDistilledURL(const GURL& url); |
| 45 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 55 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
| 46 void SetDistilledState(DistillationState distilled_state); | 56 void SetDistilledState(DistillationState distilled_state); |
| 47 | 57 |
| 48 private: | 58 private: |
| 49 GURL url_; | 59 GURL url_; |
| 50 std::string title_; | 60 std::string title_; |
| 51 GURL distilled_url_; | 61 GURL distilled_url_; |
| 52 DistillationState distilled_state_; | 62 DistillationState distilled_state_; |
| 63 std::unique_ptr<net::BackoffEntry> backoff_; |
| 53 | 64 |
| 54 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); | 65 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); |
| 55 }; | 66 }; |
| 56 | 67 |
| 57 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 68 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
| OLD | NEW |