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

Side by Side Diff: components/ntp_snippets/ntp_snippets_fetcher.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_snippets_fetcher.h" 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
6 6
7 #include <stdlib.h> 7 #include <cstdlib>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return true; 118 return true;
119 } 119 }
120 120
121 std::string GetFetchEndpoint() { 121 std::string GetFetchEndpoint() {
122 std::string endpoint = variations::GetVariationParamValue( 122 std::string endpoint = variations::GetVariationParamValue(
123 ntp_snippets::kStudyName, kContentSuggestionsBackend); 123 ntp_snippets::kStudyName, kContentSuggestionsBackend);
124 return endpoint.empty() ? kChromeReaderServer : endpoint; 124 return endpoint.empty() ? kChromeReaderServer : endpoint;
125 } 125 }
126 126
127 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { 127 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
128 if (endpoint == GURL(kChromeReaderServer)) { 128 if (endpoint == GURL(kChromeReaderServer))
129 return false; 129 return false;
130 } else if (endpoint != GURL(kContentSuggestionsServer) && 130
131 endpoint != GURL(kContentSuggestionsDevServer) && 131 if (endpoint != GURL(kContentSuggestionsServer) &&
132 endpoint != GURL(kContentSuggestionsAlphaServer)) { 132 endpoint != GURL(kContentSuggestionsDevServer) &&
133 endpoint != GURL(kContentSuggestionsAlphaServer)) {
133 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " 134 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": "
134 << "assuming chromecontentsuggestions-style API"; 135 << "assuming chromecontentsuggestions-style API";
135 } 136 }
136 return true; 137 return true;
137 } 138 }
138 139
139 // Creates snippets from dictionary values in |list| and adds them to 140 // Creates snippets from dictionary values in |list| and adds them to
140 // |snippets|. Returns true on success, false if anything went wrong. 141 // |snippets|. Returns true on success, false if anything went wrong.
141 bool AddSnippetsFromListValue(bool content_suggestions_api, 142 bool AddSnippetsFromListValue(bool content_suggestions_api,
142 const base::ListValue& list, 143 const base::ListValue& list,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 OAuth2TokenService* token_service, 189 OAuth2TokenService* token_service,
189 scoped_refptr<URLRequestContextGetter> url_request_context_getter, 190 scoped_refptr<URLRequestContextGetter> url_request_context_getter,
190 PrefService* pref_service, 191 PrefService* pref_service,
191 CategoryFactory* category_factory, 192 CategoryFactory* category_factory,
192 const ParseJSONCallback& parse_json_callback, 193 const ParseJSONCallback& parse_json_callback,
193 const std::string& api_key) 194 const std::string& api_key)
194 : OAuth2TokenService::Consumer("ntp_snippets"), 195 : OAuth2TokenService::Consumer("ntp_snippets"),
195 signin_manager_(signin_manager), 196 signin_manager_(signin_manager),
196 token_service_(token_service), 197 token_service_(token_service),
197 waiting_for_refresh_token_(false), 198 waiting_for_refresh_token_(false),
198 url_request_context_getter_(url_request_context_getter), 199 url_request_context_getter_(std::move(url_request_context_getter)),
199 category_factory_(category_factory), 200 category_factory_(category_factory),
200 parse_json_callback_(parse_json_callback), 201 parse_json_callback_(parse_json_callback),
202 count_to_fetch_(0),
201 fetch_url_(GetFetchEndpoint()), 203 fetch_url_(GetFetchEndpoint()),
202 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) 204 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_)
203 ? CHROME_CONTENT_SUGGESTIONS_API 205 ? CHROME_CONTENT_SUGGESTIONS_API
204 : CHROME_READER_API), 206 : CHROME_READER_API),
205 api_key_(api_key), 207 api_key_(api_key),
206 interactive_request_(false), 208 interactive_request_(false),
207 tick_clock_(new base::DefaultTickClock()), 209 tick_clock_(new base::DefaultTickClock()),
208 request_throttler_( 210 request_throttler_(
209 pref_service, 211 pref_service,
210 RequestThrottler::RequestType::CONTENT_SUGGESTION_FETCHER), 212 RequestThrottler::RequestType::CONTENT_SUGGESTION_FETCHER),
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", 664 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult",
663 static_cast<int>(result), 665 static_cast<int>(result),
664 static_cast<int>(FetchResult::RESULT_MAX)); 666 static_cast<int>(FetchResult::RESULT_MAX));
665 667
666 DVLOG(1) << "Fetch finished: " << last_status_; 668 DVLOG(1) << "Fetch finished: " << last_status_;
667 if (!snippets_available_callback_.is_null()) 669 if (!snippets_available_callback_.is_null())
668 snippets_available_callback_.Run(std::move(snippets)); 670 snippets_available_callback_.Run(std::move(snippets));
669 } 671 }
670 672
671 } // namespace ntp_snippets 673 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698