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/upload_bytes_element_reader.h" | 10 #include "net/base/upload_bytes_element_reader.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 virtual ~FileElementReader() {} | 58 virtual ~FileElementReader() {} |
59 | 59 |
60 private: | 60 private: |
61 scoped_refptr<ResourceRequestBody> resource_request_body_; | 61 scoped_refptr<ResourceRequestBody> resource_request_body_; |
62 | 62 |
63 DISALLOW_COPY_AND_ASSIGN(FileElementReader); | 63 DISALLOW_COPY_AND_ASSIGN(FileElementReader); |
64 }; | 64 }; |
65 | 65 |
66 void ResolveBlobReference( | 66 void ResolveBlobReference( |
67 ResourceRequestBody* body, | |
68 webkit_blob::BlobStorageContext* blob_context, | 67 webkit_blob::BlobStorageContext* blob_context, |
69 const ResourceRequestBody::Element& element, | 68 const ResourceRequestBody::Element& element, |
70 std::vector<const ResourceRequestBody::Element*>* resolved_elements) { | 69 std::vector<const ResourceRequestBody::Element*>* resolved_elements) { |
71 DCHECK(blob_context); | 70 DCHECK(blob_context); |
72 scoped_ptr<webkit_blob::BlobDataHandle> handle = | 71 scoped_ptr<webkit_blob::BlobDataHandle> handle = |
73 blob_context->GetBlobDataFromUUID(element.blob_uuid()); | 72 blob_context->GetBlobDataFromUUID(element.blob_uuid()); |
mmenke
2014/08/25 18:49:02
I know this works, due to refcounting, but but sho
horo
2014/08/26 00:31:53
If my understanding is correct, we resolve the blo
mmenke
2014/08/26 18:09:14
Think it's at least worth a comment the caller is
michaeln
2014/08/26 20:34:08
Thats a good point.
I asked horo to hoist the Set
horo
2014/08/27 01:38:15
Added comments in upload_data_stream_builder.h.
| |
74 DCHECK(handle); | 73 DCHECK(handle); |
75 if (!handle) | 74 if (!handle) |
76 return; | 75 return; |
77 | 76 |
78 // If there is no element in the referred blob data, just return. | 77 // If there is no element in the referred blob data, just return. |
79 if (handle->data()->items().empty()) | 78 if (handle->data()->items().empty()) |
80 return; | 79 return; |
81 | 80 |
82 // Append the elements in the referenced blob data. | 81 // Append the elements in the referenced blob data. |
83 for (size_t i = 0; i < handle->data()->items().size(); ++i) { | 82 for (size_t i = 0; i < handle->data()->items().size(); ++i) { |
84 const BlobData::Item& item = handle->data()->items().at(i); | 83 const BlobData::Item& item = handle->data()->items().at(i); |
85 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); | 84 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); |
86 resolved_elements->push_back(&item); | 85 resolved_elements->push_back(&item); |
87 } | 86 } |
88 | |
89 // Ensure the blob and any attached shareable files survive until | |
90 // upload completion. The |body| takes ownership of |handle|. | |
91 const void* key = handle.get(); | |
92 body->SetUserData(key, handle.release()); | |
93 } | 87 } |
94 | 88 |
95 } // namespace | 89 } // namespace |
96 | 90 |
97 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( | 91 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( |
98 ResourceRequestBody* body, | 92 ResourceRequestBody* body, |
99 BlobStorageContext* blob_context, | 93 BlobStorageContext* blob_context, |
100 fileapi::FileSystemContext* file_system_context, | 94 fileapi::FileSystemContext* file_system_context, |
101 base::TaskRunner* file_task_runner) { | 95 base::TaskRunner* file_task_runner) { |
102 // Resolve all blob elements. | 96 // Resolve all blob elements. |
103 std::vector<const ResourceRequestBody::Element*> resolved_elements; | 97 std::vector<const ResourceRequestBody::Element*> resolved_elements; |
104 for (size_t i = 0; i < body->elements()->size(); ++i) { | 98 for (size_t i = 0; i < body->elements()->size(); ++i) { |
105 const ResourceRequestBody::Element& element = (*body->elements())[i]; | 99 const ResourceRequestBody::Element& element = (*body->elements())[i]; |
106 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) | 100 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) |
107 ResolveBlobReference(body, blob_context, element, &resolved_elements); | 101 ResolveBlobReference(blob_context, element, &resolved_elements); |
108 else | 102 else |
109 resolved_elements.push_back(&element); | 103 resolved_elements.push_back(&element); |
110 } | 104 } |
111 | 105 |
112 ScopedVector<net::UploadElementReader> element_readers; | 106 ScopedVector<net::UploadElementReader> element_readers; |
113 for (size_t i = 0; i < resolved_elements.size(); ++i) { | 107 for (size_t i = 0; i < resolved_elements.size(); ++i) { |
114 const ResourceRequestBody::Element& element = *resolved_elements[i]; | 108 const ResourceRequestBody::Element& element = *resolved_elements[i]; |
115 switch (element.type()) { | 109 switch (element.type()) { |
116 case ResourceRequestBody::Element::TYPE_BYTES: | 110 case ResourceRequestBody::Element::TYPE_BYTES: |
117 element_readers.push_back(new BytesElementReader(body, element)); | 111 element_readers.push_back(new BytesElementReader(body, element)); |
(...skipping 19 matching lines...) Expand all Loading... | |
137 NOTREACHED(); | 131 NOTREACHED(); |
138 break; | 132 break; |
139 } | 133 } |
140 } | 134 } |
141 | 135 |
142 return make_scoped_ptr( | 136 return make_scoped_ptr( |
143 new net::UploadDataStream(element_readers.Pass(), body->identifier())); | 137 new net::UploadDataStream(element_readers.Pass(), body->identifier())); |
144 } | 138 } |
145 | 139 |
146 } // namespace content | 140 } // namespace content |
OLD | NEW |