OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_LOADER_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_LOADER_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "content/browser/renderer_host/resource_handler.h" | |
11 #include "content/browser/ssl/ssl_error_handler.h" | |
12 #include "content/public/browser/resource_controller.h" | |
13 #include "net/url_request/url_request.h" | |
14 | |
15 namespace content { | |
16 class ResourceDispatcherHostLoginDelegate; | |
17 class ResourceLoaderDelegate; | |
18 class ResourceRequestInfoImpl; | |
19 class SSLClientAuthHandler; | |
20 | |
21 // This class is responsible for driving the URLRequest (i.e., calling Start, | |
22 // Read, and servicing events). It has a ResourceHandler, which is typically a | |
23 // chain of ResourceHandlers, and is the ResourceController for its handler. | |
24 class ResourceLoader : public net::URLRequest::Delegate, | |
25 public SSLErrorHandler::Delegate, | |
26 public ResourceController { | |
27 public: | |
28 ResourceLoader(scoped_ptr<net::URLRequest> request, | |
29 scoped_ptr<ResourceHandler> handler, | |
30 ResourceLoaderDelegate* delegate); | |
31 virtual ~ResourceLoader(); | |
32 | |
33 void StartRequest(); | |
34 void CancelRequest(bool from_renderer); | |
35 | |
36 void ReportUploadProgress(); | |
37 | |
38 bool is_transferring() const { return is_transferring_; } | |
39 void MarkAsTransferring(); | |
40 void WillCompleteTransfer(); | |
41 void CompleteTransfer(scoped_ptr<ResourceHandler> new_handler); | |
42 | |
43 net::URLRequest* request() { return request_.get(); } | |
44 ResourceRequestInfoImpl* GetRequestInfo(); | |
45 | |
46 void ClearLoginDelegate(); | |
47 void ClearSSLClientAuthHandler(); | |
48 | |
49 // IPC message handlers: | |
50 void OnUploadProgressACK(); | |
51 | |
52 private: | |
53 // net::URLRequest::Delegate implementation: | |
54 virtual void OnReceivedRedirect(net::URLRequest* request, | |
55 const GURL& new_url, | |
56 bool* defer) OVERRIDE; | |
57 virtual void OnAuthRequired(net::URLRequest* request, | |
58 net::AuthChallengeInfo* info) OVERRIDE; | |
59 virtual void OnCertificateRequested(net::URLRequest* request, | |
60 net::SSLCertRequestInfo* info) OVERRIDE; | |
61 virtual void OnSSLCertificateError(net::URLRequest* request, | |
62 const net::SSLInfo& info, | |
63 bool fatal) OVERRIDE; | |
64 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | |
65 virtual void OnReadCompleted(net::URLRequest* request, | |
66 int bytes_read) OVERRIDE; | |
67 | |
68 // SSLErrorHandler::Delegate implementation: | |
69 virtual void CancelSSLRequest(const GlobalRequestID& id, | |
70 int error, | |
71 const net::SSLInfo* ssl_info) OVERRIDE; | |
72 virtual void ContinueSSLRequest(const GlobalRequestID& id) OVERRIDE; | |
73 | |
74 // ResourceController implementation: | |
75 virtual void Resume() OVERRIDE; | |
76 virtual void Cancel() OVERRIDE; | |
77 virtual void CancelAndIgnore() OVERRIDE; | |
78 virtual void CancelWithError(int error_code) OVERRIDE; | |
79 | |
80 void StartRequestInternal(); | |
81 void CancelRequestInternal(int error, bool from_renderer); | |
82 void CompleteResponseStarted(); | |
83 void StartReading(bool is_continuation); | |
84 void ResumeReading(); | |
85 void ReadMore(int* bytes_read); | |
86 void CompleteRead(int bytes_read); | |
87 void ResponseCompleted(); | |
88 void CallDidFinishLoading(); | |
89 | |
90 bool is_deferred() const { return deferred_stage_ != DEFERRED_NONE; } | |
91 | |
92 enum DeferredStage { | |
93 DEFERRED_NONE, | |
94 DEFERRED_START, | |
95 DEFERRED_REDIRECT, | |
96 DEFERRED_READ, | |
97 DEFERRED_FINISH | |
98 }; | |
99 DeferredStage deferred_stage_; | |
100 | |
101 scoped_ptr<net::URLRequest> request_; | |
102 scoped_ptr<ResourceHandler> handler_; | |
103 ResourceLoaderDelegate* delegate_; | |
104 | |
105 scoped_refptr<ResourceDispatcherHostLoginDelegate> login_delegate_; | |
106 scoped_refptr<SSLClientAuthHandler> ssl_client_auth_handler_; | |
107 | |
108 uint64 last_upload_position_; | |
109 bool waiting_for_upload_progress_ack_; | |
110 base::TimeTicks last_upload_ticks_; | |
111 | |
112 // Indicates that we are in a state of being transferred to a new downstream | |
113 // consumer. We are waiting for a notification to complete the transfer, at | |
114 // which point we'll receive a new ResourceHandler. | |
115 bool is_transferring_; | |
116 | |
117 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(ResourceLoader); | |
120 }; | |
121 | |
122 } // namespace content | |
123 | |
124 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_LOADER_H_ | |
OLD | NEW |