OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_PROXY_RESOLVER_H_ | 5 #ifndef NET_PROXY_PROXY_RESOLVER_H_ |
6 #define NET_PROXY_PROXY_RESOLVER_H_ | 6 #define NET_PROXY_PROXY_RESOLVER_H_ |
7 | 7 |
8 #include <string> | |
9 | |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string16.h" |
11 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
12 #include "net/base/completion_callback.h" | 11 #include "net/base/completion_callback.h" |
13 | 12 |
14 namespace net { | 13 namespace net { |
15 | 14 |
16 class BoundNetLog; | 15 class BoundNetLog; |
17 class ProxyInfo; | 16 class ProxyInfo; |
18 | 17 |
19 // Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies | 18 // Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies |
20 // to use for a particular URL. Generally the backend for a ProxyResolver is | 19 // to use for a particular URL. Generally the backend for a ProxyResolver is |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 47 |
49 // The PAC script backend can be specified to the ProxyResolver either via | 48 // The PAC script backend can be specified to the ProxyResolver either via |
50 // URL, or via the javascript text itself. If |expects_pac_bytes| is true, | 49 // URL, or via the javascript text itself. If |expects_pac_bytes| is true, |
51 // then PAC scripts should be specified using SetPacScriptByData(). Otherwise | 50 // then PAC scripts should be specified using SetPacScriptByData(). Otherwise |
52 // they should be specified using SetPacScriptByUrl(). | 51 // they should be specified using SetPacScriptByUrl(). |
53 bool expects_pac_bytes() const { return expects_pac_bytes_; } | 52 bool expects_pac_bytes() const { return expects_pac_bytes_; } |
54 | 53 |
55 // Sets the PAC script backend to use for this proxy resolver (by URL). | 54 // Sets the PAC script backend to use for this proxy resolver (by URL). |
56 int SetPacScriptByUrl(const GURL& url, CompletionCallback* callback) { | 55 int SetPacScriptByUrl(const GURL& url, CompletionCallback* callback) { |
57 DCHECK(!expects_pac_bytes()); | 56 DCHECK(!expects_pac_bytes()); |
58 return SetPacScript(url, std::string(), callback); | 57 return SetPacScript(url, string16(), callback); |
59 } | 58 } |
60 | 59 |
61 // Sets the PAC script backend to use for this proxy resolver (by contents). | 60 // Sets the PAC script backend to use for this proxy resolver (by contents). |
62 int SetPacScriptByData(const std::string& bytes_utf8, | 61 int SetPacScriptByData(const string16& script, |
63 CompletionCallback* callback) { | 62 CompletionCallback* callback) { |
64 DCHECK(expects_pac_bytes()); | 63 DCHECK(expects_pac_bytes()); |
65 return SetPacScript(GURL(), bytes_utf8, callback); | 64 return SetPacScript(GURL(), script, callback); |
66 } | 65 } |
67 | 66 |
68 // TODO(eroman): Make this =0. | 67 // TODO(eroman): Make this =0. |
69 virtual void CancelSetPacScript() { | 68 virtual void CancelSetPacScript() { |
70 NOTREACHED(); | 69 NOTREACHED(); |
71 } | 70 } |
72 | 71 |
73 // Frees any unneeded memory held by the resolver, e.g. garbage in the JS | 72 // Frees any unneeded memory held by the resolver, e.g. garbage in the JS |
74 // engine. Most subclasses don't need to do anything, so we provide a default | 73 // engine. Most subclasses don't need to do anything, so we provide a default |
75 // no-op implementation. | 74 // no-op implementation. |
76 virtual void PurgeMemory() {} | 75 virtual void PurgeMemory() {} |
77 | 76 |
78 private: | 77 private: |
79 // Called to set the PAC script backend to use. If |pac_url| is invalid, | 78 // Called to set the PAC script backend to use. If |pac_url| is invalid, |
80 // this is a request to use WPAD (auto detect). |bytes_utf8| may be empty if | 79 // this is a request to use WPAD (auto detect). |pac_script| may be empty if |
81 // the fetch failed, or if the fetch returned no content. | 80 // the fetch failed, or if the fetch returned no content. |
82 // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies | 81 // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies |
83 // the result through |callback|. | 82 // the result through |callback|. |
84 virtual int SetPacScript(const GURL& pac_url, | 83 virtual int SetPacScript(const GURL& pac_url, |
85 const std::string& bytes_utf8, | 84 const string16& pac_script, |
86 CompletionCallback* callback) = 0; | 85 CompletionCallback* callback) = 0; |
87 | 86 |
88 const bool expects_pac_bytes_; | 87 const bool expects_pac_bytes_; |
89 | 88 |
90 DISALLOW_COPY_AND_ASSIGN(ProxyResolver); | 89 DISALLOW_COPY_AND_ASSIGN(ProxyResolver); |
91 }; | 90 }; |
92 | 91 |
93 } // namespace net | 92 } // namespace net |
94 | 93 |
95 #endif // NET_PROXY_PROXY_RESOLVER_H_ | 94 #endif // NET_PROXY_PROXY_RESOLVER_H_ |
OLD | NEW |