| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/translate/core/browser/translate_url_fetcher.h" | 5 #include "components/translate/core/browser/translate_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" |
| 7 #include "components/data_use_measurement/core/data_use_user_data.h" | 8 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 8 #include "components/translate/core/browser/translate_download_manager.h" | 9 #include "components/translate/core/browser/translate_download_manager.h" |
| 9 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
| 10 #include "net/http/http_status_code.h" | 11 #include "net/http/http_status_code.h" |
| 11 #include "net/url_request/url_fetcher.h" | 12 #include "net/url_request/url_fetcher.h" |
| 12 #include "net/url_request/url_request_status.h" | 13 #include "net/url_request/url_request_status.h" |
| 13 | 14 |
| 14 namespace translate { | 15 namespace translate { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 39 } | 40 } |
| 40 | 41 |
| 41 if (retry_count_ >= kMaxRetry) | 42 if (retry_count_ >= kMaxRetry) |
| 42 return false; | 43 return false; |
| 43 retry_count_++; | 44 retry_count_++; |
| 44 | 45 |
| 45 state_ = REQUESTING; | 46 state_ = REQUESTING; |
| 46 url_ = url; | 47 url_ = url; |
| 47 callback_ = callback; | 48 callback_ = callback; |
| 48 | 49 |
| 50 // If the TranslateDownloadManager's request context getter is nullptr then |
| 51 // shutdown is in progress. Abort the request, which can't proceed with a |
| 52 // null request_context_getter. |
| 53 scoped_refptr<net::URLRequestContextGetter> request_context_getter = |
| 54 TranslateDownloadManager::GetInstance()->request_context(); |
| 55 if (request_context_getter == nullptr) |
| 56 return false; |
| 57 |
| 58 // Create and initialize the URL fetcher. |
| 49 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); | 59 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); |
| 50 data_use_measurement::DataUseUserData::AttachToFetcher( | 60 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 51 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); | 61 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); |
| 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 62 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 53 net::LOAD_DO_NOT_SAVE_COOKIES); | 63 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 54 fetcher_->SetRequestContext( | 64 fetcher_->SetRequestContext(request_context_getter.get()); |
| 55 TranslateDownloadManager::GetInstance()->request_context()); | 65 |
| 56 // Set retry parameter for HTTP status code 5xx. This doesn't work against | 66 // Set retry parameter for HTTP status code 5xx. This doesn't work against |
| 57 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. | 67 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. |
| 58 // TranslateLanguageList handles network status, and implements retry. | 68 // TranslateLanguageList handles network status, and implements retry. |
| 59 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); | 69 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); |
| 60 if (!extra_request_header_.empty()) | 70 if (!extra_request_header_.empty()) |
| 61 fetcher_->SetExtraRequestHeaders(extra_request_header_); | 71 fetcher_->SetExtraRequestHeaders(extra_request_header_); |
| 62 | 72 |
| 63 fetcher_->Start(); | 73 fetcher_->Start(); |
| 64 | 74 |
| 65 return true; | 75 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 } else { | 86 } else { |
| 77 state_ = FAILED; | 87 state_ = FAILED; |
| 78 } | 88 } |
| 79 | 89 |
| 80 // Transfer URLFetcher's ownership before invoking a callback. | 90 // Transfer URLFetcher's ownership before invoking a callback. |
| 81 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 91 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
| 82 callback_.Run(id_, state_ == COMPLETED, data); | 92 callback_.Run(id_, state_ == COMPLETED, data); |
| 83 } | 93 } |
| 84 | 94 |
| 85 } // namespace translate | 95 } // namespace translate |
| OLD | NEW |