| 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/glue/resource_request_body.h" | 5 #include "webkit/glue/resource_request_body.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/base/upload_data.h" | 8 #include "net/base/upload_data.h" |
| 9 #include "webkit/blob/blob_storage_controller.h" | 9 #include "webkit/blob/blob_storage_context.h" |
| 10 | 10 |
| 11 using webkit_blob::BlobData; | 11 using webkit_blob::BlobData; |
| 12 using webkit_blob::BlobStorageController; | 12 using webkit_blob::BlobStorageContext; |
| 13 | 13 |
| 14 namespace webkit_glue { | 14 namespace webkit_glue { |
| 15 | 15 |
| 16 ResourceRequestBody::ResourceRequestBody() : identifier_(0) {} | 16 ResourceRequestBody::ResourceRequestBody() : identifier_(0) {} |
| 17 | 17 |
| 18 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { | 18 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
| 19 if (bytes_len > 0) { | 19 if (bytes_len > 0) { |
| 20 elements_.push_back(Element()); | 20 elements_.push_back(Element()); |
| 21 elements_.back().SetToBytes(bytes, bytes_len); | 21 elements_.back().SetToBytes(bytes, bytes_len); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 void ResourceRequestBody::AppendFileRange( | 25 void ResourceRequestBody::AppendFileRange( |
| 26 const FilePath& file_path, | 26 const FilePath& file_path, |
| 27 uint64 offset, uint64 length, | 27 uint64 offset, uint64 length, |
| 28 const base::Time& expected_modification_time) { | 28 const base::Time& expected_modification_time) { |
| 29 elements_.push_back(Element()); | 29 elements_.push_back(Element()); |
| 30 elements_.back().SetToFilePathRange(file_path, offset, length, | 30 elements_.back().SetToFilePathRange(file_path, offset, length, |
| 31 expected_modification_time); | 31 expected_modification_time); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ResourceRequestBody::AppendBlob(const GURL& blob_url) { | 34 void ResourceRequestBody::AppendBlob(const std::string& uuid) { |
| 35 elements_.push_back(Element()); | 35 elements_.push_back(Element()); |
| 36 elements_.back().SetToBlobUrl(blob_url); | 36 elements_.back().SetToBlob(uuid); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void ResourceRequestBody::AppendFileSystemFileRange( | 39 void ResourceRequestBody::AppendFileSystemFileRange( |
| 40 const GURL& url, uint64 offset, uint64 length, | 40 const GURL& url, uint64 offset, uint64 length, |
| 41 const base::Time& expected_modification_time) { | 41 const base::Time& expected_modification_time) { |
| 42 elements_.push_back(Element()); | 42 elements_.push_back(Element()); |
| 43 elements_.back().SetToFileSystemUrlRange(url, offset, length, | 43 elements_.back().SetToFileSystemUrlRange(url, offset, length, |
| 44 expected_modification_time); | 44 expected_modification_time); |
| 45 } | 45 } |
| 46 | 46 |
| 47 net::UploadData* ResourceRequestBody::ResolveElementsAndCreateUploadData( | 47 net::UploadData* ResourceRequestBody::ResolveElementsAndCreateUploadData( |
| 48 BlobStorageController* blob_controller) { | 48 BlobStorageContext* blob_context) { |
| 49 // Resolve all blob elements. | 49 // Resolve all blob elements. |
| 50 std::vector<const Element*> resolved_elements; | 50 std::vector<const Element*> resolved_elements; |
| 51 for (size_t i = 0; i < elements_.size(); ++i) { | 51 for (size_t i = 0; i < elements_.size(); ++i) { |
| 52 const Element& element = elements_[i]; | 52 const Element& element = elements_[i]; |
| 53 if (element.type() == Element::TYPE_BLOB) { | 53 if (element.type() == Element::TYPE_BLOB) { |
| 54 ResolveBlobReference(blob_controller, element.url(), &resolved_elements); | 54 ResolveBlobReference(blob_context, element.blob_uuid(), |
| 55 &resolved_elements); |
| 55 } else { | 56 } else { |
| 56 // No need to resolve, just append the element. | 57 // No need to resolve, just append the element. |
| 57 resolved_elements.push_back(&element); | 58 resolved_elements.push_back(&element); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 net::UploadData* upload_data = new net::UploadData; | 62 net::UploadData* upload_data = new net::UploadData; |
| 62 // We attach 'this' to UploadData so that we do not need to copy | 63 // We attach 'this' to UploadData so that we do not need to copy |
| 63 // bytes for TYPE_BYTES. | 64 // bytes for TYPE_BYTES. |
| 64 upload_data->SetUserData( | 65 upload_data->SetUserData( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 break; | 94 break; |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 upload_data->set_identifier(identifier_); | 97 upload_data->set_identifier(identifier_); |
| 97 return upload_data; | 98 return upload_data; |
| 98 } | 99 } |
| 99 | 100 |
| 100 ResourceRequestBody::~ResourceRequestBody() {} | 101 ResourceRequestBody::~ResourceRequestBody() {} |
| 101 | 102 |
| 102 void ResourceRequestBody::ResolveBlobReference( | 103 void ResourceRequestBody::ResolveBlobReference( |
| 103 webkit_blob::BlobStorageController* blob_controller, | 104 webkit_blob::BlobStorageContext* blob_context, |
| 104 const GURL& blob_url, | 105 const std::string& uuid, |
| 105 std::vector<const Element*>* resolved_elements) { | 106 std::vector<const Element*>* resolved_elements) { |
| 106 DCHECK(blob_controller); | 107 DCHECK(blob_context); |
| 107 BlobData* blob_data = blob_controller->GetBlobDataFromUrl(blob_url); | 108 scoped_ptr<webkit_blob::BlobDataHandle> handle = |
| 108 DCHECK(blob_data); | 109 blob_context->GetBlobDataFromUUID(uuid); |
| 109 if (!blob_data) | 110 DCHECK(handle); |
| 111 if (!handle) |
| 110 return; | 112 return; |
| 111 | 113 |
| 112 // If there is no element in the referred blob data, just return. | 114 // If there is no element in the referred blob data, just return. |
| 113 if (blob_data->items().empty()) | 115 if (handle->data()->items().empty()) |
| 114 return; | 116 return; |
| 115 | 117 |
| 118 // Append the elements in the referred blob data. |
| 119 for (size_t i = 0; i < handle->data()->items().size(); ++i) { |
| 120 const BlobData::Item& item = handle->data()->items().at(i); |
| 121 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); |
| 122 resolved_elements->push_back(&item); |
| 123 } |
| 124 |
| 116 // Ensure the blob and any attached shareable files survive until | 125 // Ensure the blob and any attached shareable files survive until |
| 117 // upload completion. | 126 // upload completion. |
| 118 SetUserData(blob_data, new base::UserDataAdapter<BlobData>(blob_data)); | 127 SetUserData(handle.get(), handle.release()); |
| 119 | |
| 120 // Append the elements in the referred blob data. | |
| 121 for (size_t i = 0; i < blob_data->items().size(); ++i) { | |
| 122 const BlobData::Item& item = blob_data->items().at(i); | |
| 123 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); | |
| 124 resolved_elements->push_back(&item); | |
| 125 } | |
| 126 } | 128 } |
| 127 | 129 |
| 128 } // namespace webkit_glue | 130 } // namespace webkit_glue |
| OLD | NEW |