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

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

Issue 2369303002: Reading List create protobuf store (Closed)
Patch Set: cleaning Created 4 years, 2 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 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>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/time/default_tick_clock.h"
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 sync_pb {
18 class ReadingListLocal;
19 }
20
14 // An entry in the reading list. The URL is a unique identifier for an entry, as 21 // 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 22 // such it should not be empty and is the only thing considered when comparing
16 // entries. 23 // entries.
17 class ReadingListEntry { 24 class ReadingListEntry {
18 public: 25 public:
19 ReadingListEntry(const GURL& url, const std::string& title);
20 ReadingListEntry(const GURL& url,
21 const std::string& title,
22 std::unique_ptr<net::BackoffEntry> backoff);
23 ReadingListEntry(ReadingListEntry&& entry);
24 ~ReadingListEntry();
25
26 // Entries are created in WAITING state. At some point they will be PROCESSING 26 // Entries are created in WAITING state. At some point they will be PROCESSING
27 // into one of the three state: PROCESSED, the only state a distilled URL 27 // into one of the three state: PROCESSED, the only state a distilled URL
28 // would be set, WILL_RETRY, similar to wait, but with exponential delays or 28 // would be set, WILL_RETRY, similar to wait, but with exponential delays or
29 // ERROR where the system will not retry at all. 29 // ERROR where the system will not retry at all.
30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR }; 30 enum DistillationState { WAITING, PROCESSING, PROCESSED, WILL_RETRY, ERROR };
31 31
32 ReadingListEntry(const GURL& url, const std::string& title);
33 ReadingListEntry(const GURL& url,
34 const std::string& title,
35 std::unique_ptr<net::BackoffEntry> backoff);
36 ReadingListEntry(const GURL& url,
37 const std::string& title,
38 int64_t creation_time,
39 int64_t update_time,
40 DistillationState distilled_state,
41 const GURL& distilled_url,
42 std::unique_ptr<net::BackoffEntry> backoff);
43 ReadingListEntry(ReadingListEntry&& entry);
44 ~ReadingListEntry();
45
46
32 static const net::BackoffEntry::Policy kBackoffPolicy; 47 static const net::BackoffEntry::Policy kBackoffPolicy;
33 48
34 // The URL of the page the user would like to read later. 49 // The URL of the page the user would like to read later.
35 const GURL& URL() const; 50 const GURL& URL() const;
36 // The title of the entry. Might be empty. 51 // The title of the entry. Might be empty.
37 const std::string& Title() const; 52 const std::string& Title() const;
38 // What state this entry is in. 53 // What state this entry is in.
39 DistillationState DistilledState() const; 54 DistillationState DistilledState() const;
40 // The local file URL for the distilled version of the page. This should only 55 // The local file URL for the distilled version of the page. This should only
41 // be called if the state is "PROCESSED". 56 // be called if the state is "PROCESSED".
42 const GURL& DistilledURL() const; 57 const GURL& DistilledURL() const;
43 // 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
44 // 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.
45 base::TimeDelta TimeUntilNextTry() const; 60 base::TimeDelta TimeUntilNextTry() const;
46 // 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
47 // 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
48 // non-error state. 63 // non-error state.
49 int FailedDownloadCounter() const; 64 int FailedDownloadCounter() const;
50 65
66 // The last update time of the entry. Thes value may be used to sort the
jif-google 2016/09/27 16:39:03 s/Thes/These/
gambard 2016/09/28 09:19:08 I think it is s/Thes/This/
Olivier 2016/09/28 11:20:06 Done.
67 // entries.
68 int64_t UpdateTime() const;
jif-google 2016/09/27 16:39:03 use base::time instead of int64_t ? If not, then p
Olivier 2016/09/28 11:20:06 I did use base::time, but as the value is used onl
69
70 // Set the update time to now.
71 void MarkEntryUpdated();
72
73 // Converts a ReadingListEntry to the protobuf format.
jif-google 2016/09/27 16:39:03 How about: // Returns a protobuf encoding the cont
Olivier 2016/09/28 11:20:06 Done.
74 std::unique_ptr<sync_pb::ReadingListLocal> AsReadingListLocal(
75 bool read) const;
76
77 // Created a ReadingListEntry from the protobuf format.
78 static std::unique_ptr<ReadingListEntry> FromReadingListLocal(
79 const sync_pb::ReadingListLocal& pb_entry);
80
51 ReadingListEntry& operator=(ReadingListEntry&& other); 81 ReadingListEntry& operator=(ReadingListEntry&& other);
82
52 bool operator==(const ReadingListEntry& other) const; 83 bool operator==(const ReadingListEntry& other) const;
53 84
85 // Compares two entries using update time, most recent first.
gambard 2016/09/28 09:19:08 Maybe be a bit more explicit? Like // returns whet
Olivier 2016/09/28 11:20:06 Done.
86 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs,
87 const ReadingListEntry& rhs);
88
54 // Sets the title. 89 // Sets the title.
55 void SetTitle(const std::string& title); 90 void SetTitle(const std::string& title);
56 // Sets the distilled URL and switch the state to PROCESSED and reset the time 91 // Sets the distilled URL and switch the state to PROCESSED and reset the time
57 // until the next try. 92 // until the next try.
58 void SetDistilledURL(const GURL& url); 93 void SetDistilledURL(const GURL& url);
59 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. 94 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR.
60 void SetDistilledState(DistillationState distilled_state); 95 void SetDistilledState(DistillationState distilled_state);
61 96
62 private: 97 private:
63 GURL url_; 98 GURL url_;
64 std::string title_; 99 std::string title_;
65 GURL distilled_url_; 100 GURL distilled_url_;
66 DistillationState distilled_state_; 101 DistillationState distilled_state_;
102
67 std::unique_ptr<net::BackoffEntry> backoff_; 103 std::unique_ptr<net::BackoffEntry> backoff_;
68 int failed_download_counter_; 104 int failed_download_counter_;
105 int64_t creation_time_us_;
jif-google 2016/09/27 16:39:03 base::time ?
gambard 2016/09/28 09:19:08 what do the "us" part of the variable name mean? C
Olivier 2016/09/28 11:20:06 same comment as above. This value is fundamentally
106 int64_t update_time_us_;
69 107
70 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); 108 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry);
71 }; 109 };
72 110
111 typedef std::vector<ReadingListEntry> ReadingListEntries;
jif-google 2016/09/27 16:39:03 Use "using" instead of "typedef". It's better, and
jif-google 2016/09/27 16:39:03 move ReadingListEntries definition to where it's u
Olivier 2016/09/28 11:20:06 Done.
112
73 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ 113 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698