Index: components/ntp_snippets/ntp_snippets_fetcher.cc |
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc |
index c0018e7d816ad650ff06f25bdf664b5b64034e2e..e16278cb145fee138bd80721b0a4709c9be39002 100644 |
--- a/components/ntp_snippets/ntp_snippets_fetcher.cc |
+++ b/components/ntp_snippets/ntp_snippets_fetcher.cc |
@@ -106,7 +106,7 @@ bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { |
endpoint != GURL(kContentSuggestionsDevServer) && |
endpoint != GURL(kContentSuggestionsAlphaServer)) { |
LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " |
- << "assuming chromecontentsuggestions-style API"; |
+ << "assuming chromecontentsuggestions-style API"; |
} |
return true; |
} |
@@ -169,6 +169,7 @@ NTPSnippetsFetcher::NTPSnippetsFetcher( |
? CHROME_CONTENT_SUGGESTIONS_API |
: CHROME_READER_API), |
is_stable_channel_(is_stable_channel), |
+ interactive_request_(false), |
tick_clock_(new base::DefaultTickClock()), |
request_throttler_( |
pref_service, |
@@ -234,6 +235,7 @@ void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
count_to_fetch_ = count; |
bool use_authentication = UsesAuthentication(); |
+ interactive_request_ = interactive_request; |
if (use_authentication && signin_manager_->IsAuthenticated()) { |
// Signed-in: get OAuth token --> fetch snippets. |
@@ -322,6 +324,8 @@ std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { |
regular_hosts->AppendString(host); |
} |
request->Set("regularlyVisitedHostNames", std::move(regular_hosts)); |
+ request->SetString("type", |
+ interactive_request ? "INTERACTIVE" : "BACKGROUND"); |
// TODO(sfiera): support authentication and personalization |
// TODO(sfiera): support count_to_fetch |
@@ -361,7 +365,8 @@ void NTPSnippetsFetcher::FetchSnippetsImpl(const GURL& url, |
url_fetcher_->SetUploadData("application/json", request); |
// Log the request for debugging network issues. |
VLOG(1) << "Sending a NTP snippets request to " << url << ":" << std::endl |
- << headers.ToString() << std::endl << request; |
+ << headers.ToString() << std::endl |
+ << request; |
// Fetchers are sometimes cancelled because a network change was detected. |
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); |
// Try to make fetching the files bit more robust even with poor connection. |
@@ -393,6 +398,7 @@ void NTPSnippetsFetcher::FetchSnippetsNonAuthenticated() { |
params.host_restricts = |
UsesHostRestrictions() ? hosts_ : std::set<std::string>(); |
params.count_to_fetch = count_to_fetch_; |
+ params.interactive_request = interactive_request_; |
FetchSnippetsImpl(url, std::string(), params.BuildRequest()); |
} |
@@ -408,6 +414,7 @@ void NTPSnippetsFetcher::FetchSnippetsAuthenticated( |
params.host_restricts = |
UsesHostRestrictions() ? hosts_ : std::set<std::string>(); |
params.count_to_fetch = count_to_fetch_; |
+ params.interactive_request = interactive_request_; |
// TODO(jkrcal, treib): Add unit-tests for authenticated fetches. |
FetchSnippetsImpl(fetch_url_, |
base::StringPrintf(kAuthorizationRequestHeaderFormat, |
@@ -497,16 +504,15 @@ void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { |
OptionalSnippets(), FetchResult::HTTP_ERROR, |
/*extra_message=*/base::StringPrintf(" %d", source->GetResponseCode())); |
} else { |
- bool stores_result_to_string = source->GetResponseAsString( |
- &last_fetch_json_); |
+ bool stores_result_to_string = |
+ source->GetResponseAsString(&last_fetch_json_); |
DCHECK(stores_result_to_string); |
- parse_json_callback_.Run( |
- last_fetch_json_, |
- base::Bind(&NTPSnippetsFetcher::OnJsonParsed, |
- weak_ptr_factory_.GetWeakPtr()), |
- base::Bind(&NTPSnippetsFetcher::OnJsonError, |
- weak_ptr_factory_.GetWeakPtr())); |
+ parse_json_callback_.Run(last_fetch_json_, |
+ base::Bind(&NTPSnippetsFetcher::OnJsonParsed, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::Bind(&NTPSnippetsFetcher::OnJsonError, |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
} |
@@ -572,8 +578,8 @@ void NTPSnippetsFetcher::OnJsonParsed(std::unique_ptr<base::Value> parsed) { |
} |
void NTPSnippetsFetcher::OnJsonError(const std::string& error) { |
- LOG(WARNING) << "Received invalid JSON (" << error << "): " |
- << last_fetch_json_; |
+ LOG(WARNING) << "Received invalid JSON (" << error |
+ << "): " << last_fetch_json_; |
Marc Treib
2016/08/25 09:26:58
Was this auto-formatted?! (It's fine either way, I
vitaliii
2016/08/26 09:13:46
Yes.
Eclipse format happened to differ from git c
|
FetchFinished( |
OptionalSnippets(), FetchResult::JSON_PARSE_ERROR, |
/*extra_message=*/base::StringPrintf(" (error %s)", error.c_str())); |