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 #include "webkit/blob/blob_storage_controller.h" | 5 #include "webkit/blob/blob_storage_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "net/base/upload_data.h" | |
10 #include "webkit/blob/blob_data.h" | 9 #include "webkit/blob/blob_data.h" |
10 #include "webkit/glue/resource_request_body.h" | |
11 | |
12 using webkit_glue::ResourceRequestBody; | |
11 | 13 |
12 namespace webkit_blob { | 14 namespace webkit_blob { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // We can't use GURL directly for these hash fragment manipulations | 18 // We can't use GURL directly for these hash fragment manipulations |
17 // since it doesn't have specific knowlege of the BlobURL format. GURL | 19 // since it doesn't have specific knowlege of the BlobURL format. GURL |
18 // treats BlobURLs as if they were PathURLs which don't support hash | 20 // treats BlobURLs as if they were PathURLs which don't support hash |
19 // fragments. | 21 // fragments. |
20 | 22 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 return true; | 164 return true; |
163 } | 165 } |
164 | 166 |
165 | 167 |
166 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { | 168 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { |
167 BlobMap::iterator found = blob_map_.find( | 169 BlobMap::iterator found = blob_map_.find( |
168 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); | 170 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); |
169 return (found != blob_map_.end()) ? found->second : NULL; | 171 return (found != blob_map_.end()) ? found->second : NULL; |
170 } | 172 } |
171 | 173 |
172 void BlobStorageController::ResolveBlobReferencesInUploadData( | 174 void BlobStorageController::ResolveBlobReferencesInResourceRequestBody( |
darin (slow to review)
2012/08/15 17:49:55
nit: I'd be OK dropping the "Resource" in this fun
kinuko
2012/08/16 08:14:59
Done.
| |
173 net::UploadData* upload_data) { | 175 ResourceRequestBody* resource_request_body) { |
174 DCHECK(upload_data); | 176 DCHECK(resource_request_body); |
175 | 177 |
176 std::vector<net::UploadData::Element>* uploads = | 178 std::vector<ResourceRequestBody::Element>* uploads = |
177 upload_data->elements_mutable(); | 179 resource_request_body->elements_mutable(); |
178 std::vector<net::UploadData::Element>::iterator iter; | 180 std::vector<ResourceRequestBody::Element>::iterator iter; |
179 for (iter = uploads->begin(); iter != uploads->end();) { | 181 for (iter = uploads->begin(); iter != uploads->end();) { |
180 if (iter->type() != net::UploadData::TYPE_BLOB) { | 182 if (iter->type() != ResourceRequestBody::TYPE_BLOB) { |
181 iter++; | 183 iter++; |
182 continue; | 184 continue; |
183 } | 185 } |
184 | 186 |
185 // Find the referred blob data. | 187 // Find the referred blob data. |
186 BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url()); | 188 BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url()); |
187 DCHECK(blob_data); | 189 DCHECK(blob_data); |
188 if (!blob_data) { | 190 if (!blob_data) { |
189 // TODO(jianli): We should probably fail uploading the data | 191 // TODO(jianli): We should probably fail uploading the data |
190 iter++; | 192 iter++; |
191 continue; | 193 continue; |
192 } | 194 } |
193 | 195 |
194 // Remove this element. | 196 // Remove this element. |
195 iter = uploads->erase(iter); | 197 iter = uploads->erase(iter); |
196 | 198 |
197 // If there is no element in the referred blob data, continue the loop. | 199 // If there is no element in the referred blob data, continue the loop. |
198 // Note that we should not increase iter since it already points to the one | 200 // Note that we should not increase iter since it already points to the one |
199 // after the removed element. | 201 // after the removed element. |
200 if (blob_data->items().empty()) | 202 if (blob_data->items().empty()) |
201 continue; | 203 continue; |
202 | 204 |
203 // Ensure the blob and any attached shareable files survive until | 205 // Ensure the blob and any attached shareable files survive until |
204 // upload completion. | 206 // upload completion. |
205 upload_data->SetUserData(blob_data, | 207 resource_request_body->SetUserData( |
206 new base::UserDataAdapter<BlobData>(blob_data)); | 208 blob_data, new base::UserDataAdapter<BlobData>(blob_data)); |
207 | 209 |
208 // Insert the elements in the referred blob data. | 210 // Insert the elements in the referred blob data. |
209 // Note that we traverse from the bottom so that the elements can be | 211 // Note that we traverse from the bottom so that the elements can be |
210 // inserted in the original order. | 212 // inserted in the original order. |
211 for (size_t i = blob_data->items().size(); i > 0; --i) { | 213 for (size_t i = blob_data->items().size(); i > 0; --i) { |
212 iter = uploads->insert(iter, net::UploadData::Element()); | 214 iter = uploads->insert(iter, ResourceRequestBody::Element()); |
213 | 215 |
214 const BlobData::Item& item = blob_data->items().at(i - 1); | 216 const BlobData::Item& item = blob_data->items().at(i - 1); |
215 switch (item.type) { | 217 switch (item.type) { |
216 case BlobData::TYPE_DATA: | 218 case BlobData::TYPE_DATA: |
217 // TODO(jianli): Figure out how to avoid copying the data. | 219 iter->SetToSharedBytes( |
218 // TODO(michaeln): Now that blob_data surives for the duration, | |
219 // maybe UploadData could take a raw ptr without having to copy. | |
220 iter->SetToBytes( | |
221 &item.data.at(0) + static_cast<int>(item.offset), | 220 &item.data.at(0) + static_cast<int>(item.offset), |
222 static_cast<int>(item.length)); | 221 static_cast<int>(item.length)); |
223 break; | 222 break; |
224 case BlobData::TYPE_FILE: | 223 case BlobData::TYPE_FILE: |
225 iter->SetToFilePathRange( | 224 iter->SetToFilePathRange( |
226 item.file_path, | 225 item.file_path, |
227 item.offset, | 226 item.offset, |
228 item.length, | 227 item.length, |
229 item.expected_modification_time); | 228 item.expected_modification_time); |
230 break; | 229 break; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { | 293 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { |
295 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); | 294 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); |
296 DCHECK(found != blob_data_usage_count_.end()); | 295 DCHECK(found != blob_data_usage_count_.end()); |
297 if (--(found->second)) | 296 if (--(found->second)) |
298 return false; // Still in use | 297 return false; // Still in use |
299 blob_data_usage_count_.erase(found); | 298 blob_data_usage_count_.erase(found); |
300 return true; | 299 return true; |
301 } | 300 } |
302 | 301 |
303 } // namespace webkit_blob | 302 } // namespace webkit_blob |
OLD | NEW |