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