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