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

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

Issue 2368583002: [NTP Snippets] Cleanups from clang-tidy (Closed)
Patch Set: rebase Created 4 years, 2 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
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
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 23 matching lines...) Expand all
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_dismissed_(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() = default;
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
53 // Need at least the id. 53 // Need at least the id.
54 std::string id; 54 std::string id;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 snippet->set_dismissed(proto.dismissed()); 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();
198 GURL amp_url; 197 GURL amp_url;
199 if (source_proto.has_amp_url()) { 198 if (source_proto.has_amp_url()) {
200 amp_url = GURL(source_proto.amp_url()); 199 amp_url = GURL(source_proto.amp_url());
201 DLOG_IF(WARNING, !amp_url.is_valid()) << "Invalid AMP URL " 200 DLOG_IF(WARNING, !amp_url.is_valid()) << "Invalid AMP URL "
202 << source_proto.amp_url(); 201 << source_proto.amp_url();
203 } 202 }
204 203
205 snippet->add_source(SnippetSource(url, publisher_name, amp_url)); 204 snippet->add_source(
205 SnippetSource(url, source_proto.publisher_name(), amp_url));
206 } 206 }
207 207
208 if (snippet->sources_.empty()) { 208 if (snippet->sources_.empty()) {
209 DLOG(WARNING) << "No sources found for article " << snippet->id(); 209 DLOG(WARNING) << "No sources found for article " << snippet->id();
210 return nullptr; 210 return nullptr;
211 } 211 }
212 212
213 snippet->FindBestSource(); 213 snippet->FindBestSource();
214 214
215 return snippet; 215 return snippet;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698