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