| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // LICENSE file. | 3 // found in the 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> | 12 #include "base/string16.h" |
| 13 | |
| 14 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 15 #include "testing/gtest/include/gtest/gtest_prod.h" | 14 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 16 | 15 |
| 17 class GURL; | 16 class GURL; |
| 18 class URLRequestContext; | 17 class URLRequestContext; |
| 19 | 18 |
| 20 namespace net { | 19 namespace net { |
| 21 | 20 |
| 22 class ProxyScriptFetcher { | 21 class ProxyScriptFetcher { |
| 23 public: | 22 public: |
| 24 // Destruction should cancel any outstanding requests. | 23 // Destruction should cancel any outstanding requests. |
| 25 virtual ~ProxyScriptFetcher() {} | 24 virtual ~ProxyScriptFetcher() {} |
| 26 | 25 |
| 27 // Downloads the given PAC URL, and invokes |callback| on completion. | 26 // Downloads the given PAC URL, and invokes |callback| on completion. |
| 28 // On success |callback| is executed with a result code of OK, and a | 27 // On success |callback| is executed with a result code of OK, |*utf16_text| |
| 29 // string of the response bytes (as UTF8). On failure, the result bytes is | 28 // is filled with the response. On failure, the result text is |
| 30 // an empty string, and the result code is a network error. Some special | 29 // an empty string, and the result code is a network error. Some special |
| 31 // network errors that may occur are: | 30 // network errors that may occur are: |
| 32 // | 31 // |
| 33 // ERR_TIMED_OUT -- the fetch took too long to complete. | 32 // ERR_TIMED_OUT -- the fetch took too long to complete. |
| 34 // ERR_FILE_TOO_BIG -- the response's body was too large. | 33 // ERR_FILE_TOO_BIG -- the response's body was too large. |
| 35 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. | 34 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. |
| 36 // ERR_NOT_IMPLEMENTED -- the response required authentication. | 35 // ERR_NOT_IMPLEMENTED -- the response required authentication. |
| 37 // | 36 // |
| 38 // If the request is cancelled (either using the "Cancel()" method or by | 37 // If the request is cancelled (either using the "Cancel()" method or by |
| 39 // deleting |this|), then no callback is invoked. | 38 // deleting |this|), then no callback is invoked. |
| 40 // | 39 // |
| 41 // Only one fetch is allowed to be outstanding at a time. | 40 // Only one fetch is allowed to be outstanding at a time. |
| 42 virtual int Fetch(const GURL& url, std::string* utf8_bytes, | 41 virtual int Fetch(const GURL& url, string16* utf16_text, |
| 43 CompletionCallback* callback) = 0; | 42 CompletionCallback* callback) = 0; |
| 44 | 43 |
| 45 // Aborts the in-progress fetch (if any). | 44 // Aborts the in-progress fetch (if any). |
| 46 virtual void Cancel() = 0; | 45 virtual void Cancel() = 0; |
| 47 | 46 |
| 48 // Returns the request context that this fetcher uses to issue downloads, | 47 // Returns the request context that this fetcher uses to issue downloads, |
| 49 // or NULL. | 48 // or NULL. |
| 50 virtual URLRequestContext* GetRequestContext() { return NULL; } | 49 virtual URLRequestContext* GetRequestContext() { return NULL; } |
| 51 | 50 |
| 52 // Create a ProxyScriptFetcher that uses |url_request_context|. | 51 // Create a ProxyScriptFetcher that uses |url_request_context|. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 static int SetTimeoutConstraintForUnittest(int timeout_ms); | 63 static int SetTimeoutConstraintForUnittest(int timeout_ms); |
| 65 | 64 |
| 66 // Sets the maximum response size for a fetch to |size_bytes|. Returns the | 65 // Sets the maximum response size for a fetch to |size_bytes|. Returns the |
| 67 // previous bound. | 66 // previous bound. |
| 68 static size_t SetSizeConstraintForUnittest(size_t size_bytes); | 67 static size_t SetSizeConstraintForUnittest(size_t size_bytes); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 } // namespace net | 70 } // namespace net |
| 72 | 71 |
| 73 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ | 72 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ |
| OLD | NEW |