| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // 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 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class URLRequestContext; | 20 class URLRequestContext; |
| 21 | 21 |
| 22 // Interface for downloading a PAC script. Implementations can enforce | 22 // Interface for downloading a PAC script. Implementations can enforce |
| 23 // timeouts, maximum size constraints, content encoding, etc.. | 23 // timeouts, maximum size constraints, content encoding, etc.. |
| 24 class ProxyScriptFetcher { | 24 class ProxyScriptFetcher { |
| 25 public: | 25 public: |
| 26 // Destruction should cancel any outstanding requests. | 26 // Destruction should cancel any outstanding requests. |
| 27 virtual ~ProxyScriptFetcher() {} | 27 virtual ~ProxyScriptFetcher() {} |
| 28 | 28 |
| 29 // Downloads the given PAC URL, and invokes |callback| on completion. | 29 // Downloads a PAC script, and invokes |callback| on completion. |
| 30 // Returns OK on success, otherwise the error code. If the return code is | 30 // Returns OK on success, otherwise the error code. If the return code is |
| 31 // ERR_IO_PENDING, then the request completes asynchronously, and |callback| | 31 // ERR_IO_PENDING, then the request completes asynchronously, and |callback| |
| 32 // will be invoked later with the final error code. | 32 // will be invoked later with the final error code. |
| 33 // After synchronous or asynchronous completion with a result code of OK, | 33 // After synchronous or asynchronous completion with a result code of OK, |
| 34 // |*utf16_text| is filled with the response. On failure, the result text is | 34 // |*utf16_text| is filled with the response. On failure, the result text is |
| 35 // an empty string, and the result code is a network error. Some special | 35 // an empty string, and the result code is a network error. Some special |
| 36 // network errors that may occur are: | 36 // network errors that may occur are: |
| 37 // | 37 // |
| 38 // ERR_TIMED_OUT -- the fetch took too long to complete. | 38 // ERR_TIMED_OUT -- the fetch took too long to complete. |
| 39 // ERR_FILE_TOO_BIG -- the response's body was too large. | 39 // ERR_FILE_TOO_BIG -- the response's body was too large. |
| 40 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. | 40 // ERR_PAC_STATUS_NOT_OK -- non-200 HTTP status code. |
| 41 // ERR_NOT_IMPLEMENTED -- the response required authentication. | 41 // ERR_NOT_IMPLEMENTED -- the response required authentication. |
| 42 // | 42 // |
| 43 // If the request is cancelled (either using the "Cancel()" method or by | 43 // If the request is cancelled (either using the "Cancel()" method or by |
| 44 // deleting |this|), then no callback is invoked. | 44 // deleting |this|), then no callback is invoked. |
| 45 // | 45 // |
| 46 // Only one fetch is allowed to be outstanding at a time. | 46 // Only one fetch is allowed to be outstanding at a time. |
| 47 virtual int Fetch(const GURL& url, string16* utf16_text, | 47 virtual int Fetch(string16* utf16_text, |
| 48 CompletionCallback* callback) = 0; | 48 CompletionCallback* callback) = 0; |
| 49 | 49 |
| 50 // Aborts the in-progress fetch (if any). | 50 // Aborts the in-progress fetch (if any). |
| 51 virtual void Cancel() = 0; | 51 virtual void Cancel() = 0; |
| 52 | 52 |
| 53 // Returns the request context that this fetcher uses to issue downloads, | 53 // Returns the request context that this fetcher uses to issue downloads, |
| 54 // or NULL. | 54 // or NULL. |
| 55 virtual URLRequestContext* GetRequestContext() = 0; | 55 virtual URLRequestContext* GetRequestContext() const = 0; |
| 56 }; |
| 57 |
| 58 // A proxy script fetcher that fetches a specific URL. |
| 59 class URLProxyScriptFetcher : public ProxyScriptFetcher { |
| 60 public: |
| 61 // Sets the URL to retrieve when Fetch() is called. |
| 62 virtual void SetURL(const GURL& url) = 0; |
| 56 }; | 63 }; |
| 57 | 64 |
| 58 } // namespace net | 65 } // namespace net |
| 59 | 66 |
| 60 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ | 67 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_H_ |
| OLD | NEW |