OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 // ProxyScriptFetcher is an async interface for fetching a proxy auto config | 5 // ProxyScriptFetcher is an async interface for fetching a proxy auto config |
6 // script. It is specific to fetching a PAC script; enforces timeout, max-size, | 6 // script. It is specific to fetching a PAC script; enforces timeout, max-size, |
7 // status code. | 7 // status code. |
8 | 8 |
9 #ifndef NET_PROXY_PROXY_SCRIPT_FETCHER_H_ | 9 #ifndef NET_PROXY_PROXY_SCRIPT_FETCHER_H_ |
10 #define NET_PROXY_PROXY_SCRIPT_FETCHER_H_ | 10 #define NET_PROXY_PROXY_SCRIPT_FETCHER_H_ |
11 | 11 |
| 12 #include <string> |
| 13 |
12 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
13 #include "testing/gtest/include/gtest/gtest_prod.h" | 15 #include "testing/gtest/include/gtest/gtest_prod.h" |
14 | 16 |
15 class GURL; | 17 class GURL; |
16 class URLRequestContext; | 18 class URLRequestContext; |
17 | 19 |
18 namespace net { | 20 namespace net { |
19 | 21 |
20 class ProxyScriptFetcher { | 22 class ProxyScriptFetcher { |
21 public: | 23 public: |
22 // Destruction should cancel any outstanding requests. | 24 // Destruction should cancel any outstanding requests. |
23 virtual ~ProxyScriptFetcher() {} | 25 virtual ~ProxyScriptFetcher() {} |
24 | 26 |
25 // Downloads the given PAC URL, and invokes |callback| on completion. | 27 // Downloads the given PAC URL, and invokes |callback| on completion. |
26 // On success |callback| is executed with a result code of OK, and a | 28 // On success |callback| is executed with a result code of OK, and a |
27 // string of the response bytes. On failure, the result bytes is an empty | 29 // string of the response bytes. On failure, the result bytes is an empty |
28 // string, and the result code is a network error. Some special network | 30 // string, and the result code is a network error. Some special network |
29 // errors that may occur are: | 31 // errors that may occur are: |
30 // | 32 // |
31 // ERR_TIMED_OUT -- the fetch took too long to complete. | 33 // ERR_TIMED_OUT -- the fetch took too long to complete. |
32 // ERR_FILE_TOO_BIG -- the response's body was too large. | 34 // ERR_FILE_TOO_BIG -- the response's body was too large. |
33 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. | 35 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. |
34 // ERR_NOT_IMPLEMENTED -- the response required authentication. | 36 // ERR_NOT_IMPLEMENTED -- the response required authentication. |
35 // | 37 // |
36 // If the request is cancelled (either using the "Cancel()" method or by | 38 // If the request is cancelled (either using the "Cancel()" method or by |
37 // deleting |this|), then no callback is invoked. | 39 // deleting |this|), then no callback is invoked. |
38 // | 40 // |
39 // Only one fetch is allowed to be outstanding at a time. | 41 // Only one fetch is allowed to be outstanding at a time. |
40 virtual void Fetch(const GURL& url, std::string* bytes, | 42 virtual int Fetch(const GURL& url, std::string* bytes, |
41 CompletionCallback* callback) = 0; | 43 CompletionCallback* callback) = 0; |
42 | 44 |
43 // Aborts the in-progress fetch (if any). | 45 // Aborts the in-progress fetch (if any). |
44 virtual void Cancel() = 0; | 46 virtual void Cancel() = 0; |
45 | 47 |
46 // Create a ProxyScriptFetcher that uses |url_request_context|. | 48 // Create a ProxyScriptFetcher that uses |url_request_context|. |
47 static ProxyScriptFetcher* Create(URLRequestContext* url_request_context); | 49 static ProxyScriptFetcher* Create(URLRequestContext* url_request_context); |
48 | 50 |
49 // -------------------------------------------------------------------------- | 51 // -------------------------------------------------------------------------- |
50 // Testing helpers (only available to unit-tests). | 52 // Testing helpers (only available to unit-tests). |
51 // -------------------------------------------------------------------------- | 53 // -------------------------------------------------------------------------- |
52 private: | 54 private: |
53 FRIEND_TEST(ProxyScriptFetcherTest, Hang); | 55 FRIEND_TEST(ProxyScriptFetcherTest, Hang); |
54 FRIEND_TEST(ProxyScriptFetcherTest, TooLarge); | 56 FRIEND_TEST(ProxyScriptFetcherTest, TooLarge); |
55 | 57 |
56 // Sets the maximum duration for a fetch to |timeout_ms|. Returns the previous | 58 // Sets the maximum duration for a fetch to |timeout_ms|. Returns the previous |
57 // bound. | 59 // bound. |
58 static int SetTimeoutConstraintForUnittest(int timeout_ms); | 60 static int SetTimeoutConstraintForUnittest(int timeout_ms); |
59 | 61 |
60 // Sets the maximum response size for a fetch to |size_bytes|. Returns the | 62 // Sets the maximum response size for a fetch to |size_bytes|. Returns the |
61 // previous bound. | 63 // previous bound. |
62 static size_t SetSizeConstraintForUnittest(size_t size_bytes); | 64 static size_t SetSizeConstraintForUnittest(size_t size_bytes); |
63 }; | 65 }; |
64 | 66 |
65 } // namespace net | 67 } // namespace net |
66 | 68 |
67 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ | 69 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ |
OLD | NEW |