Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/loader/upload_data_stream_builder.h" | 5 #include "content/browser/loader/upload_data_stream_builder.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/fileapi/upload_file_system_file_element_reader.h" | 8 #include "content/browser/fileapi/upload_file_system_file_element_reader.h" |
| 9 #include "content/common/resource_request_body.h" | 9 #include "content/common/resource_request_body.h" |
| 10 #include "net/base/elements_upload_data_stream.h" | 10 #include "net/base/elements_upload_data_stream.h" |
| 11 #include "net/base/upload_bytes_element_reader.h" | 11 #include "net/base/upload_bytes_element_reader.h" |
| 12 #include "net/base/upload_file_element_reader.h" | 12 #include "net/base/upload_file_element_reader.h" |
| 13 #include "storage/browser/blob/blob_data_handle.h" | 13 #include "storage/browser/blob/blob_data_handle.h" |
| 14 #include "storage/browser/blob/blob_storage_context.h" | 14 #include "storage/browser/blob/blob_storage_context.h" |
| 15 #include "storage/common/blob/blob_data.h" | |
| 15 | 16 |
| 16 using storage::BlobData; | 17 using storage::BlobDataBuilder; |
|
michaeln
2015/01/16 00:09:09
i dont see where this is needed?
dmurph
2015/01/16 23:45:56
Done.
| |
| 17 using storage::BlobDataHandle; | 18 using storage::BlobDataSnapshotHandle; |
| 18 using storage::BlobStorageContext; | 19 using storage::BlobStorageContext; |
|
michaeln
2015/01/16 00:09:09
i think all usages (except one which is easily cha
dmurph
2015/01/16 23:45:56
Done.
| |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // A subclass of net::UploadBytesElementReader which owns ResourceRequestBody. | 24 // A subclass of net::UploadBytesElementReader which owns ResourceRequestBody. |
| 24 class BytesElementReader : public net::UploadBytesElementReader { | 25 class BytesElementReader : public net::UploadBytesElementReader { |
| 25 public: | 26 public: |
| 26 BytesElementReader(ResourceRequestBody* resource_request_body, | 27 BytesElementReader(ResourceRequestBody* resource_request_body, |
| 27 const ResourceRequestBody::Element& element) | 28 const ResourceRequestBody::Element& element) |
| 28 : net::UploadBytesElementReader(element.bytes(), element.length()), | 29 : net::UploadBytesElementReader(element.bytes(), element.length()), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 scoped_refptr<ResourceRequestBody> resource_request_body_; | 62 scoped_refptr<ResourceRequestBody> resource_request_body_; |
| 62 | 63 |
| 63 DISALLOW_COPY_AND_ASSIGN(FileElementReader); | 64 DISALLOW_COPY_AND_ASSIGN(FileElementReader); |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 void ResolveBlobReference( | 67 void ResolveBlobReference( |
| 67 storage::BlobStorageContext* blob_context, | 68 storage::BlobStorageContext* blob_context, |
| 68 const ResourceRequestBody::Element& element, | 69 const ResourceRequestBody::Element& element, |
| 69 std::vector<const ResourceRequestBody::Element*>* resolved_elements) { | 70 std::vector<const ResourceRequestBody::Element*>* resolved_elements) { |
| 70 DCHECK(blob_context); | 71 DCHECK(blob_context); |
| 71 scoped_ptr<storage::BlobDataHandle> handle = | 72 scoped_ptr<storage::BlobDataSnapshotHandle> handle = |
| 72 blob_context->GetBlobDataFromUUID(element.blob_uuid()); | 73 blob_context->GetBlobDataFromUUID(element.blob_uuid()); |
| 73 DCHECK(handle); | 74 DCHECK(handle); |
| 74 if (!handle) | 75 if (!handle) |
| 75 return; | 76 return; |
| 76 | 77 |
| 77 // If there is no element in the referred blob data, just return. | 78 // If there is no element in the referred blob data, just return. |
| 78 if (handle->data()->items().empty()) | 79 if (handle->data()->items().empty()) |
| 79 return; | 80 return; |
| 80 | 81 |
| 81 // Append the elements in the referenced blob data. | 82 // Append the elements in the referenced blob data. |
| 82 for (size_t i = 0; i < handle->data()->items().size(); ++i) { | 83 for (const auto& item : handle->data()->items()) { |
| 83 const BlobData::Item& item = handle->data()->items().at(i); | 84 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); |
| 84 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); | 85 resolved_elements->push_back(item->data_element_ptr()); |
| 85 resolved_elements->push_back(&item); | |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( | 91 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( |
| 92 ResourceRequestBody* body, | 92 ResourceRequestBody* body, |
| 93 BlobStorageContext* blob_context, | 93 BlobStorageContext* blob_context, |
|
michaeln
2015/01/16 00:09:09
storage::
dmurph
2015/01/16 23:45:56
Done.
| |
| 94 storage::FileSystemContext* file_system_context, | 94 storage::FileSystemContext* file_system_context, |
| 95 base::TaskRunner* file_task_runner) { | 95 base::TaskRunner* file_task_runner) { |
| 96 // Resolve all blob elements. | 96 // Resolve all blob elements. |
| 97 std::vector<const ResourceRequestBody::Element*> resolved_elements; | 97 std::vector<const ResourceRequestBody::Element*> resolved_elements; |
| 98 for (size_t i = 0; i < body->elements()->size(); ++i) { | 98 for (size_t i = 0; i < body->elements()->size(); ++i) { |
| 99 const ResourceRequestBody::Element& element = (*body->elements())[i]; | 99 const ResourceRequestBody::Element& element = (*body->elements())[i]; |
| 100 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) | 100 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) |
| 101 ResolveBlobReference(blob_context, element, &resolved_elements); | 101 ResolveBlobReference(blob_context, element, &resolved_elements); |
| 102 else | 102 else |
| 103 resolved_elements.push_back(&element); | 103 resolved_elements.push_back(&element); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 return make_scoped_ptr( | 139 return make_scoped_ptr( |
| 140 new net::ElementsUploadDataStream(element_readers.Pass(), | 140 new net::ElementsUploadDataStream(element_readers.Pass(), |
| 141 body->identifier())); | 141 body->identifier())); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace content | 144 } // namespace content |
| OLD | NEW |