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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/reading_list/reading_list_entry.h
diff --git a/ios/chrome/browser/reading_list/reading_list_entry.h b/ios/chrome/browser/reading_list/reading_list_entry.h
index 0b1c27f297d9a0ea78a44d4e92d613df74461bee..5a4a0087379d88753797d14e97f169de03c689f5 100644
--- a/ios/chrome/browser/reading_list/reading_list_entry.h
+++ b/ios/chrome/browser/reading_list/reading_list_entry.h
@@ -6,6 +6,7 @@
#define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_ENTRY_H_
#include <string>
+#include <unordered_map>
#include "base/files/file_path.h"
#include "base/macros.h"
@@ -21,8 +22,17 @@ namespace sync_pb {
class ReadingListSpecifics;
}
+// The hashing structure to create unorder_map<GURL, ReadingListEntry>.
+struct GURLHasher {
+ std::size_t operator()(const GURL& k) const {
+ return std::hash<std::string>()(k.spec());
+ }
+};
+
class ReadingListEntry;
-using ReadingListEntries = std::vector<ReadingListEntry>;
+
+using ReadingListEntries =
+ 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
// An entry in the reading list. The URL is a unique identifier for an entry, as
// such it should not be empty and is the only thing considered when comparing
@@ -55,6 +65,8 @@ class ReadingListEntry {
const base::FilePath& DistilledPath() const;
// The URL to the distilled file.
const GURL DistilledURL() const;
+ // The read status of the entry.
+ bool IsRead() const;
// The time before the next try. This is automatically increased when the
// state is set to WILL_RETRY or ERROR from a non-error state.
base::TimeDelta TimeUntilNextTry() const;
@@ -76,12 +88,10 @@ class ReadingListEntry {
// Returns a protobuf encoding the content of this ReadingListEntry for local
// storage.
- std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal(
- bool read) const;
+ std::unique_ptr<reading_list::ReadingListLocal> AsReadingListLocal() const;
// Returns a protobuf encoding the content of this ReadingListEntry for sync.
- std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics(
- bool read) const;
+ std::unique_ptr<sync_pb::ReadingListSpecifics> AsReadingListSpecifics() const;
// Created a ReadingListEntry from the protobuf format.
static std::unique_ptr<ReadingListEntry> FromReadingListLocal(
@@ -112,10 +122,13 @@ class ReadingListEntry {
void SetDistilledPath(const base::FilePath& path);
// Sets the state to one of PROCESSING, WILL_RETRY or ERROR.
void SetDistilledState(DistillationState distilled_state);
+ // Sets the read stat of the entry. Will set the UpdateTime of the entry.
+ void SetRead(bool read);
private:
ReadingListEntry(const GURL& url,
const std::string& title,
+ bool read,
int64_t creation_time,
int64_t update_time,
ReadingListEntry::DistillationState distilled_state,
@@ -124,6 +137,7 @@ class ReadingListEntry {
std::unique_ptr<net::BackoffEntry> backoff);
GURL url_;
std::string title_;
+ bool read_;
base::FilePath distilled_path_;
DistillationState distilled_state_;

Powered by Google App Engine
This is Rietveld 408576698