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_REMOTE_SUGGESTION_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 public: | 31 public: |
| 32 using PtrVector = std::vector<std::unique_ptr<RemoteSuggestion>>; | 32 using PtrVector = std::vector<std::unique_ptr<RemoteSuggestion>>; |
| 33 | 33 |
| 34 ~RemoteSuggestion(); | 34 ~RemoteSuggestion(); |
| 35 | 35 |
| 36 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Reader. | 36 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Reader. |
| 37 // Returns a null pointer if the dictionary doesn't correspond to a valid | 37 // Returns a null pointer if the dictionary doesn't correspond to a valid |
| 38 // suggestion. The keys in the dictionary are expected to be the same as the | 38 // suggestion. The keys in the dictionary are expected to be the same as the |
| 39 // property name, with exceptions documented in the property comment. | 39 // property name, with exceptions documented in the property comment. |
| 40 static std::unique_ptr<RemoteSuggestion> CreateFromChromeReaderDictionary( | 40 static std::unique_ptr<RemoteSuggestion> CreateFromChromeReaderDictionary( |
| 41 const base::DictionaryValue& dict); | 41 const base::DictionaryValue& dict, |
| 42 const base::Time& fetch_time); | |
| 42 | 43 |
| 43 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Content | 44 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Content |
| 44 // Suggestions. Returns a null pointer if the dictionary doesn't correspond to | 45 // Suggestions. Returns a null pointer if the dictionary doesn't correspond to |
| 45 // a valid suggestion. Maps field names to Chrome Reader field names. | 46 // a valid suggestion. Maps field names to Chrome Reader field names. |
| 46 static std::unique_ptr<RemoteSuggestion> | 47 static std::unique_ptr<RemoteSuggestion> |
| 47 CreateFromContentSuggestionsDictionary(const base::DictionaryValue& dict, | 48 CreateFromContentSuggestionsDictionary(const base::DictionaryValue& dict, |
| 48 int remote_category_id); | 49 int remote_category_id, |
| 50 const base::Time& fetch_time); | |
| 49 | 51 |
| 50 // Creates an RemoteSuggestion from a protocol buffer. Returns a null pointer | 52 // Creates an RemoteSuggestion from a protocol buffer. Returns a null pointer |
| 51 // if the protocol buffer doesn't correspond to a valid suggestion. | 53 // if the protocol buffer doesn't correspond to a valid suggestion. |
| 52 static std::unique_ptr<RemoteSuggestion> CreateFromProto( | 54 static std::unique_ptr<RemoteSuggestion> CreateFromProto( |
| 53 const SnippetProto& proto); | 55 const SnippetProto& proto); |
| 54 | 56 |
| 55 // TODO(treib): Make tests use the public interface and remove this. | 57 // TODO(treib): Make tests use the public interface and remove this. |
| 56 static std::unique_ptr<RemoteSuggestion> CreateForTesting( | 58 static std::unique_ptr<RemoteSuggestion> CreateForTesting( |
| 57 const std::string& id, | 59 const std::string& id, |
| 58 int remote_category_id, | 60 int remote_category_id, |
| 59 const GURL& url, | 61 const GURL& url, |
| 60 const std::string& publisher_name, | 62 const std::string& publisher_name, |
| 61 const GURL& amp_url); | 63 const GURL& amp_url); |
| 62 | 64 |
| 63 // Creates a protocol buffer corresponding to this suggestion, for persisting. | 65 // Creates a protocol buffer corresponding to this suggestion, for persisting. |
| 64 SnippetProto ToProto() const; | 66 SnippetProto ToProto() const; |
| 65 | 67 |
| 68 // TODO(markusheintz): Move this method to the ContentSuggestion class. | |
|
Marc Treib
2017/02/10 16:16:56
No, this belongs here IMO. The general ContentSugg
markusheintz_
2017/02/13 09:59:55
I'll remove the TODO. Not feeling strongly about i
| |
| 66 // Coverts to general content suggestion form | 69 // Coverts to general content suggestion form |
| 67 ContentSuggestion ToContentSuggestion(Category category) const; | 70 ContentSuggestion ToContentSuggestion(Category category) const; |
| 68 | 71 |
| 69 // Returns all ids of the suggestion. | 72 // Returns all ids of the suggestion. |
| 70 const std::vector<std::string>& GetAllIDs() const { return ids_; } | 73 const std::vector<std::string>& GetAllIDs() const { return ids_; } |
| 71 | 74 |
| 72 // The unique, primary ID for identifying the suggestion. | 75 // The unique, primary ID for identifying the suggestion. |
| 73 const std::string& id() const { return ids_.front(); } | 76 const std::string& id() const { return ids_.front(); } |
| 74 | 77 |
| 75 // Title of the suggestion. | 78 // Title of the suggestion. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 bool should_notify() const { return should_notify_; } | 116 bool should_notify() const { return should_notify_; } |
| 114 base::Time notification_deadline() const { return notification_deadline_; } | 117 base::Time notification_deadline() const { return notification_deadline_; } |
| 115 | 118 |
| 116 bool is_dismissed() const { return is_dismissed_; } | 119 bool is_dismissed() const { return is_dismissed_; } |
| 117 void set_dismissed(bool dismissed) { is_dismissed_ = dismissed; } | 120 void set_dismissed(bool dismissed) { is_dismissed_ = dismissed; } |
| 118 | 121 |
| 119 // The ID of the remote category this suggestion belongs to, for use with | 122 // The ID of the remote category this suggestion belongs to, for use with |
| 120 // CategoryFactory::FromRemoteCategory. | 123 // CategoryFactory::FromRemoteCategory. |
| 121 int remote_category_id() const { return remote_category_id_; } | 124 int remote_category_id() const { return remote_category_id_; } |
| 122 | 125 |
| 126 base::Time fetch_time() const { return fetch_time_; } | |
| 127 | |
| 123 // Public for testing. | 128 // Public for testing. |
| 124 static base::Time TimeFromJsonString(const std::string& timestamp_str); | 129 static base::Time TimeFromJsonString(const std::string& timestamp_str); |
| 125 static std::string TimeToJsonString(const base::Time& time); | 130 static std::string TimeToJsonString(const base::Time& time); |
| 126 | 131 |
| 127 private: | 132 private: |
| 128 RemoteSuggestion(const std::vector<std::string>& ids, int remote_category_id); | 133 RemoteSuggestion(const std::vector<std::string>& ids, int remote_category_id); |
| 129 | 134 |
| 130 // base::MakeUnique doesn't work if the ctor is private. | 135 // base::MakeUnique doesn't work if the ctor is private. |
| 131 static std::unique_ptr<RemoteSuggestion> MakeUnique( | 136 static std::unique_ptr<RemoteSuggestion> MakeUnique( |
| 132 const std::vector<std::string>& ids, | 137 const std::vector<std::string>& ids, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 145 std::string snippet_; | 150 std::string snippet_; |
| 146 base::Time publish_date_; | 151 base::Time publish_date_; |
| 147 base::Time expiry_date_; | 152 base::Time expiry_date_; |
| 148 float score_; | 153 float score_; |
| 149 bool is_dismissed_; | 154 bool is_dismissed_; |
| 150 int remote_category_id_; | 155 int remote_category_id_; |
| 151 | 156 |
| 152 bool should_notify_; | 157 bool should_notify_; |
| 153 base::Time notification_deadline_; | 158 base::Time notification_deadline_; |
| 154 | 159 |
| 160 // The time when the remote suggestions was fetched from the server. | |
| 161 base::Time fetch_time_; | |
| 162 | |
| 155 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestion); | 163 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestion); |
| 156 }; | 164 }; |
| 157 | 165 |
| 158 } // namespace ntp_snippets | 166 } // namespace ntp_snippets |
| 159 | 167 |
| 160 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ | 168 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ |
| OLD | NEW |