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

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

Issue 1789513003: Downloading the json file from ChromeReader is tried several times when ERR_NETW… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fetcher-sign-in
Patch Set: Rebase Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 base::StringPrintf(kAuthorizationRequestHeaderFormat, 114 base::StringPrintf(kAuthorizationRequestHeaderFormat,
115 access_token.c_str())); 115 access_token.c_str()));
116 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); 116 headers.SetHeader("Content-Type", "application/json; charset=UTF-8");
117 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); 117 url_fetcher_->SetExtraRequestHeaders(headers.ToString());
118 std::string host_restricts; 118 std::string host_restricts;
119 for (const std::string& host : hosts_) 119 for (const std::string& host : hosts_)
120 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str()); 120 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str());
121 url_fetcher_->SetUploadData("application/json", 121 url_fetcher_->SetUploadData("application/json",
122 base::StringPrintf(kRequestParameterFormat, 122 base::StringPrintf(kRequestParameterFormat,
123 host_restricts.c_str())); 123 host_restricts.c_str()));
124
125 // Fetchers are sometimes cancelled because a network change was detected.
126 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3);
127 // Try to make fetching the files bit more robust even with poor connection.
128 url_fetcher_->SetMaxRetriesOn5xx(3);
124 url_fetcher_->Start(); 129 url_fetcher_->Start();
125 } 130 }
126 131
127 void NTPSnippetsFetcher::OnGetTokenFailure( 132 void NTPSnippetsFetcher::OnGetTokenFailure(
128 const OAuth2TokenService::Request* request, 133 const OAuth2TokenService::Request* request,
129 const GoogleServiceAuthError& error) { 134 const GoogleServiceAuthError& error) {
130 oauth_request_.reset(); 135 oauth_request_.reset();
131 DLOG(ERROR) << "Unable to get token: " << error.ToString(); 136 DLOG(ERROR) << "Unable to get token: " << error.ToString();
132 } 137 }
133 138
(...skipping 26 matching lines...) Expand all
160 } 165 }
161 166
162 std::string response; 167 std::string response;
163 bool stores_result_to_string = source->GetResponseAsString(&response); 168 bool stores_result_to_string = source->GetResponseAsString(&response);
164 DCHECK(stores_result_to_string); 169 DCHECK(stores_result_to_string);
165 170
166 callback_list_.Notify(response); 171 callback_list_.Notify(response);
167 } 172 }
168 173
169 } // namespace ntp_snippets 174 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698