| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mock_proxy_script_fetcher.h" | 5 #include "net/proxy/mock_proxy_script_fetcher.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 MockProxyScriptFetcher::MockProxyScriptFetcher() | 14 MockProxyScriptFetcher::MockProxyScriptFetcher() |
| 15 : pending_request_callback_(NULL), pending_request_text_(NULL) { | 15 : pending_request_text_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 // ProxyScriptFetcher implementation. | 18 // ProxyScriptFetcher implementation. |
| 19 int MockProxyScriptFetcher::Fetch(const GURL& url, | 19 int MockProxyScriptFetcher::Fetch(const GURL& url, string16* text, |
| 20 string16* text, | 20 const CompletionCallback& callback) { |
| 21 OldCompletionCallback* callback) { | |
| 22 DCHECK(!has_pending_request()); | 21 DCHECK(!has_pending_request()); |
| 23 | 22 |
| 24 // Save the caller's information, and have them wait. | 23 // Save the caller's information, and have them wait. |
| 25 pending_request_url_ = url; | 24 pending_request_url_ = url; |
| 26 pending_request_callback_ = callback; | 25 pending_request_callback_ = callback; |
| 27 pending_request_text_ = text; | 26 pending_request_text_ = text; |
| 28 return ERR_IO_PENDING; | 27 return ERR_IO_PENDING; |
| 29 } | 28 } |
| 30 | 29 |
| 31 void MockProxyScriptFetcher::NotifyFetchCompletion( | 30 void MockProxyScriptFetcher::NotifyFetchCompletion( |
| 32 int result, const std::string& ascii_text) { | 31 int result, const std::string& ascii_text) { |
| 33 DCHECK(has_pending_request()); | 32 DCHECK(has_pending_request()); |
| 34 *pending_request_text_ = ASCIIToUTF16(ascii_text); | 33 *pending_request_text_ = ASCIIToUTF16(ascii_text); |
| 35 OldCompletionCallback* callback = pending_request_callback_; | 34 CompletionCallback callback = pending_request_callback_; |
| 36 pending_request_callback_ = NULL; | 35 pending_request_callback_.Reset(); |
| 37 callback->Run(result); | 36 callback.Run(result); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void MockProxyScriptFetcher::Cancel() { | 39 void MockProxyScriptFetcher::Cancel() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 URLRequestContext* MockProxyScriptFetcher::GetRequestContext() const { | 42 URLRequestContext* MockProxyScriptFetcher::GetRequestContext() const { |
| 44 return NULL; | 43 return NULL; |
| 45 } | 44 } |
| 46 | 45 |
| 47 const GURL& MockProxyScriptFetcher::pending_request_url() const { | 46 const GURL& MockProxyScriptFetcher::pending_request_url() const { |
| 48 return pending_request_url_; | 47 return pending_request_url_; |
| 49 } | 48 } |
| 50 | 49 |
| 51 bool MockProxyScriptFetcher::has_pending_request() const { | 50 bool MockProxyScriptFetcher::has_pending_request() const { |
| 52 return pending_request_callback_ != NULL; | 51 return !pending_request_callback_.is_null(); |
| 53 } | 52 } |
| 54 | 53 |
| 55 } // namespace net | 54 } // namespace net |
| OLD | NEW |