| 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 #ifndef NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ | 5 #ifndef NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ |
| 6 #define NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ | 6 #define NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Creates a ProxyScriptFetcher that issues requests through | 30 // Creates a ProxyScriptFetcher that issues requests through |
| 31 // |url_request_context|. |url_request_context| must remain valid for the | 31 // |url_request_context|. |url_request_context| must remain valid for the |
| 32 // lifetime of ProxyScriptFetcherImpl. | 32 // lifetime of ProxyScriptFetcherImpl. |
| 33 // Note that while a request is in progress, we will be holding a reference | 33 // Note that while a request is in progress, we will be holding a reference |
| 34 // to |url_request_context|. Be careful not to create cycles between the | 34 // to |url_request_context|. Be careful not to create cycles between the |
| 35 // fetcher and the context; you can break such cycles by calling Cancel(). | 35 // fetcher and the context; you can break such cycles by calling Cancel(). |
| 36 explicit ProxyScriptFetcherImpl(URLRequestContext* url_request_context); | 36 explicit ProxyScriptFetcherImpl(URLRequestContext* url_request_context); |
| 37 | 37 |
| 38 virtual ~ProxyScriptFetcherImpl(); | 38 virtual ~ProxyScriptFetcherImpl(); |
| 39 | 39 |
| 40 // Used by unit-tests to modify the default limits. |
| 41 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); |
| 42 size_t SetSizeConstraint(size_t size_bytes); |
| 43 |
| 44 virtual void OnResponseCompleted(URLRequest* request); |
| 45 |
| 40 // ProxyScriptFetcher methods: | 46 // ProxyScriptFetcher methods: |
| 41 | |
| 42 virtual int Fetch(const GURL& url, string16* text, | 47 virtual int Fetch(const GURL& url, string16* text, |
| 43 CompletionCallback* callback); | 48 CompletionCallback* callback); |
| 44 virtual void Cancel(); | 49 virtual void Cancel(); |
| 45 virtual URLRequestContext* GetRequestContext(); | 50 virtual URLRequestContext* GetRequestContext(); |
| 46 | 51 |
| 47 // URLRequest::Delegate methods: | 52 // URLRequest::Delegate methods: |
| 48 virtual void OnAuthRequired(URLRequest* request, | 53 virtual void OnAuthRequired(URLRequest* request, |
| 49 AuthChallengeInfo* auth_info); | 54 AuthChallengeInfo* auth_info); |
| 50 virtual void OnSSLCertificateError(URLRequest* request, int cert_error, | 55 virtual void OnSSLCertificateError(URLRequest* request, int cert_error, |
| 51 X509Certificate* cert); | 56 X509Certificate* cert); |
| 52 virtual void OnResponseStarted(URLRequest* request); | 57 virtual void OnResponseStarted(URLRequest* request); |
| 53 virtual void OnReadCompleted(URLRequest* request, int num_bytes); | 58 virtual void OnReadCompleted(URLRequest* request, int num_bytes); |
| 54 virtual void OnResponseCompleted(URLRequest* request); | |
| 55 | |
| 56 // Used by unit-tests to modify the default limits. | |
| 57 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); | |
| 58 size_t SetSizeConstraint(size_t size_bytes); | |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 enum { kBufSize = 4096 }; |
| 62 |
| 61 // Read more bytes from the response. | 63 // Read more bytes from the response. |
| 62 void ReadBody(URLRequest* request); | 64 void ReadBody(URLRequest* request); |
| 63 | 65 |
| 64 // Handles a response from Read(). Returns true if we should continue trying | 66 // Handles a response from Read(). Returns true if we should continue trying |
| 65 // to read. |num_bytes| is 0 for EOF, and < 0 on errors. | 67 // to read. |num_bytes| is 0 for EOF, and < 0 on errors. |
| 66 bool ConsumeBytesRead(URLRequest* request, int num_bytes); | 68 bool ConsumeBytesRead(URLRequest* request, int num_bytes); |
| 67 | 69 |
| 68 // Called once the request has completed to notify the caller of | 70 // Called once the request has completed to notify the caller of |
| 69 // |response_code_| and |response_text_|. | 71 // |response_code_| and |response_text_|. |
| 70 void FetchCompleted(); | 72 void FetchCompleted(); |
| 71 | 73 |
| 72 // Clear out the state for the current request. | 74 // Clear out the state for the current request. |
| 73 void ResetCurRequestState(); | 75 void ResetCurRequestState(); |
| 74 | 76 |
| 75 // Callback for time-out task of request with id |id|. | 77 // Callback for time-out task of request with id |id|. |
| 76 void OnTimeout(int id); | 78 void OnTimeout(int id); |
| 77 | 79 |
| 78 // Factory for creating the time-out task. This takes care of revoking | 80 // Factory for creating the time-out task. This takes care of revoking |
| 79 // outstanding tasks when |this| is deleted. | 81 // outstanding tasks when |this| is deleted. |
| 80 ScopedRunnableMethodFactory<ProxyScriptFetcherImpl> task_factory_; | 82 ScopedRunnableMethodFactory<ProxyScriptFetcherImpl> task_factory_; |
| 81 | 83 |
| 82 // The context used for making network requests. | 84 // The context used for making network requests. |
| 83 URLRequestContext* url_request_context_; | 85 URLRequestContext* url_request_context_; |
| 84 | 86 |
| 85 // Buffer that URLRequest writes into. | 87 // Buffer that URLRequest writes into. |
| 86 enum { kBufSize = 4096 }; | |
| 87 scoped_refptr<IOBuffer> buf_; | 88 scoped_refptr<IOBuffer> buf_; |
| 88 | 89 |
| 89 // The next ID to use for |cur_request_| (monotonically increasing). | 90 // The next ID to use for |cur_request_| (monotonically increasing). |
| 90 int next_id_; | 91 int next_id_; |
| 91 | 92 |
| 92 // The current (in progress) request, or NULL. | 93 // The current (in progress) request, or NULL. |
| 93 scoped_ptr<URLRequest> cur_request_; | 94 scoped_ptr<URLRequest> cur_request_; |
| 94 | 95 |
| 95 // State for current request (only valid when |cur_request_| is not NULL): | 96 // State for current request (only valid when |cur_request_| is not NULL): |
| 96 | 97 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 | 116 |
| 116 // The maximum amount of time to wait for download to complete. | 117 // The maximum amount of time to wait for download to complete. |
| 117 base::TimeDelta max_duration_; | 118 base::TimeDelta max_duration_; |
| 118 | 119 |
| 119 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); | 120 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 } // namespace net | 123 } // namespace net |
| 123 | 124 |
| 124 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ | 125 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ |
| OLD | NEW |