OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ |
6 #define CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ | 6 #define CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/timer/timer.h" |
11 #include "content/browser/loader/resource_handler.h" | 12 #include "content/browser/loader/resource_handler.h" |
12 #include "content/browser/ssl/ssl_error_handler.h" | 13 #include "content/browser/ssl/ssl_error_handler.h" |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
14 #include "content/public/browser/resource_controller.h" | 15 #include "content/public/browser/resource_controller.h" |
15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class ResourceDispatcherHostLoginDelegate; | 19 class ResourceDispatcherHostLoginDelegate; |
19 class ResourceLoaderDelegate; | 20 class ResourceLoaderDelegate; |
20 class ResourceRequestInfoImpl; | 21 class ResourceRequestInfoImpl; |
21 class SSLClientAuthHandler; | 22 class SSLClientAuthHandler; |
22 | 23 |
23 // This class is responsible for driving the URLRequest (i.e., calling Start, | 24 // This class is responsible for driving the URLRequest (i.e., calling Start, |
24 // Read, and servicing events). It has a ResourceHandler, which is typically a | 25 // Read, and servicing events). It has a ResourceHandler, which is typically a |
25 // chain of ResourceHandlers, and is the ResourceController for its handler. | 26 // chain of ResourceHandlers, and is the ResourceController for its handler. |
26 class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate, | 27 class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate, |
27 public SSLErrorHandler::Delegate, | 28 public SSLErrorHandler::Delegate, |
28 public ResourceController { | 29 public ResourceController { |
29 public: | 30 public: |
30 ResourceLoader(scoped_ptr<net::URLRequest> request, | 31 ResourceLoader(scoped_ptr<net::URLRequest> request, |
31 scoped_ptr<ResourceHandler> handler, | 32 scoped_ptr<ResourceHandler> handler, |
32 ResourceLoaderDelegate* delegate); | 33 ResourceLoaderDelegate* delegate); |
33 virtual ~ResourceLoader(); | 34 virtual ~ResourceLoader(); |
34 | 35 |
35 void StartRequest(); | 36 void StartRequest(); |
36 void CancelRequest(bool from_renderer); | 37 void CancelRequest(bool from_renderer); |
37 | 38 |
| 39 // Sets the resource as detached and starts a timer to cancel the request in |
| 40 // the future. |
| 41 void Detach(); |
| 42 |
38 void ReportUploadProgress(); | 43 void ReportUploadProgress(); |
39 | 44 |
40 bool is_transferring() const { return is_transferring_; } | 45 bool is_transferring() const { return is_transferring_; } |
41 void MarkAsTransferring(const GURL& target_url); | 46 void MarkAsTransferring(const GURL& target_url); |
42 void CompleteTransfer(); | 47 void CompleteTransfer(); |
43 | 48 |
44 net::URLRequest* request() { return request_.get(); } | 49 net::URLRequest* request() { return request_.get(); } |
45 ResourceRequestInfoImpl* GetRequestInfo(); | 50 ResourceRequestInfoImpl* GetRequestInfo(); |
46 | 51 |
47 void ClearLoginDelegate(); | 52 void ClearLoginDelegate(); |
48 void ClearSSLClientAuthHandler(); | 53 void ClearSSLClientAuthHandler(); |
49 | 54 |
50 // IPC message handlers: | 55 // IPC message handlers: |
51 void OnUploadProgressACK(); | 56 void OnUploadProgressACK(); |
52 | 57 |
| 58 void set_detachable_delay_ms(int delay) { |
| 59 detachable_delay_on_cancel_ms_ = delay; |
| 60 } |
| 61 |
53 private: | 62 private: |
54 FRIEND_TEST_ALL_PREFIXES(ResourceLoaderTest, ClientCertStoreLookup); | 63 FRIEND_TEST_ALL_PREFIXES(ResourceLoaderTest, ClientCertStoreLookup); |
55 FRIEND_TEST_ALL_PREFIXES(ResourceLoaderTest, ClientCertStoreNull); | 64 FRIEND_TEST_ALL_PREFIXES(ResourceLoaderTest, ClientCertStoreNull); |
56 | 65 |
57 // net::URLRequest::Delegate implementation: | 66 // net::URLRequest::Delegate implementation: |
58 virtual void OnReceivedRedirect(net::URLRequest* request, | 67 virtual void OnReceivedRedirect(net::URLRequest* request, |
59 const GURL& new_url, | 68 const GURL& new_url, |
60 bool* defer) OVERRIDE; | 69 bool* defer) OVERRIDE; |
61 virtual void OnAuthRequired(net::URLRequest* request, | 70 virtual void OnAuthRequired(net::URLRequest* request, |
62 net::AuthChallengeInfo* info) OVERRIDE; | 71 net::AuthChallengeInfo* info) OVERRIDE; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 uint64 last_upload_position_; | 121 uint64 last_upload_position_; |
113 bool waiting_for_upload_progress_ack_; | 122 bool waiting_for_upload_progress_ack_; |
114 base::TimeTicks last_upload_ticks_; | 123 base::TimeTicks last_upload_ticks_; |
115 base::TimeTicks read_deferral_start_time_; | 124 base::TimeTicks read_deferral_start_time_; |
116 | 125 |
117 // Indicates that we are in a state of being transferred to a new downstream | 126 // Indicates that we are in a state of being transferred to a new downstream |
118 // consumer. We are waiting for a notification to complete the transfer, at | 127 // consumer. We are waiting for a notification to complete the transfer, at |
119 // which point we'll receive a new ResourceHandler. | 128 // which point we'll receive a new ResourceHandler. |
120 bool is_transferring_; | 129 bool is_transferring_; |
121 | 130 |
| 131 int detachable_delay_on_cancel_ms_; |
| 132 scoped_ptr<base::OneShotTimer<ResourceLoader> > detached_timer_; |
| 133 |
122 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_; | 134 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_; |
123 | 135 |
124 DISALLOW_COPY_AND_ASSIGN(ResourceLoader); | 136 DISALLOW_COPY_AND_ASSIGN(ResourceLoader); |
125 }; | 137 }; |
126 | 138 |
127 } // namespace content | 139 } // namespace content |
128 | 140 |
129 #endif // CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ | 141 #endif // CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ |
OLD | NEW |