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 |
| 21 namespace sync_pb { |
| 22 class ReadingListSpecifics; |
| 23 } |
| 24 |
14 // An entry in the reading list. The URL is a unique identifier for an entry, as | 25 // 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 | 26 // such it should not be empty and is the only thing considered when comparing |
16 // entries. | 27 // entries. |
17 class ReadingListEntry { | 28 class ReadingListEntry { |
18 public: | 29 public: |
19 ReadingListEntry(const GURL& url, const std::string& title); | 30 ReadingListEntry(const GURL& url, const std::string& title); |
20 ReadingListEntry(const GURL& url, | 31 ReadingListEntry(const GURL& url, |
21 const std::string& title, | 32 const std::string& title, |
22 std::unique_ptr<net::BackoffEntry> backoff); | 33 std::unique_ptr<net::BackoffEntry> backoff); |
23 ReadingListEntry(ReadingListEntry&& entry); | 34 ReadingListEntry(ReadingListEntry&& entry); |
(...skipping 17 matching lines...) Expand all Loading... |
41 // be called if the state is "PROCESSED". | 52 // be called if the state is "PROCESSED". |
42 const GURL& DistilledURL() const; | 53 const GURL& DistilledURL() const; |
43 // The time before the next try. This is automatically increased when the | 54 // 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. | 55 // state is set to WILL_RETRY or ERROR from a non-error state. |
45 base::TimeDelta TimeUntilNextTry() const; | 56 base::TimeDelta TimeUntilNextTry() const; |
46 // The number of time chrome failed to download this entry. This is | 57 // 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 | 58 // automatically increased when the state is set to WILL_RETRY or ERROR from a |
48 // non-error state. | 59 // non-error state. |
49 int FailedDownloadCounter() const; | 60 int FailedDownloadCounter() const; |
50 | 61 |
| 62 // The last update time of the entry. This value may be used to sort the |
| 63 // entries. The value is in microseconds since Jan 1st 1970. |
| 64 int64_t UpdateTime() const; |
| 65 |
| 66 // Set the update time to now. |
| 67 void MarkEntryUpdated(); |
| 68 |
| 69 // Returns a protobuf encoding the content of this ReadingListEntry. |
| 70 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( |
| 71 bool read) const; |
| 72 |
| 73 // Returns a protobuf encoding the content of this ReadingListEntry for sync. |
| 74 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics( |
| 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 |
| 81 // Created a ReadingListEntry from the protobuf format. |
| 82 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( |
| 83 const sync_pb::ReadingListSpecifics& pb_entry); |
| 84 |
| 85 // Merge the local data from |other| to this. |
| 86 // |other| must not be used after this point. |
| 87 void MergeLocalStateFrom(ReadingListEntry& other); |
| 88 |
51 ReadingListEntry& operator=(ReadingListEntry&& other); | 89 ReadingListEntry& operator=(ReadingListEntry&& other); |
| 90 |
52 bool operator==(const ReadingListEntry& other) const; | 91 bool operator==(const ReadingListEntry& other) const; |
53 | 92 |
| 93 // returns whether |lhs| is more recent than |rhs|. |
| 94 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, |
| 95 const ReadingListEntry& rhs); |
| 96 |
54 // Sets the title. | 97 // Sets the title. |
55 void SetTitle(const std::string& title); | 98 void SetTitle(const std::string& title); |
56 // Sets the distilled URL and switch the state to PROCESSED and reset the time | 99 // Sets the distilled URL and switch the state to PROCESSED and reset the time |
57 // until the next try. | 100 // until the next try. |
58 void SetDistilledURL(const GURL& url); | 101 void SetDistilledURL(const GURL& url); |
59 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 102 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
60 void SetDistilledState(DistillationState distilled_state); | 103 void SetDistilledState(DistillationState distilled_state); |
61 | 104 |
62 private: | 105 private: |
| 106 ReadingListEntry(const GURL& url, |
| 107 const std::string& title, |
| 108 int64_t creation_time, |
| 109 int64_t update_time, |
| 110 DistillationState distilled_state, |
| 111 const GURL& distilled_url, |
| 112 std::unique_ptr<net::BackoffEntry> backoff); |
63 GURL url_; | 113 GURL url_; |
64 std::string title_; | 114 std::string title_; |
65 GURL distilled_url_; | 115 GURL distilled_url_; |
66 DistillationState distilled_state_; | 116 DistillationState distilled_state_; |
| 117 |
67 std::unique_ptr<net::BackoffEntry> backoff_; | 118 std::unique_ptr<net::BackoffEntry> backoff_; |
68 int failed_download_counter_; | 119 int failed_download_counter_; |
69 | 120 |
| 121 // These value are in microseconds since Jan 1st 1970. They are used for |
| 122 // sorting the entries from the database. They are kept in int64_t to avoid |
| 123 // conversion on each save/read event. |
| 124 int64_t creation_time_us_; |
| 125 int64_t update_time_us_; |
| 126 |
70 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); | 127 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); |
71 }; | 128 }; |
72 | 129 |
73 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ | 130 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ |
OLD | NEW |