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

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

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: format Created 4 years 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 <unordered_map>
9 10
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "net/base/backoff_entry.h" 14 #include "net/base/backoff_entry.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace reading_list { 17 namespace reading_list {
17 class ReadingListLocal; 18 class ReadingListLocal;
18 } 19 }
19 20
20 namespace sync_pb { 21 namespace sync_pb {
21 class ReadingListSpecifics; 22 class ReadingListSpecifics;
22 } 23 }
23 24
25 // The hashing structure to create unorder_map<GURL, ReadingListEntry>.
26 struct GURLHasher {
27 std::size_t operator()(const GURL& k) const {
28 return std::hash<std::string>()(k.spec());
29 }
30 };
31
24 class ReadingListEntry; 32 class ReadingListEntry;
25 using ReadingListEntries = std::vector<ReadingListEntry>; 33
34 using ReadingListEntries =
35 std::unordered_map<GURL, ReadingListEntry, GURLHasher>;
jif-google 2016/11/22 18:21:45 are you using std::unordered_map instead of std::m
Olivier 2016/11/28 14:54:14 I asked the C++ expert what to use here. He said u
26 36
27 // An entry in the reading list. The URL is a unique identifier for an entry, as 37 // 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 38 // such it should not be empty and is the only thing considered when comparing
29 // entries. 39 // entries.
30 class ReadingListEntry { 40 class ReadingListEntry {
31 public: 41 public:
32 ReadingListEntry(const GURL& url, const std::string& title); 42 ReadingListEntry(const GURL& url, const std::string& title);
33 ReadingListEntry(const GURL& url, 43 ReadingListEntry(const GURL& url,
34 const std::string& title, 44 const std::string& title,
35 std::unique_ptr<net::BackoffEntry> backoff); 45 std::unique_ptr<net::BackoffEntry> backoff);
(...skipping 12 matching lines...) Expand all
48 const GURL& URL() const; 58 const GURL& URL() const;
49 // The title of the entry. Might be empty. 59 // The title of the entry. Might be empty.
50 const std::string& Title() const; 60 const std::string& Title() const;
51 // What state this entry is in. 61 // What state this entry is in.
52 DistillationState DistilledState() const; 62 DistillationState DistilledState() const;
53 // The local file path for the distilled version of the page. This should only 63 // The local file path for the distilled version of the page. This should only
54 // be called if the state is "PROCESSED". 64 // be called if the state is "PROCESSED".
55 const base::FilePath& DistilledPath() const; 65 const base::FilePath& DistilledPath() const;
56 // The URL to the distilled file. 66 // The URL to the distilled file.
57 const GURL DistilledURL() const; 67 const GURL DistilledURL() const;
68 // The read status of the entry.
69 bool IsRead() const;
58 // The time before the next try. This is automatically increased when the 70 // The time before the next try. This is automatically increased when the
59 // state is set to WILL_RETRY or ERROR from a non-error state. 71 // state is set to WILL_RETRY or ERROR from a non-error state.
60 base::TimeDelta TimeUntilNextTry() const; 72 base::TimeDelta TimeUntilNextTry() const;
61 // The number of time chrome failed to download this entry. This is 73 // The number of time chrome failed to download this entry. This is
62 // automatically increased when the state is set to WILL_RETRY or ERROR from a 74 // automatically increased when the state is set to WILL_RETRY or ERROR from a
63 // non-error state. 75 // non-error state.
64 int FailedDownloadCounter() const; 76 int FailedDownloadCounter() const;
65 77
66 // The last update time of the entry. This value may be used to sort the 78 // 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. 79 // entries. The value is in microseconds since Jan 1st 1970.
68 int64_t UpdateTime() const; 80 int64_t UpdateTime() const;
69 81
70 // The creation update time of the entry. The value is in microseconds since 82 // The creation update time of the entry. The value is in microseconds since
71 // Jan 1st 1970. 83 // Jan 1st 1970.
72 int64_t CreationTime() const; 84 int64_t CreationTime() const;
73 85
74 // Set the update time to now. 86 // Set the update time to now.
75 void MarkEntryUpdated(); 87 void MarkEntryUpdated();
76 88
77 // Returns a protobuf encoding the content of this ReadingListEntry for local 89 // Returns a protobuf encoding the content of this ReadingListEntry for local
78 // storage. 90 // storage.
79 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal( 91 std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal() const;
80 bool read) const;
81 92
82 // Returns a protobuf encoding the content of this ReadingListEntry for sync. 93 // Returns a protobuf encoding the content of this ReadingListEntry for sync.
83 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics( 94 std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const;
84 bool read) const;
85 95
86 // Created a ReadingListEntry from the protobuf format. 96 // Created a ReadingListEntry from the protobuf format.
87 static std::unique_ptr<ReadingListEntry> FromReadingListLocal( 97 static std::unique_ptr<ReadingListEntry> FromReadingListLocal(
88 const reading_list::ReadingListLocal& pb_entry); 98 const reading_list::ReadingListLocal& pb_entry);
89 99
90 // Created a ReadingListEntry from the protobuf format. 100 // Created a ReadingListEntry from the protobuf format.
91 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics( 101 static std::unique_ptr<ReadingListEntry> FromReadingListSpecifics(
92 const sync_pb::ReadingListSpecifics& pb_entry); 102 const sync_pb::ReadingListSpecifics& pb_entry);
93 103
94 // Merge the local data from |other| to this. 104 // Merge the local data from |other| to this.
(...skipping 10 matching lines...) Expand all
105 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs, 115 static bool CompareEntryUpdateTime(const ReadingListEntry& lhs,
106 const ReadingListEntry& rhs); 116 const ReadingListEntry& rhs);
107 117
108 // Sets the title. 118 // Sets the title.
109 void SetTitle(const std::string& title); 119 void SetTitle(const std::string& title);
110 // Sets the distilled URL and switch the state to PROCESSED and reset the time 120 // Sets the distilled URL and switch the state to PROCESSED and reset the time
111 // until the next try. 121 // until the next try.
112 void SetDistilledPath(const base::FilePath& path); 122 void SetDistilledPath(const base::FilePath& path);
113 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR. 123 // Sets the state to one of PROCESSING, WILL_RETRY or ERROR.
114 void SetDistilledState(DistillationState distilled_state); 124 void SetDistilledState(DistillationState distilled_state);
125 // Sets the read stat of the entry. Will set the UpdateTime of the entry.
126 void SetRead(bool read);
115 127
116 private: 128 private:
117 ReadingListEntry(const GURL& url, 129 ReadingListEntry(const GURL& url,
118 const std::string& title, 130 const std::string& title,
131 bool read,
119 int64_t creation_time, 132 int64_t creation_time,
120 int64_t update_time, 133 int64_t update_time,
121 ReadingListEntry::DistillationState distilled_state, 134 ReadingListEntry::DistillationState distilled_state,
122 const base::FilePath& distilled_path, 135 const base::FilePath& distilled_path,
123 int failed_download_counter, 136 int failed_download_counter,
124 std::unique_ptr<net::BackoffEntry> backoff); 137 std::unique_ptr<net::BackoffEntry> backoff);
125 GURL url_; 138 GURL url_;
126 std::string title_; 139 std::string title_;
140 bool read_;
127 base::FilePath distilled_path_; 141 base::FilePath distilled_path_;
128 DistillationState distilled_state_; 142 DistillationState distilled_state_;
129 143
130 std::unique_ptr<net::BackoffEntry> backoff_; 144 std::unique_ptr<net::BackoffEntry> backoff_;
131 int failed_download_counter_; 145 int failed_download_counter_;
132 146
133 // These value are in microseconds since Jan 1st 1970. They are used for 147 // 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 148 // sorting the entries from the database. They are kept in int64_t to avoid
135 // conversion on each save/read event. 149 // conversion on each save/read event.
136 int64_t creation_time_us_; 150 int64_t creation_time_us_;
137 int64_t update_time_us_; 151 int64_t update_time_us_;
138 152
139 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry); 153 DISALLOW_COPY_AND_ASSIGN(ReadingListEntry);
140 }; 154 };
141 155
142 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_ 156 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698