| 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/profiler/scoped_profile.h" |
| 7 #include "components/translate/core/browser/translate_download_manager.h" | 8 #include "components/translate/core/browser/translate_download_manager.h" |
| 8 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 9 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
| 10 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
| 11 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 12 | 13 |
| 13 namespace translate { | 14 namespace translate { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); | 61 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); |
| 61 if (!extra_request_header_.empty()) | 62 if (!extra_request_header_.empty()) |
| 62 fetcher_->SetExtraRequestHeaders(extra_request_header_); | 63 fetcher_->SetExtraRequestHeaders(extra_request_header_); |
| 63 | 64 |
| 64 fetcher_->Start(); | 65 fetcher_->Start(); |
| 65 | 66 |
| 66 return true; | 67 return true; |
| 67 } | 68 } |
| 68 | 69 |
| 69 void TranslateURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 70 void TranslateURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 71 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422577 is fixed. |
| 72 tracked_objects::ScopedProfile tracking_profile( |
| 73 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 74 "422577 TranslateURLFetcher::OnURLFetchComplete")); |
| 75 |
| 70 DCHECK(fetcher_.get() == source); | 76 DCHECK(fetcher_.get() == source); |
| 71 | 77 |
| 72 std::string data; | 78 std::string data; |
| 73 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS && | 79 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS && |
| 74 source->GetResponseCode() == net::HTTP_OK) { | 80 source->GetResponseCode() == net::HTTP_OK) { |
| 75 state_ = COMPLETED; | 81 state_ = COMPLETED; |
| 76 source->GetResponseAsString(&data); | 82 source->GetResponseAsString(&data); |
| 77 } else { | 83 } else { |
| 78 state_ = FAILED; | 84 state_ = FAILED; |
| 79 } | 85 } |
| 80 | 86 |
| 81 // Transfer URLFetcher's ownership before invoking a callback. | 87 // Transfer URLFetcher's ownership before invoking a callback. |
| 82 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 88 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
| 83 callback_.Run(id_, state_ == COMPLETED, data); | 89 callback_.Run(id_, state_ == COMPLETED, data); |
| 84 } | 90 } |
| 85 | 91 |
| 86 } // namespace translate | 92 } // namespace translate |
| OLD | NEW |