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

Side by Side Diff: components/ntp_snippets/ntp_snippet.h

Issue 1737563003: [NTP Snippets] Persist the set of snippets in a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_merge
Patch Set: noyau review Created 4 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
« no previous file with comments | « components/ntp_snippets/DEPS ('k') | components/ntp_snippets/ntp_snippet.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
5 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
6 7
7 #include <string> 8 #include <string>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace base { 14 namespace base {
14 class DictionaryValue; 15 class DictionaryValue;
15 } 16 }
16 17
17 namespace ntp_snippets { 18 namespace ntp_snippets {
18 19
19 // Stores and vend fresh content data for the NTP. This is a dumb class with no 20 // Stores and vend fresh content data for the NTP. This is a dumb class with no
20 // smarts at all, all the logic is in the service. 21 // smarts at all, all the logic is in the service.
21 class NTPSnippet { 22 class NTPSnippet {
22 public: 23 public:
23 // Creates a new snippet with the given URL. URL must be valid. 24 // Creates a new snippet with the given URL. URL must be valid.
24 NTPSnippet(const GURL& url); 25 NTPSnippet(const GURL& url);
25 26
26 ~NTPSnippet(); 27 ~NTPSnippet();
27 28
28 // Creates an NTPSnippet from a dictionary. Returns a null pointer if the 29 // Creates an NTPSnippet from a dictionary. Returns a null pointer if the
29 // dictionary doesn't contain at least a url. The keys in the dictionary are 30 // dictionary doesn't contain at least a url. The keys in the dictionary are
30 // expected to be the same as the property name, with exceptions documented in 31 // expected to be the same as the property name, with exceptions documented in
31 // the property comment. 32 // the property comment.
32 static scoped_ptr<NTPSnippet> NTPSnippetFromDictionary( 33 static scoped_ptr<NTPSnippet> CreateFromDictionary(
33 const base::DictionaryValue& dict); 34 const base::DictionaryValue& dict);
34 35
36 scoped_ptr<base::DictionaryValue> ToDictionary() const;
37
35 // URL of the page described by this snippet. 38 // URL of the page described by this snippet.
36 const GURL& url() const { return url_; } 39 const GURL& url() const { return url_; }
37 40
38 // Subtitle to identify the site the snippet is from. 41 // Subtitle to identify the site the snippet is from.
39 const std::string& site_title() const { return site_title_; } 42 const std::string& site_title() const { return site_title_; }
40 void set_site_title(const std::string& site_title) { 43 void set_site_title(const std::string& site_title) {
41 site_title_ = site_title; 44 site_title_ = site_title;
42 } 45 }
43 46
44 // Favicon for the site. Do not use to directly retrieve the favicon. 47 // Favicon for the site. Do not use to directly retrieve the favicon.
45 const GURL& favicon_url() const { return favicon_url_; } 48 const GURL& favicon_url() const { return favicon_url_; }
46 void set_favicon_url(const GURL& favicon_url) { favicon_url_ = favicon_url; } 49 void set_favicon_url(const GURL& favicon_url) { favicon_url_ = favicon_url; }
47 50
48 // Title of the snippet. 51 // Title of the snippet.
49 const std::string& title() const { return title_; } 52 const std::string& title() const { return title_; }
50 void set_title(const std::string& title) { title_ = title; } 53 void set_title(const std::string& title) { title_ = title; }
51 54
52 // Summary or relevant extract from the content. 55 // Summary or relevant extract from the content.
53 const std::string& snippet() const { return snippet_; } 56 const std::string& snippet() const { return snippet_; }
54 void set_snippet(const std::string& snippet) { snippet_ = snippet; } 57 void set_snippet(const std::string& snippet) { snippet_ = snippet; }
55 58
56 // Link to an image representative of the content. Do not fetch this image 59 // Link to an image representative of the content. Do not fetch this image
57 // directly. If initialized by NTPSnippetFromDictionary() the relevant key is 60 // directly. If initialized by CreateFromDictionary() the relevant key is
58 // 'thumbnailURL' 61 // 'thumbnailUrl'
59 const GURL& salient_image_url() const { return salient_image_url_; } 62 const GURL& salient_image_url() const { return salient_image_url_; }
60 void set_salient_image_url(const GURL& salient_image_url) { 63 void set_salient_image_url(const GURL& salient_image_url) {
61 salient_image_url_ = salient_image_url; 64 salient_image_url_ = salient_image_url;
62 } 65 }
63 66
64 // When the page pointed by this snippet was published. If initialized by 67 // When the page pointed by this snippet was published. If initialized by
65 // NTPSnippetFromDictionary() the relevant key is 'creationTimestampSec' 68 // CreateFromDictionary() the relevant key is 'creationTimestampSec'
66 const base::Time& publish_date() const { return publish_date_; } 69 const base::Time& publish_date() const { return publish_date_; }
67 void set_publish_date(const base::Time& publish_date) { 70 void set_publish_date(const base::Time& publish_date) {
68 publish_date_ = publish_date; 71 publish_date_ = publish_date;
69 } 72 }
70 73
71 // After this expiration date this snippet should no longer be presented to 74 // After this expiration date this snippet should no longer be presented to
72 // the user. 75 // the user.
73 const base::Time& expiry_date() const { return expiry_date_; } 76 const base::Time& expiry_date() const { return expiry_date_; }
74 void set_expiry_date(const base::Time& expiry_date) { 77 void set_expiry_date(const base::Time& expiry_date) {
75 expiry_date_ = expiry_date; 78 expiry_date_ = expiry_date;
76 } 79 }
77 80
78 private: 81 private:
79 const GURL url_; 82 const GURL url_;
80 std::string site_title_; 83 std::string site_title_;
81 std::string title_; 84 std::string title_;
82 GURL favicon_url_; 85 GURL favicon_url_;
83 GURL salient_image_url_; 86 GURL salient_image_url_;
84 std::string snippet_; 87 std::string snippet_;
85 base::Time publish_date_; 88 base::Time publish_date_;
86 base::Time expiry_date_; 89 base::Time expiry_date_;
87 90
88 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); 91 DISALLOW_COPY_AND_ASSIGN(NTPSnippet);
89 }; 92 };
90 93
91 } // namespace ntp_snippets 94 } // namespace ntp_snippets
92 95
93 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_ 96 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
OLDNEW
« 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