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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/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 X509Certificate; | 19 class X509Certificate; |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 class URLRequestContext; | 23 class URLRequestContext; |
24 | 24 |
25 // Implementation of ProxyScriptFetcher that downloads scripts using the | 25 // Implementation of ProxyScriptFetcher that downloads scripts using the |
26 // specified request context. | 26 // specified request context. |
27 class ProxyScriptFetcherImpl : public ProxyScriptFetcher, | 27 class ProxyScriptFetcherImpl : public URLProxyScriptFetcher, |
28 public URLRequest::Delegate { | 28 public URLRequest::Delegate { |
29 public: | 29 public: |
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. | 40 // Used by unit-tests to modify the default limits. |
41 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); | 41 base::TimeDelta SetTimeoutConstraint(base::TimeDelta timeout); |
42 size_t SetSizeConstraint(size_t size_bytes); | 42 size_t SetSizeConstraint(size_t size_bytes); |
43 | 43 |
44 virtual void OnResponseCompleted(URLRequest* request); | 44 virtual void OnResponseCompleted(URLRequest* request); |
45 | 45 |
46 // ProxyScriptFetcher methods: | 46 // URLProxyScriptFetcher methods: |
47 virtual int Fetch(const GURL& url, string16* text, | 47 virtual int Fetch(string16* text, CompletionCallback* callback) OVERRIDE; |
48 CompletionCallback* callback); | 48 virtual void Cancel() OVERRIDE; |
49 virtual void Cancel(); | 49 virtual URLRequestContext* GetRequestContext() const OVERRIDE; |
50 virtual URLRequestContext* GetRequestContext(); | 50 virtual void SetURL(const GURL& url) OVERRIDE; |
51 | 51 |
52 // URLRequest::Delegate methods: | 52 // URLRequest::Delegate methods: |
53 virtual void OnAuthRequired(URLRequest* request, | 53 virtual void OnAuthRequired(URLRequest* request, |
54 AuthChallengeInfo* auth_info); | 54 AuthChallengeInfo* auth_info); |
55 virtual void OnSSLCertificateError(URLRequest* request, int cert_error, | 55 virtual void OnSSLCertificateError(URLRequest* request, int cert_error, |
56 X509Certificate* cert); | 56 X509Certificate* cert); |
57 virtual void OnResponseStarted(URLRequest* request); | 57 virtual void OnResponseStarted(URLRequest* request); |
58 virtual void OnReadCompleted(URLRequest* request, int num_bytes); | 58 virtual void OnReadCompleted(URLRequest* request, int num_bytes); |
59 | 59 |
60 private: | 60 private: |
(...skipping 16 matching lines...) Expand all Loading... |
77 // Callback for time-out task of request with id |id|. | 77 // Callback for time-out task of request with id |id|. |
78 void OnTimeout(int id); | 78 void OnTimeout(int id); |
79 | 79 |
80 // 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 |
81 // outstanding tasks when |this| is deleted. | 81 // outstanding tasks when |this| is deleted. |
82 ScopedRunnableMethodFactory<ProxyScriptFetcherImpl> task_factory_; | 82 ScopedRunnableMethodFactory<ProxyScriptFetcherImpl> task_factory_; |
83 | 83 |
84 // The context used for making network requests. | 84 // The context used for making network requests. |
85 URLRequestContext* url_request_context_; | 85 URLRequestContext* url_request_context_; |
86 | 86 |
| 87 // The URL that should be fetched. Valid only after |SetURL()| has been |
| 88 // called. |
| 89 GURL url_; |
| 90 |
87 // Buffer that URLRequest writes into. | 91 // Buffer that URLRequest writes into. |
88 scoped_refptr<IOBuffer> buf_; | 92 scoped_refptr<IOBuffer> buf_; |
89 | 93 |
90 // The next ID to use for |cur_request_| (monotonically increasing). | 94 // The next ID to use for |cur_request_| (monotonically increasing). |
91 int next_id_; | 95 int next_id_; |
92 | 96 |
93 // The current (in progress) request, or NULL. | 97 // The current (in progress) request, or NULL. |
94 scoped_ptr<URLRequest> cur_request_; | 98 scoped_ptr<URLRequest> cur_request_; |
95 | 99 |
96 // 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): |
(...skipping 19 matching lines...) Expand all Loading... |
116 | 120 |
117 // The maximum amount of time to wait for download to complete. | 121 // The maximum amount of time to wait for download to complete. |
118 base::TimeDelta max_duration_; | 122 base::TimeDelta max_duration_; |
119 | 123 |
120 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); | 124 DISALLOW_COPY_AND_ASSIGN(ProxyScriptFetcherImpl); |
121 }; | 125 }; |
122 | 126 |
123 } // namespace net | 127 } // namespace net |
124 | 128 |
125 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ | 129 #endif // NET_PROXY_PROXY_SCRIPT_FETCHER_IMPL_H_ |
OLD | NEW |