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(string16* text, |
| 20 CompletionCallback* callback) { |
| 21 DCHECK(!has_pending_request()); |
| 22 |
| 23 // Save the caller's information, and have them wait. |
| 24 pending_request_callback_ = callback; |
| 25 pending_request_text_ = text; |
| 26 return ERR_IO_PENDING; |
| 27 } |
| 28 |
| 29 void MockProxyScriptFetcher::NotifyFetchCompletion( |
| 30 int result, const std::string& ascii_text) { |
| 31 DCHECK(has_pending_request()); |
| 32 *pending_request_text_ = ASCIIToUTF16(ascii_text); |
| 33 CompletionCallback* callback = pending_request_callback_; |
| 34 pending_request_callback_ = NULL; |
| 35 callback->Run(result); |
| 36 } |
| 37 |
| 38 void MockProxyScriptFetcher::Cancel() { |
| 39 } |
| 40 |
| 41 URLRequestContext* MockProxyScriptFetcher::GetRequestContext() const { |
| 42 return NULL; |
| 43 } |
| 44 |
| 45 void MockProxyScriptFetcher::SetURL(const GURL& url) { |
| 46 pending_request_url_ = url; |
| 47 } |
| 48 |
| 49 const GURL& MockProxyScriptFetcher::pending_request_url() const { |
| 50 return pending_request_url_; |
| 51 } |
| 52 |
| 53 bool MockProxyScriptFetcher::has_pending_request() const { |
| 54 return pending_request_callback_ != NULL; |
| 55 } |
| 56 |
| 57 } // namespace net |
OLD | NEW |