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 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 5 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/proxy/proxy_resolver.h" | 13 #include "net/proxy/proxy_resolver.h" |
14 | 14 |
| 15 namespace base { |
15 class MessageLoop; | 16 class MessageLoop; |
| 17 } |
16 | 18 |
17 namespace net { | 19 namespace net { |
18 | 20 |
19 // Asynchronous mock proxy resolver. All requests complete asynchronously, | 21 // Asynchronous mock proxy resolver. All requests complete asynchronously, |
20 // user must call Request::CompleteNow() on a pending request to signal it. | 22 // user must call Request::CompleteNow() on a pending request to signal it. |
21 class MockAsyncProxyResolverBase : public ProxyResolver { | 23 class MockAsyncProxyResolverBase : public ProxyResolver { |
22 public: | 24 public: |
23 class Request : public base::RefCounted<Request> { | 25 class Request : public base::RefCounted<Request> { |
24 public: | 26 public: |
25 Request(MockAsyncProxyResolverBase* resolver, | 27 Request(MockAsyncProxyResolverBase* resolver, |
26 const GURL& url, | 28 const GURL& url, |
27 ProxyInfo* results, | 29 ProxyInfo* results, |
28 const net::CompletionCallback& callback); | 30 const net::CompletionCallback& callback); |
29 | 31 |
30 const GURL& url() const { return url_; } | 32 const GURL& url() const { return url_; } |
31 ProxyInfo* results() const { return results_; } | 33 ProxyInfo* results() const { return results_; } |
32 const net::CompletionCallback& callback() const { return callback_; } | 34 const net::CompletionCallback& callback() const { return callback_; } |
33 | 35 |
34 void CompleteNow(int rv); | 36 void CompleteNow(int rv); |
35 | 37 |
36 private: | 38 private: |
37 friend class base::RefCounted<Request>; | 39 friend class base::RefCounted<Request>; |
38 | 40 |
39 virtual ~Request(); | 41 virtual ~Request(); |
40 | 42 |
41 MockAsyncProxyResolverBase* resolver_; | 43 MockAsyncProxyResolverBase* resolver_; |
42 const GURL url_; | 44 const GURL url_; |
43 ProxyInfo* results_; | 45 ProxyInfo* results_; |
44 net::CompletionCallback callback_; | 46 net::CompletionCallback callback_; |
45 MessageLoop* origin_loop_; | 47 base::MessageLoop* origin_loop_; |
46 }; | 48 }; |
47 | 49 |
48 class SetPacScriptRequest { | 50 class SetPacScriptRequest { |
49 public: | 51 public: |
50 SetPacScriptRequest( | 52 SetPacScriptRequest( |
51 MockAsyncProxyResolverBase* resolver, | 53 MockAsyncProxyResolverBase* resolver, |
52 const scoped_refptr<ProxyResolverScriptData>& script_data, | 54 const scoped_refptr<ProxyResolverScriptData>& script_data, |
53 const net::CompletionCallback& callback); | 55 const net::CompletionCallback& callback); |
54 ~SetPacScriptRequest(); | 56 ~SetPacScriptRequest(); |
55 | 57 |
56 const ProxyResolverScriptData* script_data() const { return script_data_; } | 58 const ProxyResolverScriptData* script_data() const { return script_data_; } |
57 | 59 |
58 void CompleteNow(int rv); | 60 void CompleteNow(int rv); |
59 | 61 |
60 private: | 62 private: |
61 MockAsyncProxyResolverBase* resolver_; | 63 MockAsyncProxyResolverBase* resolver_; |
62 const scoped_refptr<ProxyResolverScriptData> script_data_; | 64 const scoped_refptr<ProxyResolverScriptData> script_data_; |
63 net::CompletionCallback callback_; | 65 net::CompletionCallback callback_; |
64 MessageLoop* origin_loop_; | 66 base::MessageLoop* origin_loop_; |
65 }; | 67 }; |
66 | 68 |
67 typedef std::vector<scoped_refptr<Request> > RequestsList; | 69 typedef std::vector<scoped_refptr<Request> > RequestsList; |
68 | 70 |
69 virtual ~MockAsyncProxyResolverBase(); | 71 virtual ~MockAsyncProxyResolverBase(); |
70 | 72 |
71 // ProxyResolver implementation. | 73 // ProxyResolver implementation. |
72 virtual int GetProxyForURL(const GURL& url, | 74 virtual int GetProxyForURL(const GURL& url, |
73 ProxyInfo* results, | 75 ProxyInfo* results, |
74 const net::CompletionCallback& callback, | 76 const net::CompletionCallback& callback, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 118 |
117 class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase { | 119 class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase { |
118 public: | 120 public: |
119 MockAsyncProxyResolverExpectsBytes() | 121 MockAsyncProxyResolverExpectsBytes() |
120 : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {} | 122 : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {} |
121 }; | 123 }; |
122 | 124 |
123 } // namespace net | 125 } // namespace net |
124 | 126 |
125 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 127 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
OLD | NEW |