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

Side by Side Diff: components/reading_list/ios/reading_list_entry.h

Issue 2764533002: Reading List iOS: Use external clock in ReadingListEntry. (Closed)
Patch Set: fix microseconds Created 3 years, 9 months 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 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 17 matching lines...) Expand all
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 class ReadingListEntry { 36 class ReadingListEntry {
37 public: 37 public:
38 ReadingListEntry(const GURL& url, const std::string& title); 38 // Creates a ReadingList entry. |url| and |title| are the main fields of the
39 // entry.
40 // |now| is used to fill the |creation_time_us_| and all the update timestamp
41 // fields.
39 ReadingListEntry(const GURL& url, 42 ReadingListEntry(const GURL& url,
40 const std::string& title, 43 const std::string& title,
44 const base::Time& now);
45 ReadingListEntry(const GURL& url,
46 const std::string& title,
47 const base::Time& now,
41 std::unique_ptr<net::BackoffEntry> backoff); 48 std::unique_ptr<net::BackoffEntry> backoff);
42 ReadingListEntry(ReadingListEntry&& entry); 49 ReadingListEntry(ReadingListEntry&& entry);
43 ~ReadingListEntry(); 50 ~ReadingListEntry();
44 51
45 // Entries are created in WAITING state. At some point they will be PROCESSING 52 // 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 53 // 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 54 // would be set, WILL_RETRY, similar to wait, but with exponential delays or
48 // ERROR where the system will not retry at all. 55 // ERROR where the system will not retry at all.
49 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; 56 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR };
50 57
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 int64_t UpdateTitleTime() const; 94 int64_t UpdateTitleTime() const;
88 95
89 // The creation update time of the entry. The value is in microseconds since 96 // The creation update time of the entry. The value is in microseconds since
90 // Jan 1st 1970. 97 // Jan 1st 1970.
91 int64_t CreationTime() const; 98 int64_t CreationTime() const;
92 99
93 // The time when the entry was read for the first time. The value is in 100 // The time when the entry was read for the first time. The value is in
94 // microseconds since Jan 1st 1970. 101 // microseconds since Jan 1st 1970.
95 int64_t FirstReadTime() const; 102 int64_t FirstReadTime() const;
96 103
97 // Set the update time to now. 104 // Set the update time to |now|.
98 void MarkEntryUpdated(); 105 void MarkEntryUpdated(const base::Time& now);
99 106
100 // Returns a protobuf encoding the content of this ReadingListEntry for local 107 // Returns a protobuf encoding the content of this ReadingListEntry for local
101 // storage. 108 // storage. Use |now| to serialize the backoff_entry.
102 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal() const; 109 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal(
110 const base::Time& now) const;
103 111
104 // Returns a protobuf encoding the content of this ReadingListEntry for sync. 112 // Returns a protobuf encoding the content of this ReadingListEntry for sync.
105 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const; 113 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const;
106 114
107 // Created a ReadingListEntry from the protobuf format. 115 // Created a ReadingListEntry from the protobuf format.
116 // Use |now| to deserialize the backoff_entry.
108 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( 117 static std::unique_ptr<ReadingListEntry> FromReadingListLocal(
109 const reading_list::ReadingListLocal& pb_entry); 118 const reading_list::ReadingListLocal& pb_entry,
119 const base::Time& now);
110 120
111 // Created a ReadingListEntry from the protobuf format. 121 // Created a ReadingListEntry from the protobuf format.
122 // If creation time is not set, it will be set to |now|.
112 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( 123 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics(
113 const sync_pb::ReadingListSpecifics& pb_entry); 124 const sync_pb::ReadingListSpecifics& pb_entry,
125 const base::Time& now);
114 126
115 // Merge |this| and |other| into this. 127 // Merge |this| and |other| into this.
116 // Local fields are kept from |this|. 128 // Local fields are kept from |this|.
117 // Each field is merged individually keeping the highest value as defined by 129 // Each field is merged individually keeping the highest value as defined by
118 // the |ReadingListStore.CompareEntriesForSync| function. 130 // the |ReadingListStore.CompareEntriesForSync| function.
119 // 131 //
120 // After calling |MergeLocalStateFrom|, the result must verify 132 // After calling |MergeLocalStateFrom|, the result must verify
121 // ReadingListStore.CompareEntriesForSync(old_this.AsReadingListSpecifics(), 133 // ReadingListStore.CompareEntriesForSync(old_this.AsReadingListSpecifics(),
122 // new_this.AsReadingListSpecifics()) 134 // new_this.AsReadingListSpecifics())
123 // and 135 // and
124 // ReadingListStore.CompareEntriesForSync(other.AsReadingListSpecifics(), 136 // ReadingListStore.CompareEntriesForSync(other.AsReadingListSpecifics(),
125 // new_this.AsReadingListSpecifics()). 137 // new_this.AsReadingListSpecifics()).
126 void MergeWithEntry(const ReadingListEntry& other); 138 void MergeWithEntry(const ReadingListEntry& other);
127 139
128 ReadingListEntry& operator=(ReadingListEntry&& other); 140 ReadingListEntry& operator=(ReadingListEntry&& other);
129 141
130 bool operator==(const ReadingListEntry& other) const; 142 bool operator==(const ReadingListEntry& other) const;
131 143
132 // Sets the title. 144 // Sets |title_| to |title|. Sets |update_title_time_us_| to |now|.
gambard 2017/03/21 13:08:06 Here and in the others comments of the Entry, you
Olivier 2017/03/21 14:01:09 Technically, update_title_time_us_ is a timestamp,
gambard 2017/03/21 15:36:53 Acknowledged.
133 void SetTitle(const std::string& title); 145 void SetTitle(const std::string& title, const base::Time& now);
134 // Sets the distilled info (offline path, online URL, size and date of the 146 // 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 147 // stored files) about distilled page, switch the state to PROCESSED and reset
136 // the time until the next try. 148 // the time until the next try.
137 void SetDistilledInfo(const base::FilePath& path, 149 void SetDistilledInfo(const base::FilePath& path,
138 const GURL& distilled_url, 150 const GURL& distilled_url,
139 int64_t distilation_size, 151 int64_t distilation_size,
140 int64_t distilation_time); 152 const base::Time& distilation_time);
141 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. 153 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR.
142 void SetDistilledState(DistillationState distilled_state); 154 void SetDistilledState(DistillationState distilled_state);
143 // Sets the read state of the entry. Will set the UpdateTime of the entry. 155 // Sets the read state of the entry. Will set the UpdateTime of the entry.
144 void SetRead(bool read); 156 // If |first_read_time_us_| is 0 and read is READ, sets |first_read_time_us_|
157 // to |now|.
158 void SetRead(bool read, const base::Time& now);
145 159
146 private: 160 private:
147 enum State { UNSEEN, UNREAD, READ }; 161 enum State { UNSEEN, UNREAD, READ };
148 ReadingListEntry(const GURL& url, 162 ReadingListEntry(const GURL& url,
149 const std::string& title, 163 const std::string& title,
150 State state, 164 State state,
151 int64_t creation_time, 165 int64_t creation_time,
152 int64_t first_read_time, 166 int64_t first_read_time,
153 int64_t update_time, 167 int64_t update_time,
154 int64_t update_title_time, 168 int64_t update_title_time,
(...skipping 21 matching lines...) Expand all
176 int64_t first_read_time_us_; 190 int64_t first_read_time_us_;
177 int64_t update_time_us_; 191 int64_t update_time_us_;
178 int64_t update_title_time_us_; 192 int64_t update_title_time_us_;
179 int64_t distillation_time_us_; 193 int64_t distillation_time_us_;
180 int64_t distillation_size_; 194 int64_t distillation_size_;
181 195
182 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); 196 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry);
183 }; 197 };
184 198
185 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_ 199 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698