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