| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_script_fetcher_impl.h" | 5 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 cur_request_->GetCharset(&charset); | 288 cur_request_->GetCharset(&charset); |
| 289 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_); | 289 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_); |
| 290 } else { | 290 } else { |
| 291 // On error, the caller expects empty string for bytes. | 291 // On error, the caller expects empty string for bytes. |
| 292 result_text_->clear(); | 292 result_text_->clear(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 int result_code = result_code_; | 295 int result_code = result_code_; |
| 296 CompletionCallback callback = callback_; | 296 CompletionCallback callback = callback_; |
| 297 | 297 |
| 298 // Hold a reference to the URLRequestContext to prevent re-entrancy from | |
| 299 // ~URLRequestContext. | |
| 300 scoped_refptr<const URLRequestContext> context(cur_request_->context()); | |
| 301 ResetCurRequestState(); | 298 ResetCurRequestState(); |
| 302 | 299 |
| 303 callback.Run(result_code); | 300 callback.Run(result_code); |
| 304 } | 301 } |
| 305 | 302 |
| 306 void ProxyScriptFetcherImpl::ResetCurRequestState() { | 303 void ProxyScriptFetcherImpl::ResetCurRequestState() { |
| 307 cur_request_.reset(); | 304 cur_request_.reset(); |
| 308 cur_request_id_ = 0; | 305 cur_request_id_ = 0; |
| 309 callback_.Reset(); | 306 callback_.Reset(); |
| 310 result_code_ = OK; | 307 result_code_ = OK; |
| 311 result_text_ = NULL; | 308 result_text_ = NULL; |
| 312 } | 309 } |
| 313 | 310 |
| 314 void ProxyScriptFetcherImpl::OnTimeout(int id) { | 311 void ProxyScriptFetcherImpl::OnTimeout(int id) { |
| 315 // Timeout tasks may outlive the URLRequest they reference. Make sure it | 312 // Timeout tasks may outlive the URLRequest they reference. Make sure it |
| 316 // is still applicable. | 313 // is still applicable. |
| 317 if (cur_request_id_ != id) | 314 if (cur_request_id_ != id) |
| 318 return; | 315 return; |
| 319 | 316 |
| 320 DCHECK(cur_request_.get()); | 317 DCHECK(cur_request_.get()); |
| 321 result_code_ = ERR_TIMED_OUT; | 318 result_code_ = ERR_TIMED_OUT; |
| 322 cur_request_->Cancel(); | 319 cur_request_->Cancel(); |
| 323 } | 320 } |
| 324 | 321 |
| 325 } // namespace net | 322 } // namespace net |
| OLD | NEW |