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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/common/resource_dispatcher.h" | 7 #include "content/common/resource_dispatcher.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "content/common/inter_process_time_ticks_converter.h" | 16 #include "content/common/inter_process_time_ticks_converter.h" |
17 #include "content/common/request_extra_data.h" | 17 #include "content/common/request_extra_data.h" |
18 #include "content/common/resource_messages.h" | 18 #include "content/common/resource_messages.h" |
19 #include "content/public/common/resource_dispatcher_delegate.h" | 19 #include "content/public/common/resource_dispatcher_delegate.h" |
20 #include "content/public/common/resource_response.h" | 20 #include "content/public/common/resource_response.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "net/base/upload_data.h" | |
24 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 24 #include "webkit/glue/resource_request_body.h" |
25 #include "webkit/glue/resource_type.h" | 25 #include "webkit/glue/resource_type.h" |
26 | 26 |
27 using webkit_glue::ResourceLoaderBridge; | 27 using webkit_glue::ResourceLoaderBridge; |
| 28 using webkit_glue::ResourceRequestBody; |
28 using webkit_glue::ResourceResponseInfo; | 29 using webkit_glue::ResourceResponseInfo; |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
32 // Each resource request is assigned an ID scoped to this process. | 33 // Each resource request is assigned an ID scoped to this process. |
33 static int MakeRequestID() { | 34 static int MakeRequestID() { |
34 // NOTE: The resource_dispatcher_host also needs probably unique | 35 // NOTE: The resource_dispatcher_host also needs probably unique |
35 // request_ids, so they count down from -2 (-1 is a special we're | 36 // request_ids, so they count down from -2 (-1 is a special we're |
36 // screwed value), while the renderer process counts up. | 37 // screwed value), while the renderer process counts up. |
37 static int next_request_id = 0; | 38 static int next_request_id = 0; |
38 return next_request_id++; | 39 return next_request_id++; |
39 } | 40 } |
40 | 41 |
41 // ResourceLoaderBridge implementation ---------------------------------------- | 42 // ResourceLoaderBridge implementation ---------------------------------------- |
42 | 43 |
43 class IPCResourceLoaderBridge : public ResourceLoaderBridge { | 44 class IPCResourceLoaderBridge : public ResourceLoaderBridge { |
44 public: | 45 public: |
45 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | 46 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, |
46 const ResourceLoaderBridge::RequestInfo& request_info); | 47 const ResourceLoaderBridge::RequestInfo& request_info); |
47 virtual ~IPCResourceLoaderBridge(); | 48 virtual ~IPCResourceLoaderBridge(); |
48 | 49 |
49 // ResourceLoaderBridge | 50 // ResourceLoaderBridge |
50 virtual void AppendDataToUpload(const char* data, int data_len); | 51 virtual void SetRequestBody(ResourceRequestBody* request_body); |
51 virtual void AppendFileRangeToUpload( | |
52 const FilePath& path, | |
53 uint64 offset, | |
54 uint64 length, | |
55 const base::Time& expected_modification_time); | |
56 virtual void AppendBlobToUpload(const GURL& blob_url); | |
57 virtual void SetUploadIdentifier(int64 identifier); | |
58 virtual bool Start(Peer* peer); | 52 virtual bool Start(Peer* peer); |
59 virtual void Cancel(); | 53 virtual void Cancel(); |
60 virtual void SetDefersLoading(bool value); | 54 virtual void SetDefersLoading(bool value); |
61 virtual void SyncLoad(SyncLoadResponse* response); | 55 virtual void SyncLoad(SyncLoadResponse* response); |
62 | 56 |
63 private: | 57 private: |
64 ResourceLoaderBridge::Peer* peer_; | 58 ResourceLoaderBridge::Peer* peer_; |
65 | 59 |
66 // The resource dispatcher for this loader. The bridge doesn't own it, but | 60 // The resource dispatcher for this loader. The bridge doesn't own it, but |
67 // it's guaranteed to outlive the bridge. | 61 // it's guaranteed to outlive the bridge. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // removed us when the renderer sends the ReceivedAllData message. | 129 // removed us when the renderer sends the ReceivedAllData message. |
136 dispatcher_->RemovePendingRequest(request_id_); | 130 dispatcher_->RemovePendingRequest(request_id_); |
137 | 131 |
138 if (request_.download_to_file) { | 132 if (request_.download_to_file) { |
139 dispatcher_->message_sender()->Send( | 133 dispatcher_->message_sender()->Send( |
140 new ResourceHostMsg_ReleaseDownloadedFile(request_id_)); | 134 new ResourceHostMsg_ReleaseDownloadedFile(request_id_)); |
141 } | 135 } |
142 } | 136 } |
143 } | 137 } |
144 | 138 |
145 void IPCResourceLoaderBridge::AppendDataToUpload(const char* data, | 139 void IPCResourceLoaderBridge::SetRequestBody( |
146 int data_len) { | 140 ResourceRequestBody* request_body) { |
147 DCHECK(request_id_ == -1) << "request already started"; | 141 DCHECK(request_id_ == -1) << "request already started"; |
148 | 142 request_.request_body = request_body; |
149 // don't bother appending empty data segments | |
150 if (data_len == 0) | |
151 return; | |
152 | |
153 if (!request_.upload_data) | |
154 request_.upload_data = new net::UploadData(); | |
155 request_.upload_data->AppendBytes(data, data_len); | |
156 } | |
157 | |
158 void IPCResourceLoaderBridge::AppendFileRangeToUpload( | |
159 const FilePath& path, uint64 offset, uint64 length, | |
160 const base::Time& expected_modification_time) { | |
161 DCHECK(request_id_ == -1) << "request already started"; | |
162 | |
163 if (!request_.upload_data) | |
164 request_.upload_data = new net::UploadData(); | |
165 request_.upload_data->AppendFileRange(path, offset, length, | |
166 expected_modification_time); | |
167 } | |
168 | |
169 void IPCResourceLoaderBridge::AppendBlobToUpload(const GURL& blob_url) { | |
170 DCHECK(request_id_ == -1) << "request already started"; | |
171 | |
172 if (!request_.upload_data) | |
173 request_.upload_data = new net::UploadData(); | |
174 request_.upload_data->AppendBlob(blob_url); | |
175 } | |
176 | |
177 void IPCResourceLoaderBridge::SetUploadIdentifier(int64 identifier) { | |
178 DCHECK(request_id_ == -1) << "request already started"; | |
179 | |
180 if (!request_.upload_data) | |
181 request_.upload_data = new net::UploadData(); | |
182 request_.upload_data->set_identifier(identifier); | |
183 } | 143 } |
184 | 144 |
185 // Writes a footer on the message and sends it | 145 // Writes a footer on the message and sends it |
186 bool IPCResourceLoaderBridge::Start(Peer* peer) { | 146 bool IPCResourceLoaderBridge::Start(Peer* peer) { |
187 if (request_id_ != -1) { | 147 if (request_id_ != -1) { |
188 NOTREACHED() << "Starting a request twice"; | 148 NOTREACHED() << "Starting a request twice"; |
189 return false; | 149 return false; |
190 } | 150 } |
191 | 151 |
192 peer_ = peer; | 152 peer_ = peer; |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 664 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
705 while (!queue->empty()) { | 665 while (!queue->empty()) { |
706 IPC::Message* message = queue->front(); | 666 IPC::Message* message = queue->front(); |
707 ReleaseResourcesInDataMessage(*message); | 667 ReleaseResourcesInDataMessage(*message); |
708 queue->pop_front(); | 668 queue->pop_front(); |
709 delete message; | 669 delete message; |
710 } | 670 } |
711 } | 671 } |
712 | 672 |
713 } // namespace content | 673 } // namespace content |
OLD | NEW |