| 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 16 #include "base/task.h" | 17 #include "base/task.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "net/proxy/proxy_script_fetcher.h" | 19 #include "net/proxy/proxy_script_fetcher.h" |
| 19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 20 | 21 |
| 21 class GURL; | 22 class GURL; |
| 22 | 23 |
| 23 namespace net { | 24 namespace net { |
| 24 | 25 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 virtual ~ProxyScriptFetcherImpl(); | 41 virtual ~ProxyScriptFetcherImpl(); |
| 41 | 42 |
| 42 // Used by unit-tests to modify the default limits. | 43 // Used by unit-tests to modify the default limits. |
| 43 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); | 44 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); |
| 44 size_t SetSizeConstraint(size_t size_bytes); | 45 size_t SetSizeConstraint(size_t size_bytes); |
| 45 | 46 |
| 46 void OnResponseCompleted(URLRequest* request); | 47 void OnResponseCompleted(URLRequest* request); |
| 47 | 48 |
| 48 // ProxyScriptFetcher methods: | 49 // ProxyScriptFetcher methods: |
| 49 virtual int Fetch(const GURL& url, string16* text, | 50 virtual int Fetch(const GURL& url, string16* text, |
| 50 OldCompletionCallback* callback) OVERRIDE; | 51 const net::CompletionCallback& callback) OVERRIDE; |
| 51 virtual void Cancel() OVERRIDE; | 52 virtual void Cancel() OVERRIDE; |
| 52 virtual URLRequestContext* GetRequestContext() const OVERRIDE; | 53 virtual URLRequestContext* GetRequestContext() const OVERRIDE; |
| 53 | 54 |
| 54 // URLRequest::Delegate methods: | 55 // URLRequest::Delegate methods: |
| 55 virtual void OnAuthRequired(URLRequest* request, | 56 virtual void OnAuthRequired(URLRequest* request, |
| 56 AuthChallengeInfo* auth_info) OVERRIDE; | 57 AuthChallengeInfo* auth_info) OVERRIDE; |
| 57 virtual void OnSSLCertificateError(URLRequest* request, | 58 virtual void OnSSLCertificateError(URLRequest* request, |
| 58 const SSLInfo& ssl_info, | 59 const SSLInfo& ssl_info, |
| 59 bool is_hsts_ok) OVERRIDE; | 60 bool is_hsts_ok) OVERRIDE; |
| 60 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; | 61 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 void FetchCompleted(); | 76 void FetchCompleted(); |
| 76 | 77 |
| 77 // Clear out the state for the current request. | 78 // Clear out the state for the current request. |
| 78 void ResetCurRequestState(); | 79 void ResetCurRequestState(); |
| 79 | 80 |
| 80 // Callback for time-out task of request with id |id|. | 81 // Callback for time-out task of request with id |id|. |
| 81 void OnTimeout(int id); | 82 void OnTimeout(int id); |
| 82 | 83 |
| 83 // Factory for creating the time-out task. This takes care of revoking | 84 // Factory for creating the time-out task. This takes care of revoking |
| 84 // outstanding tasks when |this| is deleted. | 85 // outstanding tasks when |this| is deleted. |
| 85 ScopedRunnableMethodFactory<ProxyScriptFetcherImpl> task_factory_; | 86 base::WeakPtrFactory<ProxyScriptFetcherImpl> weak_factory_; |
| 86 | 87 |
| 87 // The context used for making network requests. | 88 // The context used for making network requests. |
| 88 URLRequestContext* url_request_context_; | 89 URLRequestContext* url_request_context_; |
| 89 | 90 |
| 90 // Buffer that URLRequest writes into. | 91 // Buffer that URLRequest writes into. |
| 91 scoped_refptr<IOBuffer> buf_; | 92 scoped_refptr<IOBuffer> buf_; |
| 92 | 93 |
| 93 // The next ID to use for |cur_request_| (monotonically increasing). | 94 // The next ID to use for |cur_request_| (monotonically increasing). |
| 94 int next_id_; | 95 int next_id_; |
| 95 | 96 |
| 96 // The current (in progress) request, or NULL. | 97 // The current (in progress) request, or NULL. |
| 97 scoped_ptr<URLRequest> cur_request_; | 98 scoped_ptr<URLRequest> cur_request_; |
| 98 | 99 |
| 99 // State for current request (only valid when |cur_request_| is not NULL): | 100 // State for current request (only valid when |cur_request_| is not NULL): |
| 100 | 101 |
| 101 // Unique ID for the current request. | 102 // Unique ID for the current request. |
| 102 int cur_request_id_; | 103 int cur_request_id_; |
| 103 | 104 |
| 104 // Callback to invoke on completion of the fetch. | 105 // Callback to invoke on completion of the fetch. |
| 105 OldCompletionCallback* callback_; | 106 net::CompletionCallback callback_; |
| 106 | 107 |
| 107 // Holds the error condition that was hit on the current request, or OK. | 108 // Holds the error condition that was hit on the current request, or OK. |
| 108 int result_code_; | 109 int result_code_; |
| 109 | 110 |
| 110 // Holds the bytes read so far. Will not exceed |max_response_bytes|. | 111 // Holds the bytes read so far. Will not exceed |max_response_bytes|. |
| 111 std::string bytes_read_so_far_; | 112 std::string bytes_read_so_far_; |
| 112 | 113 |
| 113 // This buffer is owned by the owner of |callback|, and will be filled with | 114 // This buffer is owned by the owner of |callback|, and will be filled with |
| 114 // UTF16 response on completion. | 115 // UTF16 response on completion. |
| 115 string16* result_text_; | 116 string16* result_text_; |
| 116 | 117 |
| 117 // The maximum number of bytes to allow in responses. | 118 // The maximum number of bytes to allow in responses. |
| 118 size_t max_response_bytes_; | 119 size_t max_response_bytes_; |
| 119 | 120 |
| 120 // The maximum amount of time to wait for download to complete. | 121 // The maximum amount of time to wait for download to complete. |
| 121 base::TimeDelta max_duration_; | 122 base::TimeDelta max_duration_; |
| 122 | 123 |
| 123 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); | 124 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 } // namespace net | 127 } // namespace net |
| 127 | 128 |
| 128 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ | 129 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ |
| OLD | NEW |