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