| 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 COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ | 5 #ifndef COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ |
| 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ | 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 namespace sync_pb { | 27 namespace sync_pb { |
| 28 class ReadingListSpecifics; | 28 class ReadingListSpecifics; |
| 29 } | 29 } |
| 30 | 30 |
| 31 class ReadingListEntry; | 31 class ReadingListEntry; |
| 32 | 32 |
| 33 // An entry in the reading list. The URL is a unique identifier for an entry, as | 33 // An entry in the reading list. The URL is a unique identifier for an entry, as |
| 34 // such it should not be empty and is the only thing considered when comparing | 34 // such it should not be empty and is the only thing considered when comparing |
| 35 // entries. | 35 // entries. |
| 36 // A word about timestamp usage in this class: |
| 37 // - The backing store uses int64 values to code timestamps. We use internally |
| 38 // the same type to avoid useless conversions. This values represent the |
| 39 // number of micro seconds since Jan 1st 1970. |
| 40 // - As most timestamp are used to sort entries, operations on int64_t are |
| 41 // faster than operations on base::Time. So Getter return the int64_t values. |
| 42 // - However, to ensure all the conversions are done the same way, and because |
| 43 // the Now time is alway retrieved using base::Time::Now(), all the timestamp |
| 44 // parameter are passed as base::Time. These parameters are internally |
| 45 // converted in int64_t. |
| 36 class ReadingListEntry { | 46 class ReadingListEntry { |
| 37 public: | 47 public: |
| 38 ReadingListEntry(const GURL& url, const std::string& title); | 48 // Creates a ReadingList entry. |url| and |title| are the main fields of the |
| 49 // entry. |
| 50 // |now| is used to fill the |creation_time_us_| and all the update timestamp |
| 51 // fields. |
| 39 ReadingListEntry(const GURL& url, | 52 ReadingListEntry(const GURL& url, |
| 40 const std::string& title, | 53 const std::string& title, |
| 54 const base::Time& now); |
| 55 ReadingListEntry(const GURL& url, |
| 56 const std::string& title, |
| 57 const base::Time& now, |
| 41 std::unique_ptr<net::BackoffEntry> backoff); | 58 std::unique_ptr<net::BackoffEntry> backoff); |
| 42 ReadingListEntry(ReadingListEntry&& entry); | 59 ReadingListEntry(ReadingListEntry&& entry); |
| 43 ~ReadingListEntry(); | 60 ~ReadingListEntry(); |
| 44 | 61 |
| 45 // Entries are created in WAITING state. At some point they will be PROCESSING | 62 // Entries are created in WAITING state. At some point they will be PROCESSING |
| 46 // into one of the three state: PROCESSED, the only state a distilled URL | 63 // into one of the three state: PROCESSED, the only state a distilled URL |
| 47 // would be set, WILL_RETRY, similar to wait, but with exponential delays or | 64 // would be set, WILL_RETRY, similar to wait, but with exponential delays or |
| 48 // ERROR where the system will not retry at all. | 65 // ERROR where the system will not retry at all. |
| 49 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; | 66 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; |
| 50 | 67 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 int64_t UpdateTitleTime() const; | 104 int64_t UpdateTitleTime() const; |
| 88 | 105 |
| 89 // The creation update time of the entry. The value is in microseconds since | 106 // The creation update time of the entry. The value is in microseconds since |
| 90 // Jan 1st 1970. | 107 // Jan 1st 1970. |
| 91 int64_t CreationTime() const; | 108 int64_t CreationTime() const; |
| 92 | 109 |
| 93 // The time when the entry was read for the first time. The value is in | 110 // The time when the entry was read for the first time. The value is in |
| 94 // microseconds since Jan 1st 1970. | 111 // microseconds since Jan 1st 1970. |
| 95 int64_t FirstReadTime() const; | 112 int64_t FirstReadTime() const; |
| 96 | 113 |
| 97 // Set the update time to now. | 114 // Set the update time to |now|. |
| 98 void MarkEntryUpdated(); | 115 void MarkEntryUpdated(const base::Time& now); |
| 99 | 116 |
| 100 // Returns a protobuf encoding the content of this ReadingListEntry for local | 117 // Returns a protobuf encoding the content of this ReadingListEntry for local |
| 101 // storage. | 118 // storage. Use |now| to serialize the backoff_entry. |
| 102 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal() const; | 119 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( |
| 120 const base::Time& now) const; |
| 103 | 121 |
| 104 // Returns a protobuf encoding the content of this ReadingListEntry for sync. | 122 // Returns a protobuf encoding the content of this ReadingListEntry for sync. |
| 105 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const; | 123 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const; |
| 106 | 124 |
| 107 // Created a ReadingListEntry from the protobuf format. | 125 // Created a ReadingListEntry from the protobuf format. |
| 126 // Use |now| to deserialize the backoff_entry. |
| 108 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( | 127 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( |
| 109 const reading_list::ReadingListLocal& pb_entry); | 128 const reading_list::ReadingListLocal& pb_entry, |
| 129 const base::Time& now); |
| 110 | 130 |
| 111 // Created a ReadingListEntry from the protobuf format. | 131 // Created a ReadingListEntry from the protobuf format. |
| 132 // If creation time is not set, it will be set to |now|. |
| 112 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( | 133 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( |
| 113 const sync_pb::ReadingListSpecifics& pb_entry); | 134 const sync_pb::ReadingListSpecifics& pb_entry, |
| 135 const base::Time& now); |
| 114 | 136 |
| 115 // Merge |this| and |other| into this. | 137 // Merge |this| and |other| into this. |
| 116 // Local fields are kept from |this|. | 138 // Local fields are kept from |this|. |
| 117 // Each field is merged individually keeping the highest value as defined by | 139 // Each field is merged individually keeping the highest value as defined by |
| 118 // the |ReadingListStore.CompareEntriesForSync| function. | 140 // the |ReadingListStore.CompareEntriesForSync| function. |
| 119 // | 141 // |
| 120 // After calling |MergeLocalStateFrom|, the result must verify | 142 // After calling |MergeLocalStateFrom|, the result must verify |
| 121 // ReadingListStore.CompareEntriesForSync(old_this.AsReadingListSpecifics(), | 143 // ReadingListStore.CompareEntriesForSync(old_this.AsReadingListSpecifics(), |
| 122 // new_this.AsReadingListSpecifics()) | 144 // new_this.AsReadingListSpecifics()) |
| 123 // and | 145 // and |
| 124 // ReadingListStore.CompareEntriesForSync(other.AsReadingListSpecifics(), | 146 // ReadingListStore.CompareEntriesForSync(other.AsReadingListSpecifics(), |
| 125 // new_this.AsReadingListSpecifics()). | 147 // new_this.AsReadingListSpecifics()). |
| 126 void MergeWithEntry(const ReadingListEntry& other); | 148 void MergeWithEntry(const ReadingListEntry& other); |
| 127 | 149 |
| 128 ReadingListEntry& operator=(ReadingListEntry&& other); | 150 ReadingListEntry& operator=(ReadingListEntry&& other); |
| 129 | 151 |
| 130 bool operator==(const ReadingListEntry& other) const; | 152 bool operator==(const ReadingListEntry& other) const; |
| 131 | 153 |
| 132 // Sets the title. | 154 // Sets |title_| to |title|. Sets |update_title_time_us_| to |now|. |
| 133 void SetTitle(const std::string& title); | 155 void SetTitle(const std::string& title, const base::Time& now); |
| 134 // Sets the distilled info (offline path, online URL, size and date of the | 156 // Sets the distilled info (offline path, online URL, size and date of the |
| 135 // stored files) about distilled page, switch the state to PROCESSED and reset | 157 // stored files) about distilled page, switch the state to PROCESSED and reset |
| 136 // the time until the next try. | 158 // the time until the next try. |
| 137 void SetDistilledInfo(const base::FilePath& path, | 159 void SetDistilledInfo(const base::FilePath& path, |
| 138 const GURL& distilled_url, | 160 const GURL& distilled_url, |
| 139 int64_t distilation_size, | 161 int64_t distilation_size, |
| 140 int64_t distilation_time); | 162 const base::Time& distilation_time); |
| 141 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 163 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
| 142 void SetDistilledState(DistillationState distilled_state); | 164 void SetDistilledState(DistillationState distilled_state); |
| 143 // Sets the read state of the entry. Will set the UpdateTime of the entry. | 165 // Sets the read state of the entry. Will set the UpdateTime of the entry. |
| 144 void SetRead(bool read); | 166 // If |first_read_time_us_| is 0 and read is READ, sets |first_read_time_us_| |
| 167 // to |now|. |
| 168 void SetRead(bool read, const base::Time& now); |
| 145 | 169 |
| 146 private: | 170 private: |
| 147 enum State { UNSEEN, UNREAD, READ }; | 171 enum State { UNSEEN, UNREAD, READ }; |
| 148 ReadingListEntry(const GURL& url, | 172 ReadingListEntry(const GURL& url, |
| 149 const std::string& title, | 173 const std::string& title, |
| 150 State state, | 174 State state, |
| 151 int64_t creation_time, | 175 int64_t creation_time, |
| 152 int64_t first_read_time, | 176 int64_t first_read_time, |
| 153 int64_t update_time, | 177 int64_t update_time, |
| 154 int64_t update_title_time, | 178 int64_t update_title_time, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 176 int64_t first_read_time_us_; | 200 int64_t first_read_time_us_; |
| 177 int64_t update_time_us_; | 201 int64_t update_time_us_; |
| 178 int64_t update_title_time_us_; | 202 int64_t update_title_time_us_; |
| 179 int64_t distillation_time_us_; | 203 int64_t distillation_time_us_; |
| 180 int64_t distillation_size_; | 204 int64_t distillation_size_; |
| 181 | 205 |
| 182 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); | 206 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); |
| 183 }; | 207 }; |
| 184 | 208 |
| 185 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ | 209 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ |
| OLD | NEW |