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