Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this); | 63 url_fetcher_ = URLFetcher::Create(GURL(url), URLFetcher::POST, this); |
| 64 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); | 64 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
| 65 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 65 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 66 net::LOAD_DO_NOT_SAVE_COOKIES); | 66 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 67 HttpRequestHeaders headers; | 67 HttpRequestHeaders headers; |
| 68 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); | 68 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); |
| 69 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 69 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 70 url_fetcher_->SetUploadData("application/json", | 70 url_fetcher_->SetUploadData("application/json", |
| 71 kUnpersonalizedRequestParameters); | 71 kUnpersonalizedRequestParameters); |
| 72 url_fetcher_->SaveResponseToTemporaryFile(file_task_runner_.get()); | 72 url_fetcher_->SaveResponseToTemporaryFile(file_task_runner_.get()); |
| 73 | |
| 74 // Fetchers are sometimes cancelled because a network change was detected, | |
| 75 // especially at startup and after sign-in on ChromeOS. Retrying once should | |
|
Marc Treib
2016/03/23 11:50:08
I would remove everything after the first line her
jkrcal
2016/03/23 21:10:28
Done.
| |
| 76 // be enough in those cases; let the fetcher retry up to 3 times just in case. | |
| 77 // http://crbug.com/163710 | |
| 78 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); | |
| 79 // Enable fetching the files properly even with poor connection | |
|
Marc Treib
2016/03/23 11:50:08
This is IMO a bit too generic - it's more "try to
jkrcal
2016/03/23 21:10:28
Done.
| |
| 80 url_fetcher_->SetMaxRetriesOn5xx(3); | |
| 73 url_fetcher_->Start(); | 81 url_fetcher_->Start(); |
| 74 } | 82 } |
| 75 | 83 |
| 76 void NTPSnippetsFetcher::OnFileMoveDone(bool success) { | 84 void NTPSnippetsFetcher::OnFileMoveDone(bool success) { |
| 77 if (!success) { | 85 if (!success) { |
| 78 DLOG(WARNING) << "Could not move file to " | 86 DLOG(WARNING) << "Could not move file to " |
| 79 << download_path_.LossyDisplayName(); | 87 << download_path_.LossyDisplayName(); |
| 80 return; | 88 return; |
| 81 } | 89 } |
| 82 | 90 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 110 source->GetResponseAsFilePath(false, &response_path); | 118 source->GetResponseAsFilePath(false, &response_path); |
| 111 | 119 |
| 112 base::PostTaskAndReplyWithResult( | 120 base::PostTaskAndReplyWithResult( |
| 113 file_task_runner_.get(), FROM_HERE, | 121 file_task_runner_.get(), FROM_HERE, |
| 114 base::Bind(&base::Move, response_path, download_path_), | 122 base::Bind(&base::Move, response_path, download_path_), |
| 115 base::Bind(&NTPSnippetsFetcher::OnFileMoveDone, | 123 base::Bind(&NTPSnippetsFetcher::OnFileMoveDone, |
| 116 weak_ptr_factory_.GetWeakPtr())); | 124 weak_ptr_factory_.GetWeakPtr())); |
| 117 } | 125 } |
| 118 | 126 |
| 119 } // namespace ntp_snippets | 127 } // namespace ntp_snippets |
| OLD | NEW |