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

Unified Diff: components/ntp_snippets/ntp_snippet.h

Issue 1987333003: [NTP Snippets] Persist snippets in a LevelDB instead of prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test memleaks Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/DEPS ('k') | components/ntp_snippets/ntp_snippet.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/ntp_snippet.h
diff --git a/components/ntp_snippets/ntp_snippet.h b/components/ntp_snippets/ntp_snippet.h
index 20c7fe732711a6b4d48d433529d4eff0c58a62d7..745c246e9d619f3c6c390da482d41d776d5dbf3e 100644
--- a/components/ntp_snippets/ntp_snippet.h
+++ b/components/ntp_snippets/ntp_snippet.h
@@ -20,6 +20,8 @@ class ListValue;
namespace ntp_snippets {
+class SnippetProto;
+
struct SnippetSource {
SnippetSource(const GURL& url,
const std::string& publisher_name,
@@ -35,23 +37,31 @@ class NTPSnippet {
using PtrVector = std::vector<std::unique_ptr<NTPSnippet>>;
// Creates a new snippet with the given |id|.
+ // Public for testing only - create snippets using the Create* methods below.
+ // TODO(treib): Make this private and add a CreateSnippetForTest?
NTPSnippet(const std::string& id);
~NTPSnippet();
// Creates an NTPSnippet from a dictionary. Returns a null pointer if the
- // dictionary doesn't contain at least a url. The keys in the dictionary are
- // expected to be the same as the property name, with exceptions documented in
- // the property comment.
+ // dictionary doesn't correspond to a valid snippet. The keys in the
+ // dictionary are expected to be the same as the property name, with
+ // exceptions documented in the property comment.
static std::unique_ptr<NTPSnippet> CreateFromDictionary(
const base::DictionaryValue& dict);
+ // Creates an NTPSnippet from a protocol buffer. Returns a null pointer if the
+ // protocol buffer doesn't correspond to a valid snippet.
+ static std::unique_ptr<NTPSnippet> CreateFromProto(const SnippetProto& proto);
+
// Creates snippets from dictionary values in |list| and adds them to
// |snippets|. Returns true on success, false if anything went wrong.
+ // TODO(treib): Move this to NTPSnippetsFetcher where it's used.
static bool AddFromListValue(const base::ListValue& list,
PtrVector* snippets);
- std::unique_ptr<base::DictionaryValue> ToDictionary() const;
+ // Creates a protocol buffer corresponding to this snippet, for persisting.
+ SnippetProto ToProto() const;
// A unique ID for identifying the snippet. If initialized by
// CreateFromDictionary() the relevant key is 'url'.
@@ -112,11 +122,16 @@ class NTPSnippet {
float score() const { return score_; }
void set_score(float score) { score_ = score; }
+ bool is_discarded() const { return is_discarded_; }
+ void set_discarded(bool discarded) { is_discarded_ = discarded; }
+
// Public for testing.
static base::Time TimeFromJsonString(const std::string& timestamp_str);
static std::string TimeToJsonString(const base::Time& time);
private:
+ void FindBestSource();
+
std::string id_;
std::string title_;
GURL salient_image_url_;
@@ -124,6 +139,8 @@ class NTPSnippet {
base::Time publish_date_;
base::Time expiry_date_;
float score_;
+ bool is_discarded_;
+
size_t best_source_index_;
std::vector<SnippetSource> sources_;
« no previous file with comments | « components/ntp_snippets/DEPS ('k') | components/ntp_snippets/ntp_snippet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698