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 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/default_tick_clock.h" |
| 13 #include "base/time/time.h" |
11 #include "net/base/backoff_entry.h" | 14 #include "net/base/backoff_entry.h" |
12 #include "url/gurl.h" | 15 #include "url/gurl.h" |
13 | 16 |
| 17 namespace reading_list { |
| 18 class ReadingListLocal; |
| 19 } |
| 20 |
14 // An entry in the reading list. The URL is a unique identifier for an entry, as | 21 // An entry in the reading list. The URL is a unique identifier for an entry, as |
15 // such it should not be empty and is the only thing considered when comparing | 22 // such it should not be empty and is the only thing considered when comparing |
16 // entries. | 23 // entries. |
17 class ReadingListEntry { | 24 class ReadingListEntry { |
18 public: | 25 public: |
| 26 // Entries are created in WAITING state. At some point they will be PROCESSING |
| 27 // into one of the three state: PROCESSED, the only state a distilled URL |
| 28 // would be set, WILL_RETRY, similar to wait, but with exponential delays or |
| 29 // ERROR where the system will not retry at all. |
| 30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; |
| 31 |
19 ReadingListEntry(const GURL& url, const std::string& title); | 32 ReadingListEntry(const GURL& url, const std::string& title); |
20 ReadingListEntry(const GURL& url, | 33 ReadingListEntry(const GURL& url, |
21 const std::string& title, | 34 const std::string& title, |
22 std::unique_ptr<net::BackoffEntry> backoff); | 35 std::unique_ptr<net::BackoffEntry> backoff); |
23 ReadingListEntry(ReadingListEntry&& entry); | 36 ReadingListEntry(ReadingListEntry&& entry); |
24 ~ReadingListEntry(); | 37 ~ReadingListEntry(); |
25 | 38 |
26 // Entries are created in WAITING state. At some point they will be PROCESSING | |
27 // into one of the three state: PROCESSED, the only state a distilled URL | |
28 // would be set, WILL_RETRY, similar to wait, but with exponential delays or | |
29 // ERROR where the system will not retry at all. | |
30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; | |
31 | 39 |
32 static const net::BackoffEntry::Policy kBackoffPolicy; | 40 static const net::BackoffEntry::Policy kBackoffPolicy; |
33 | 41 |
34 // The URL of the page the user would like to read later. | 42 // The URL of the page the user would like to read later. |
35 const GURL& URL() const; | 43 const GURL& URL() const; |
36 // The title of the entry. Might be empty. | 44 // The title of the entry. Might be empty. |
37 const std::string& Title() const; | 45 const std::string& Title() const; |
38 // What state this entry is in. | 46 // What state this entry is in. |
39 DistillationState DistilledState() const; | 47 DistillationState DistilledState() const; |
40 // The local file URL for the distilled version of the page. This should only | 48 // The local file URL for the distilled version of the page. This should only |
41 // be called if the state is "PROCESSED". | 49 // be called if the state is "PROCESSED". |
42 const GURL& DistilledURL() const; | 50 const GURL& DistilledURL() const; |
43 // The time before the next try. This is automatically increased when the | 51 // 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. | 52 // state is set to WILL_RETRY or ERROR from a non-error state. |
45 base::TimeDelta TimeUntilNextTry() const; | 53 base::TimeDelta TimeUntilNextTry() const; |
46 // The number of time chrome failed to download this entry. This is | 54 // The number of time chrome failed to download this entry. This is |
47 // automatically increased when the state is set to WILL_RETRY or ERROR from a | 55 // automatically increased when the state is set to WILL_RETRY or ERROR from a |
48 // non-error state. | 56 // non-error state. |
49 int FailedDownloadCounter() const; | 57 int FailedDownloadCounter() const; |
50 | 58 |
| 59 // The last update time of the entry. This value may be used to sort the |
| 60 // entries. The value is in microseconds since Jan 1st 1970. |
| 61 int64_t UpdateTime() const; |
| 62 |
| 63 // Set the update time to now. |
| 64 void MarkEntryUpdated(); |
| 65 |
| 66 // Returns a protobuf encoding the content of this ReadingListEntry. |
| 67 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( |
| 68 bool read) const; |
| 69 |
| 70 // Created a ReadingListEntry from the protobuf format. |
| 71 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( |
| 72 const reading_list::ReadingListLocal& pb_entry); |
| 73 |
51 ReadingListEntry& operator=(ReadingListEntry&& other); | 74 ReadingListEntry& operator=(ReadingListEntry&& other); |
| 75 |
52 bool operator==(const ReadingListEntry& other) const; | 76 bool operator==(const ReadingListEntry& other) const; |
53 | 77 |
| 78 // returns whether |lhs| is more recent than |rhs|. |
| 79 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, |
| 80 const ReadingListEntry& rhs); |
| 81 |
54 // Sets the title. | 82 // Sets the title. |
55 void SetTitle(const std::string& title); | 83 void SetTitle(const std::string& title); |
56 // Sets the distilled URL and switch the state to PROCESSED and reset the time | 84 // Sets the distilled URL and switch the state to PROCESSED and reset the time |
57 // until the next try. | 85 // until the next try. |
58 void SetDistilledURL(const GURL& url); | 86 void SetDistilledURL(const GURL& url); |
59 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 87 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
60 void SetDistilledState(DistillationState distilled_state); | 88 void SetDistilledState(DistillationState distilled_state); |
61 | 89 |
62 private: | 90 private: |
| 91 ReadingListEntry(const GURL& url, |
| 92 const std::string& title, |
| 93 int64_t creation_time, |
| 94 int64_t update_time, |
| 95 DistillationState distilled_state, |
| 96 const GURL& distilled_url, |
| 97 std::unique_ptr<net::BackoffEntry> backoff); |
63 GURL url_; | 98 GURL url_; |
64 std::string title_; | 99 std::string title_; |
65 GURL distilled_url_; | 100 GURL distilled_url_; |
66 DistillationState distilled_state_; | 101 DistillationState distilled_state_; |
| 102 |
67 std::unique_ptr<net::BackoffEntry> backoff_; | 103 std::unique_ptr<net::BackoffEntry> backoff_; |
68 int failed_download_counter_; | 104 int failed_download_counter_; |
69 | 105 |
| 106 // These value are in microseconds since Jan 1st 1970. They are used for |
| 107 // sorting the entries from the database. They are kept in int64_t to avoid |
| 108 // conversion on each save/read event. |
| 109 int64_t creation_time_us_; |
| 110 int64_t update_time_us_; |
| 111 |
70 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); | 112 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); |
71 }; | 113 }; |
72 | 114 |
73 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 115 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
OLD | NEW |