| 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" | |
| 8 #include "components/translate/core/browser/translate_download_manager.h" | 7 #include "components/translate/core/browser/translate_download_manager.h" |
| 9 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
| 10 #include "net/http/http_status_code.h" | 9 #include "net/http/http_status_code.h" |
| 11 #include "net/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
| 12 #include "net/url_request/url_request_status.h" | 11 #include "net/url_request/url_request_status.h" |
| 13 | 12 |
| 14 namespace translate { | 13 namespace translate { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 40 | 39 |
| 41 if (retry_count_ >= kMaxRetry) | 40 if (retry_count_ >= kMaxRetry) |
| 42 return false; | 41 return false; |
| 43 retry_count_++; | 42 retry_count_++; |
| 44 | 43 |
| 45 state_ = REQUESTING; | 44 state_ = REQUESTING; |
| 46 url_ = url; | 45 url_ = url; |
| 47 callback_ = callback; | 46 callback_ = callback; |
| 48 | 47 |
| 49 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); | 48 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); |
| 50 data_use_measurement::DataUseUserData::AttachToFetcher( | |
| 51 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); | |
| 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 49 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 53 net::LOAD_DO_NOT_SAVE_COOKIES); | 50 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 54 fetcher_->SetRequestContext( | 51 fetcher_->SetRequestContext( |
| 55 TranslateDownloadManager::GetInstance()->request_context()); | 52 TranslateDownloadManager::GetInstance()->request_context()); |
| 56 // Set retry parameter for HTTP status code 5xx. This doesn't work against | 53 // Set retry parameter for HTTP status code 5xx. This doesn't work against |
| 57 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. | 54 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. |
| 58 // TranslateLanguageList handles network status, and implements retry. | 55 // TranslateLanguageList handles network status, and implements retry. |
| 59 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); | 56 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); |
| 60 if (!extra_request_header_.empty()) | 57 if (!extra_request_header_.empty()) |
| 61 fetcher_->SetExtraRequestHeaders(extra_request_header_); | 58 fetcher_->SetExtraRequestHeaders(extra_request_header_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 } else { | 73 } else { |
| 77 state_ = FAILED; | 74 state_ = FAILED; |
| 78 } | 75 } |
| 79 | 76 |
| 80 // Transfer URLFetcher's ownership before invoking a callback. | 77 // Transfer URLFetcher's ownership before invoking a callback. |
| 81 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 78 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
| 82 callback_.Run(id_, state_ == COMPLETED, data); | 79 callback_.Run(id_, state_ == COMPLETED, data); |
| 83 } | 80 } |
| 84 | 81 |
| 85 } // namespace translate | 82 } // namespace translate |
| OLD | NEW |