| 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 #include "components/ntp_snippets/ntp_snippet.h" | 5 #include "components/ntp_snippets/ntp_snippet.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 *url = GURL(spec); | 33 *url = GURL(spec); |
| 34 return url->is_valid(); | 34 return url->is_valid(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 namespace ntp_snippets { | 39 namespace ntp_snippets { |
| 40 | 40 |
| 41 NTPSnippet::NTPSnippet(const std::string& id) | 41 NTPSnippet::NTPSnippet(const std::string& id) |
| 42 : id_(id), score_(0), is_discarded_(false), best_source_index_(0) {} | 42 : id_(id), score_(0), is_dismissed_(false), best_source_index_(0) {} |
| 43 | 43 |
| 44 NTPSnippet::~NTPSnippet() {} | 44 NTPSnippet::~NTPSnippet() {} |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 std::unique_ptr<NTPSnippet> NTPSnippet::CreateFromChromeReaderDictionary( | 47 std::unique_ptr<NTPSnippet> NTPSnippet::CreateFromChromeReaderDictionary( |
| 48 const base::DictionaryValue& dict) { | 48 const base::DictionaryValue& dict) { |
| 49 const base::DictionaryValue* content = nullptr; | 49 const base::DictionaryValue* content = nullptr; |
| 50 if (!dict.GetDictionary("contentInfo", &content)) | 50 if (!dict.GetDictionary("contentInfo", &content)) |
| 51 return nullptr; | 51 return nullptr; |
| 52 | 52 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 std::unique_ptr<NTPSnippet> snippet(new NTPSnippet(proto.id())); | 178 std::unique_ptr<NTPSnippet> snippet(new NTPSnippet(proto.id())); |
| 179 | 179 |
| 180 snippet->set_title(proto.title()); | 180 snippet->set_title(proto.title()); |
| 181 snippet->set_snippet(proto.snippet()); | 181 snippet->set_snippet(proto.snippet()); |
| 182 snippet->set_salient_image_url(GURL(proto.salient_image_url())); | 182 snippet->set_salient_image_url(GURL(proto.salient_image_url())); |
| 183 snippet->set_publish_date( | 183 snippet->set_publish_date( |
| 184 base::Time::FromInternalValue(proto.publish_date())); | 184 base::Time::FromInternalValue(proto.publish_date())); |
| 185 snippet->set_expiry_date(base::Time::FromInternalValue(proto.expiry_date())); | 185 snippet->set_expiry_date(base::Time::FromInternalValue(proto.expiry_date())); |
| 186 snippet->set_score(proto.score()); | 186 snippet->set_score(proto.score()); |
| 187 snippet->set_discarded(proto.discarded()); | 187 snippet->set_dismissed(proto.dismissed()); |
| 188 | 188 |
| 189 for (int i = 0; i < proto.sources_size(); ++i) { | 189 for (int i = 0; i < proto.sources_size(); ++i) { |
| 190 const SnippetSourceProto& source_proto = proto.sources(i); | 190 const SnippetSourceProto& source_proto = proto.sources(i); |
| 191 GURL url(source_proto.url()); | 191 GURL url(source_proto.url()); |
| 192 if (!url.is_valid()) { | 192 if (!url.is_valid()) { |
| 193 // We must at least have a valid source URL. | 193 // We must at least have a valid source URL. |
| 194 DLOG(WARNING) << "Invalid article url " << source_proto.url(); | 194 DLOG(WARNING) << "Invalid article url " << source_proto.url(); |
| 195 continue; | 195 continue; |
| 196 } | 196 } |
| 197 std::string publisher_name = source_proto.publisher_name(); | 197 std::string publisher_name = source_proto.publisher_name(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 result.set_title(title_); | 223 result.set_title(title_); |
| 224 if (!snippet_.empty()) | 224 if (!snippet_.empty()) |
| 225 result.set_snippet(snippet_); | 225 result.set_snippet(snippet_); |
| 226 if (salient_image_url_.is_valid()) | 226 if (salient_image_url_.is_valid()) |
| 227 result.set_salient_image_url(salient_image_url_.spec()); | 227 result.set_salient_image_url(salient_image_url_.spec()); |
| 228 if (!publish_date_.is_null()) | 228 if (!publish_date_.is_null()) |
| 229 result.set_publish_date(publish_date_.ToInternalValue()); | 229 result.set_publish_date(publish_date_.ToInternalValue()); |
| 230 if (!expiry_date_.is_null()) | 230 if (!expiry_date_.is_null()) |
| 231 result.set_expiry_date(expiry_date_.ToInternalValue()); | 231 result.set_expiry_date(expiry_date_.ToInternalValue()); |
| 232 result.set_score(score_); | 232 result.set_score(score_); |
| 233 result.set_discarded(is_discarded_); | 233 result.set_dismissed(is_dismissed_); |
| 234 | 234 |
| 235 for (const SnippetSource& source : sources_) { | 235 for (const SnippetSource& source : sources_) { |
| 236 SnippetSourceProto* source_proto = result.add_sources(); | 236 SnippetSourceProto* source_proto = result.add_sources(); |
| 237 source_proto->set_url(source.url.spec()); | 237 source_proto->set_url(source.url.spec()); |
| 238 if (!source.publisher_name.empty()) | 238 if (!source.publisher_name.empty()) |
| 239 source_proto->set_publisher_name(source.publisher_name); | 239 source_proto->set_publisher_name(source.publisher_name); |
| 240 if (source.amp_url.is_valid()) | 240 if (source.amp_url.is_valid()) |
| 241 source_proto->set_amp_url(source.amp_url.spec()); | 241 source_proto->set_amp_url(source.amp_url.spec()); |
| 242 } | 242 } |
| 243 | 243 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 best_source_index_ = i; | 276 best_source_index_ = i; |
| 277 if (!source.amp_url.is_empty()) { | 277 if (!source.amp_url.is_empty()) { |
| 278 // This is the best possible source, stop looking. | 278 // This is the best possible source, stop looking. |
| 279 break; | 279 break; |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace ntp_snippets | 285 } // namespace ntp_snippets |
| OLD | NEW |