| 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 12 matching lines...) Expand all Loading... |
| 23 // Exposed for tests. | 23 // Exposed for tests. |
| 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 | |
| 34 // the CreateFrom* methods below instead. | |
| 35 // TODO(treib): Make the constructor take the vector of IDs and remove AddIDs. | |
| 36 NTPSnippet(const std::string& id, int remote_category_id); | |
| 37 ~NTPSnippet(); | 33 ~NTPSnippet(); |
| 38 | 34 |
| 39 // Creates an NTPSnippet from a dictionary, as returned by Chrome Reader. | 35 // 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 | 36 // 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 | 37 // snippet. The keys in the dictionary are expected to be the same as the |
| 42 // property name, with exceptions documented in the property comment. | 38 // property name, with exceptions documented in the property comment. |
| 43 static std::unique_ptr<NTPSnippet> CreateFromChromeReaderDictionary( | 39 static std::unique_ptr<NTPSnippet> CreateFromChromeReaderDictionary( |
| 44 const base::DictionaryValue& dict); | 40 const base::DictionaryValue& dict); |
| 45 | 41 |
| 46 // Creates an NTPSnippet from a dictionary, as returned by Chrome Content | 42 // 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 | 110 |
| 115 // The ID of the remote category this snippet belongs to, for use with | 111 // The ID of the remote category this snippet belongs to, for use with |
| 116 // CategoryFactory::FromRemoteCategory. | 112 // CategoryFactory::FromRemoteCategory. |
| 117 int remote_category_id() const { return remote_category_id_; } | 113 int remote_category_id() const { return remote_category_id_; } |
| 118 | 114 |
| 119 // Public for testing. | 115 // Public for testing. |
| 120 static base::Time TimeFromJsonString(const std::string& timestamp_str); | 116 static base::Time TimeFromJsonString(const std::string& timestamp_str); |
| 121 static std::string TimeToJsonString(const base::Time& time); | 117 static std::string TimeToJsonString(const base::Time& time); |
| 122 | 118 |
| 123 private: | 119 private: |
| 124 void AddIDs(const std::vector<std::string>& ids); | 120 NTPSnippet(const std::vector<std::string>& ids, int remote_category_id); |
| 121 |
| 122 // base::MakeUnique doesn't work if the ctor is private. |
| 123 static std::unique_ptr<NTPSnippet> MakeUnique( |
| 124 const std::vector<std::string>& ids, int remote_category_id); |
| 125 | 125 |
| 126 // The first ID in the vector is the primary id. | 126 // The first ID in the vector is the primary id. |
| 127 std::vector<std::string> ids_; | 127 std::vector<std::string> ids_; |
| 128 std::string title_; | 128 std::string title_; |
| 129 GURL url_; | 129 GURL url_; |
| 130 std::string publisher_name_; | 130 std::string publisher_name_; |
| 131 GURL amp_url_; | 131 GURL amp_url_; |
| 132 GURL salient_image_url_; | 132 GURL salient_image_url_; |
| 133 std::string snippet_; | 133 std::string snippet_; |
| 134 base::Time publish_date_; | 134 base::Time publish_date_; |
| 135 base::Time expiry_date_; | 135 base::Time expiry_date_; |
| 136 float score_; | 136 float score_; |
| 137 bool is_dismissed_; | 137 bool is_dismissed_; |
| 138 int remote_category_id_; | 138 int remote_category_id_; |
| 139 | 139 |
| 140 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); | 140 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 } // namespace ntp_snippets | 143 } // namespace ntp_snippets |
| 144 | 144 |
| 145 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ | 145 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPET_H_ |
| OLD | NEW |