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