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: |
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); | |
23 ReadingListEntry(ReadingListEntry&& entry); | |
24 ~ReadingListEntry(); | |
25 | |
26 // 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 |
27 // 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 |
28 // 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 |
29 // ERROR where the system will not retry at all. | 29 // ERROR where the system will not retry at all. |
30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; | 30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; |
31 | 31 |
32 ReadingListEntry(const GURL& url, const std::string& title); | |
33 ReadingListEntry(const GURL& url, | |
34 const std::string& title, | |
35 std::unique_ptr<net::BackoffEntry> backoff); | |
36 ReadingListEntry(const GURL& url, | |
37 const std::string& title, | |
38 int64_t creation_time, | |
39 int64_t update_time, | |
40 DistillationState distilled_state, | |
41 const GURL& distilled_url, | |
42 std::unique_ptr<net::BackoffEntry> backoff); | |
noyau (Ping after 24h)
2016/10/06 09:56:19
If it is only used by the protobuf decoding static
Olivier
2016/10/06 11:58:15
Done.
| |
43 ReadingListEntry(ReadingListEntry&& entry); | |
44 ~ReadingListEntry(); | |
45 | |
46 | |
32 static const net::BackoffEntry::Policy kBackoffPolicy; | 47 static const net::BackoffEntry::Policy kBackoffPolicy; |
33 | 48 |
34 // The URL of the page the user would like to read later. | 49 // The URL of the page the user would like to read later. |
35 const GURL& URL() const; | 50 const GURL& URL() const; |
36 // The title of the entry. Might be empty. | 51 // The title of the entry. Might be empty. |
37 const std::string& Title() const; | 52 const std::string& Title() const; |
38 // What state this entry is in. | 53 // What state this entry is in. |
39 DistillationState DistilledState() const; | 54 DistillationState DistilledState() const; |
40 // The local file URL for the distilled version of the page. This should only | 55 // The local file URL for the distilled version of the page. This should only |
41 // be called if the state is "PROCESSED". | 56 // be called if the state is "PROCESSED". |
42 const GURL& DistilledURL() const; | 57 const GURL& DistilledURL() const; |
43 // The time before the next try. This is automatically increased when the | 58 // 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. | 59 // state is set to WILL_RETRY or ERROR from a non-error state. |
45 base::TimeDelta TimeUntilNextTry() const; | 60 base::TimeDelta TimeUntilNextTry() const; |
46 // The number of time chrome failed to download this entry. This is | 61 // 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 | 62 // automatically increased when the state is set to WILL_RETRY or ERROR from a |
48 // non-error state. | 63 // non-error state. |
49 int FailedDownloadCounter() const; | 64 int FailedDownloadCounter() const; |
50 | 65 |
66 // The last update time of the entry. This value may be used to sort the | |
67 // entries. The value is in microseconds since Jan 1st 1970. | |
68 int64_t UpdateTime() const; | |
69 | |
70 // Set the update time to now. | |
71 void MarkEntryUpdated(); | |
72 | |
73 // Returns a protobuf encoding the content of this ReadingListEntry. | |
74 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( | |
75 bool read) const; | |
76 | |
77 // Created a ReadingListEntry from the protobuf format. | |
78 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( | |
79 const reading_list::ReadingListLocal& pb_entry); | |
80 | |
51 ReadingListEntry& operator=(ReadingListEntry&& other); | 81 ReadingListEntry& operator=(ReadingListEntry&& other); |
82 | |
52 bool operator==(const ReadingListEntry& other) const; | 83 bool operator==(const ReadingListEntry& other) const; |
53 | 84 |
85 // returns whether |lhs| is more recent than |rhs|. | |
86 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, | |
87 const ReadingListEntry& rhs); | |
88 | |
54 // Sets the title. | 89 // Sets the title. |
55 void SetTitle(const std::string& title); | 90 void SetTitle(const std::string& title); |
56 // Sets the distilled URL and switch the state to PROCESSED and reset the time | 91 // Sets the distilled URL and switch the state to PROCESSED and reset the time |
57 // until the next try. | 92 // until the next try. |
58 void SetDistilledURL(const GURL& url); | 93 void SetDistilledURL(const GURL& url); |
59 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 94 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
60 void SetDistilledState(DistillationState distilled_state); | 95 void SetDistilledState(DistillationState distilled_state); |
61 | 96 |
62 private: | 97 private: |
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 |