| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "net/base/backoff_entry.h" | 13 #include "net/base/backoff_entry.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace reading_list { | 16 namespace reading_list { |
| 17 class ReadingListLocal; | 17 class ReadingListLocal; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace sync_pb { | 20 namespace sync_pb { |
| 21 class ReadingListSpecifics; | 21 class ReadingListSpecifics; |
| 22 } | 22 } |
| 23 | 23 |
| 24 class ReadingListEntry; | 24 class ReadingListEntry; |
| 25 using ReadingListEntries = std::vector<ReadingListEntry>; | |
| 26 | 25 |
| 27 // 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 |
| 28 // 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 |
| 29 // entries. | 28 // entries. |
| 30 class ReadingListEntry { | 29 class ReadingListEntry { |
| 31 public: | 30 public: |
| 32 ReadingListEntry(const GURL& url, const std::string& title); | 31 ReadingListEntry(const GURL& url, const std::string& title); |
| 33 ReadingListEntry(const GURL& url, | 32 ReadingListEntry(const GURL& url, |
| 34 const std::string& title, | 33 const std::string& title, |
| 35 std::unique_ptr<net::BackoffEntry> backoff); | 34 std::unique_ptr<net::BackoffEntry> backoff); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 // The local file path for the distilled version of the page. This should only | 52 // The local file path for the distilled version of the page. This should only |
| 54 // be called if the state is "PROCESSED". | 53 // be called if the state is "PROCESSED". |
| 55 const base::FilePath& DistilledPath() const; | 54 const base::FilePath& DistilledPath() const; |
| 56 // 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 |
| 57 // 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. |
| 58 base::TimeDelta TimeUntilNextTry() const; | 57 base::TimeDelta TimeUntilNextTry() const; |
| 59 // 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 |
| 60 // 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 |
| 61 // non-error state. | 60 // non-error state. |
| 62 int FailedDownloadCounter() const; | 61 int FailedDownloadCounter() const; |
| 62 // The read status of the entry. |
| 63 bool IsRead() const; |
| 63 | 64 |
| 64 // The last update time of the entry. This value may be used to sort the | 65 // The last update time of the entry. This value may be used to sort the |
| 65 // entries. The value is in microseconds since Jan 1st 1970. | 66 // entries. The value is in microseconds since Jan 1st 1970. |
| 66 int64_t UpdateTime() const; | 67 int64_t UpdateTime() const; |
| 67 | 68 |
| 68 // The creation update time of the entry. The value is in microseconds since | 69 // The creation update time of the entry. The value is in microseconds since |
| 69 // Jan 1st 1970. | 70 // Jan 1st 1970. |
| 70 int64_t CreationTime() const; | 71 int64_t CreationTime() const; |
| 71 | 72 |
| 72 // Set the update time to now. | 73 // Set the update time to now. |
| 73 void MarkEntryUpdated(); | 74 void MarkEntryUpdated(); |
| 74 | 75 |
| 75 // Returns a protobuf encoding the content of this ReadingListEntry for local | 76 // Returns a protobuf encoding the content of this ReadingListEntry for local |
| 76 // storage. | 77 // storage. |
| 77 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( | 78 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal() const; |
| 78 bool read) const; | |
| 79 | 79 |
| 80 // Returns a protobuf encoding the content of this ReadingListEntry for sync. | 80 // Returns a protobuf encoding the content of this ReadingListEntry for sync. |
| 81 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics( | 81 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const; |
| 82 bool read) const; | |
| 83 | 82 |
| 84 // Created a ReadingListEntry from the protobuf format. | 83 // Created a ReadingListEntry from the protobuf format. |
| 85 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( | 84 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( |
| 86 const reading_list::ReadingListLocal& pb_entry); | 85 const reading_list::ReadingListLocal& pb_entry); |
| 87 | 86 |
| 88 // Created a ReadingListEntry from the protobuf format. | 87 // Created a ReadingListEntry from the protobuf format. |
| 89 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( | 88 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( |
| 90 const sync_pb::ReadingListSpecifics& pb_entry); | 89 const sync_pb::ReadingListSpecifics& pb_entry); |
| 91 | 90 |
| 92 // Merge the local data from |other| to this. | 91 // Merge the local data from |other| to this. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, | 102 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, |
| 104 const ReadingListEntry& rhs); | 103 const ReadingListEntry& rhs); |
| 105 | 104 |
| 106 // Sets the title. | 105 // Sets the title. |
| 107 void SetTitle(const std::string& title); | 106 void SetTitle(const std::string& title); |
| 108 // 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 |
| 109 // until the next try. | 108 // until the next try. |
| 110 void SetDistilledPath(const base::FilePath& path); | 109 void SetDistilledPath(const base::FilePath& path); |
| 111 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. | 110 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. |
| 112 void SetDistilledState(DistillationState distilled_state); | 111 void SetDistilledState(DistillationState distilled_state); |
| 112 // Sets the read stat of the entry. Will set the UpdateTime of the entry. |
| 113 void SetRead(bool read); |
| 113 | 114 |
| 114 private: | 115 private: |
| 115 ReadingListEntry(const GURL& url, | 116 ReadingListEntry(const GURL& url, |
| 116 const std::string& title, | 117 const std::string& title, |
| 118 bool read, |
| 117 int64_t creation_time, | 119 int64_t creation_time, |
| 118 int64_t update_time, | 120 int64_t update_time, |
| 119 ReadingListEntry::DistillationState distilled_state, | 121 ReadingListEntry::DistillationState distilled_state, |
| 120 const base::FilePath& distilled_path, | 122 const base::FilePath& distilled_path, |
| 121 int failed_download_counter, | 123 int failed_download_counter, |
| 122 std::unique_ptr<net::BackoffEntry> backoff); | 124 std::unique_ptr<net::BackoffEntry> backoff); |
| 123 GURL url_; | 125 GURL url_; |
| 124 std::string title_; | 126 std::string title_; |
| 127 bool read_; |
| 125 base::FilePath distilled_path_; | 128 base::FilePath distilled_path_; |
| 126 DistillationState distilled_state_; | 129 DistillationState distilled_state_; |
| 127 | 130 |
| 128 std::unique_ptr<net::BackoffEntry> backoff_; | 131 std::unique_ptr<net::BackoffEntry> backoff_; |
| 129 int failed_download_counter_; | 132 int failed_download_counter_; |
| 130 | 133 |
| 131 // These value are in microseconds since Jan 1st 1970. They are used for | 134 // These value are in microseconds since Jan 1st 1970. They are used for |
| 132 // sorting the entries from the database. They are kept in int64_t to avoid | 135 // sorting the entries from the database. They are kept in int64_t to avoid |
| 133 // conversion on each save/read event. | 136 // conversion on each save/read event. |
| 134 int64_t creation_time_us_; | 137 int64_t creation_time_us_; |
| 135 int64_t update_time_us_; | 138 int64_t update_time_us_; |
| 136 | 139 |
| 137 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); | 140 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); |
| 138 }; | 141 }; |
| 139 | 142 |
| 140 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ | 143 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ |
| OLD | NEW |