| 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/time/tick_clock.h" |
| 11 #include "base/time/time.h" |
| 10 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 11 | 13 |
| 12 // 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 |
| 13 // 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 |
| 14 // entries. | 16 // entries. |
| 15 class ReadingListEntry { | 17 class ReadingListEntry { |
| 16 public: | 18 public: |
| 17 ReadingListEntry(const GURL& url, const std::string& title); | 19 ReadingListEntry(const GURL& url, const std::string& title); |
| 20 // The lifetime of |clock| must enclose lifetime of ReadingListEntry, the |
| 21 // pointer can be null. |
| 22 ReadingListEntry(const GURL& url, |
| 23 const std::string& title, |
| 24 base::TickClock* clock); |
| 18 ReadingListEntry(const ReadingListEntry& entry); | 25 ReadingListEntry(const ReadingListEntry& entry); |
| 19 ~ReadingListEntry(); | 26 ~ReadingListEntry(); |
| 20 | 27 |
| 21 // Entries are created in WAITING state. At some point they will be PROCESSING | 28 // Entries are created in WAITING state. At some point they will be PROCESSING |
| 22 // into one of the three state: PROCESSED, the only state a distilled URL | 29 // into one of the three state: PROCESSED, the only state a distilled URL |
| 23 // would be set, WILL_RETRY, similar to wait, but with exponential delays or | 30 // would be set, WILL_RETRY, similar to wait, but with exponential delays or |
| 24 // ERROR where the system will not retry at all. | 31 // ERROR where the system will not retry at all. |
| 25 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; | 32 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; |
| 26 | 33 |
| 27 // 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. |
| 28 const GURL& URL() const; | 35 const GURL& URL() const; |
| 29 // The title of the entry. Might be empty. | 36 // The title of the entry. Might be empty. |
| 30 const std::string Title() const; | 37 const std::string& Title() const; |
| 31 // What state this entry is in. | 38 // What state this entry is in. |
| 32 DistillationState DistilledState() const; | 39 DistillationState DistilledState() const; |
| 33 // 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 |
| 34 // be called if the state is "PROCESSED". | 41 // be called if the state is "PROCESSED". |
| 35 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. |
| 45 base::TimeDelta TimeUntilNextTry() const; |
| 36 | 46 |
| 37 ReadingListEntry& operator=(const ReadingListEntry& other); | 47 ReadingListEntry& operator=(const ReadingListEntry& other); |
| 38 bool operator==(const ReadingListEntry& other) const; | 48 bool operator==(const ReadingListEntry& other) const; |
| 39 | 49 |
| 40 // Sets the title. | 50 // Sets the title. |
| 41 void SetTitle(const std::string& title); | 51 void SetTitle(const std::string& title); |
| 42 // Sets the distilled URL and switch the state to PROCESSED. | 52 // Sets the distilled URL and switch the state to PROCESSED. |
| 43 void SetDistilledURL(const GURL& url); | 53 void SetDistilledURL(const GURL& url); |
| 44 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 54 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
| 45 void SetDistilledState(DistillationState distilled_state); | 55 void SetDistilledState(DistillationState distilled_state); |
| 46 | 56 |
| 47 private: | 57 private: |
| 58 // Calculates the delta until the next retry based of the |
| 59 // |currentWaitingTime|. This implementation doubles it. |
| 60 static base::TimeDelta NextWaitingTime(base::TimeDelta currentWaitingTime); |
| 61 // Get the current time using the clock or base::TimeTicks::Now() if no clock |
| 62 // is provided. |
| 63 base::TimeTicks GetTimeTicksNow() const; |
| 64 |
| 48 GURL url_; | 65 GURL url_; |
| 49 std::string title_; | 66 std::string title_; |
| 50 GURL distilled_url_; | 67 GURL distilled_url_; |
| 51 DistillationState distilled_state_; | 68 DistillationState distilled_state_; |
| 69 base::TimeTicks time_to_retry_; |
| 70 base::TimeDelta current_waiting_time_; |
| 71 base::TickClock* clock_; |
| 52 }; | 72 }; |
| 53 | 73 |
| 54 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 74 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
| OLD | NEW |