Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 extern const int kArticlesRemoteId; | 24 extern const int kArticlesRemoteId; |
| 25 extern const int kChromeReaderDefaultExpiryTimeMins; | 25 extern const int kChromeReaderDefaultExpiryTimeMins; |
| 26 | 26 |
| 27 class SnippetProto; | 27 class SnippetProto; |
| 28 | 28 |
| 29 class NTPSnippet { | 29 class NTPSnippet { |
| 30 public: | 30 public: |
| 31 using PtrVector = std::vector<std::unique_ptr<NTPSnippet>>; | 31 using PtrVector = std::vector<std::unique_ptr<NTPSnippet>>; |
| 32 | 32 |
| 33 // Public only so that MakeUnique will work. Don't use directly, call one of | 33 // Public only so that MakeUnique will work. Don't use directly, call one of |
| 34 // the CreateFrom* methods below instead. | 34 // the CreateFrom* methods below instead. |
|
tschumann
2016/11/25 15:55:26
Here's a nice discussion around this topic:
https:
Marc Treib
2016/11/25 16:57:36
Done.
| |
| 35 // TODO(treib): Make the constructor take the vector of IDs and remove AddIDs. | 35 NTPSnippet(const std::vector<std::string>& ids, int remote_category_id); |
| 36 NTPSnippet(const std::string& id, int remote_category_id); | |
| 37 ~NTPSnippet(); | 36 ~NTPSnippet(); |
| 38 | 37 |
| 39 // Creates an NTPSnippet from a dictionary, as returned by Chrome Reader. | 38 // Creates an NTPSnippet from a dictionary, as returned by Chrome Reader. |
| 40 // Returns a null pointer if the dictionary doesn't correspond to a valid | 39 // Returns a null pointer if the dictionary doesn't correspond to a valid |
| 41 // snippet. The keys in the dictionary are expected to be the same as the | 40 // snippet. The keys in the dictionary are expected to be the same as the |
| 42 // property name, with exceptions documented in the property comment. | 41 // property name, with exceptions documented in the property comment. |
| 43 static std::unique_ptr<NTPSnippet> CreateFromChromeReaderDictionary( | 42 static std::unique_ptr<NTPSnippet> CreateFromChromeReaderDictionary( |
| 44 const base::DictionaryValue& dict); | 43 const base::DictionaryValue& dict); |
| 45 | 44 |
| 46 // Creates an NTPSnippet from a dictionary, as returned by Chrome Content | 45 // Creates an NTPSnippet from a dictionary, as returned by Chrome Content |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 113 |
| 115 // The ID of the remote category this snippet belongs to, for use with | 114 // The ID of the remote category this snippet belongs to, for use with |
| 116 // CategoryFactory::FromRemoteCategory. | 115 // CategoryFactory::FromRemoteCategory. |
| 117 int remote_category_id() const { return remote_category_id_; } | 116 int remote_category_id() const { return remote_category_id_; } |
| 118 | 117 |
| 119 // Public for testing. | 118 // Public for testing. |
| 120 static base::Time TimeFromJsonString(const std::string& timestamp_str); | 119 static base::Time TimeFromJsonString(const std::string& timestamp_str); |
| 121 static std::string TimeToJsonString(const base::Time& time); | 120 static std::string TimeToJsonString(const base::Time& time); |
| 122 | 121 |
| 123 private: | 122 private: |
| 124 void AddIDs(const std::vector<std::string>& ids); | |
| 125 | |
| 126 // The first ID in the vector is the primary id. | 123 // The first ID in the vector is the primary id. |
| 127 std::vector<std::string> ids_; | 124 std::vector<std::string> ids_; |
| 128 std::string title_; | 125 std::string title_; |
| 129 GURL url_; | 126 GURL url_; |
| 130 std::string publisher_name_; | 127 std::string publisher_name_; |
| 131 GURL amp_url_; | 128 GURL amp_url_; |
| 132 GURL salient_image_url_; | 129 GURL salient_image_url_; |
| 133 std::string snippet_; | 130 std::string snippet_; |
| 134 base::Time publish_date_; | 131 base::Time publish_date_; |
| 135 base::Time expiry_date_; | 132 base::Time expiry_date_; |
| 136 float score_; | 133 float score_; |
| 137 bool is_dismissed_; | 134 bool is_dismissed_; |
| 138 int remote_category_id_; | 135 int remote_category_id_; |
| 139 | 136 |
| 140 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); | 137 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); |
| 141 }; | 138 }; |
| 142 | 139 |
| 143 } // namespace ntp_snippets | 140 } // namespace ntp_snippets |
| 144 | 141 |
| 145 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ | 142 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ |
| OLD | NEW |