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/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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 MockProxyScriptFetcher::MockProxyScriptFetcher() | 15 MockProxyScriptFetcher::MockProxyScriptFetcher() |
16 : pending_request_text_(NULL), | 16 : pending_request_text_(NULL), waiting_for_fetch_(false) { |
17 waiting_for_fetch_(false) { | |
18 } | 17 } |
19 | 18 |
20 MockProxyScriptFetcher::~MockProxyScriptFetcher() {} | 19 MockProxyScriptFetcher::~MockProxyScriptFetcher() { |
| 20 } |
21 | 21 |
22 // ProxyScriptFetcher implementation. | 22 // ProxyScriptFetcher implementation. |
23 int MockProxyScriptFetcher::Fetch(const GURL& url, base::string16* text, | 23 int MockProxyScriptFetcher::Fetch(const GURL& url, |
| 24 base::string16* text, |
24 const CompletionCallback& callback) { | 25 const CompletionCallback& callback) { |
25 DCHECK(!has_pending_request()); | 26 DCHECK(!has_pending_request()); |
26 | 27 |
27 // Save the caller's information, and have them wait. | 28 // Save the caller's information, and have them wait. |
28 pending_request_url_ = url; | 29 pending_request_url_ = url; |
29 pending_request_callback_ = callback; | 30 pending_request_callback_ = callback; |
30 pending_request_text_ = text; | 31 pending_request_text_ = text; |
31 | 32 |
32 if (waiting_for_fetch_) | 33 if (waiting_for_fetch_) |
33 base::MessageLoop::current()->Quit(); | 34 base::MessageLoop::current()->Quit(); |
34 | 35 |
35 return ERR_IO_PENDING; | 36 return ERR_IO_PENDING; |
36 } | 37 } |
37 | 38 |
38 void MockProxyScriptFetcher::NotifyFetchCompletion( | 39 void MockProxyScriptFetcher::NotifyFetchCompletion( |
39 int result, const std::string& ascii_text) { | 40 int result, |
| 41 const std::string& ascii_text) { |
40 DCHECK(has_pending_request()); | 42 DCHECK(has_pending_request()); |
41 *pending_request_text_ = base::ASCIIToUTF16(ascii_text); | 43 *pending_request_text_ = base::ASCIIToUTF16(ascii_text); |
42 CompletionCallback callback = pending_request_callback_; | 44 CompletionCallback callback = pending_request_callback_; |
43 pending_request_callback_.Reset(); | 45 pending_request_callback_.Reset(); |
44 callback.Run(result); | 46 callback.Run(result); |
45 } | 47 } |
46 | 48 |
47 void MockProxyScriptFetcher::Cancel() { | 49 void MockProxyScriptFetcher::Cancel() { |
48 } | 50 } |
49 | 51 |
(...skipping 10 matching lines...) Expand all Loading... |
60 } | 62 } |
61 | 63 |
62 void MockProxyScriptFetcher::WaitUntilFetch() { | 64 void MockProxyScriptFetcher::WaitUntilFetch() { |
63 DCHECK(!has_pending_request()); | 65 DCHECK(!has_pending_request()); |
64 waiting_for_fetch_ = true; | 66 waiting_for_fetch_ = true; |
65 base::MessageLoop::current()->Run(); | 67 base::MessageLoop::current()->Run(); |
66 waiting_for_fetch_ = false; | 68 waiting_for_fetch_ = false; |
67 } | 69 } |
68 | 70 |
69 } // namespace net | 71 } // namespace net |
OLD | NEW |