Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_entry.h

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
pavely 2016/11/14 07:45:33 Do you need vector header?
Olivier 2016/11/14 11:36:48 Done.
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/time/default_tick_clock.h"
pavely 2016/11/14 07:45:33 Same with default_tick_clock.h.
Olivier 2016/11/14 11:36:48 Done.
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
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 // The creation update time of the entry. The value is in microseconds since
67 // Jan 1st 1970.
68 int64_t CreationTime() const;
69
70 // Set the update time to now.
71 void MarkEntryUpdated();
72
73 // Returns a protobuf encoding the content of this ReadingListEntry for local
74 // storage.
75 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal(
76 bool read) const;
77
78 // Returns a protobuf encoding the content of this ReadingListEntry for sync.
79 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics(
80 bool read) const;
81
82 // Created a ReadingListEntry from the protobuf format.
83 static std::unique_ptr<ReadingListEntry> FromReadingListLocal(
84 const reading_list::ReadingListLocal& pb_entry);
85
86 // Created a ReadingListEntry from the protobuf format.
87 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics(
88 const sync_pb::ReadingListSpecifics& pb_entry);
89
90 // Merge the local data from |other| to this.
91 // The local fields (distilled_state_, distilled_url_, backoff_,
92 // failed_download_counter_) of |other| are moved to |this| and must not be
93 // used after this call.
94 void MergeLocalStateFrom(ReadingListEntry& other);
95
51 ReadingListEntry& operator=(ReadingListEntry&& other); 96 ReadingListEntry& operator=(ReadingListEntry&& other);
97
52 bool operator==(const ReadingListEntry& other) const; 98 bool operator==(const ReadingListEntry& other) const;
53 99
100 // Returns whether |lhs| is more recent than |rhs|.
101 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs,
102 const ReadingListEntry& rhs);
103
54 // Sets the title. 104 // Sets the title.
55 void SetTitle(const std::string& title); 105 void SetTitle(const std::string& title);
56 // Sets the distilled URL and switch the state to PROCESSED and reset the time 106 // Sets the distilled URL and switch the state to PROCESSED and reset the time
57 // until the next try. 107 // until the next try.
58 void SetDistilledURL(const GURL& url); 108 void SetDistilledURL(const GURL& url);
59 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. 109 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR.
60 void SetDistilledState(DistillationState distilled_state); 110 void SetDistilledState(DistillationState distilled_state);
61 111
62 private: 112 private:
113 ReadingListEntry(const GURL& url,
114 const std::string& title,
115 int64_t creation_time,
116 int64_t update_time,
117 DistillationState distilled_state,
118 const GURL& distilled_url,
119 int failed_download_counter,
120 std::unique_ptr<net::BackoffEntry> backoff);
63 GURL url_; 121 GURL url_;
64 std::string title_; 122 std::string title_;
65 GURL distilled_url_; 123 GURL distilled_url_;
66 DistillationState distilled_state_; 124 DistillationState distilled_state_;
125
67 std::unique_ptr<net::BackoffEntry> backoff_; 126 std::unique_ptr<net::BackoffEntry> backoff_;
68 int failed_download_counter_; 127 int failed_download_counter_;
69 128
129 // These value are in microseconds since Jan 1st 1970. They are used for
130 // sorting the entries from the database. They are kept in int64_t to avoid
131 // conversion on each save/read event.
132 int64_t creation_time_us_;
133 int64_t update_time_us_;
134
70 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); 135 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry);
71 }; 136 };
72 137
73 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ 138 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698