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