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