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_bytes_element_reader.h" | 8 #include "net/base/upload_bytes_element_reader.h" |
9 #include "net/base/upload_data_stream.h" | 9 #include "net/base/upload_data_stream.h" |
10 #include "net/base/upload_file_element_reader.h" | 10 #include "net/base/upload_file_element_reader.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 DISALLOW_COPY_AND_ASSIGN(BytesElementReader); | 35 DISALLOW_COPY_AND_ASSIGN(BytesElementReader); |
36 }; | 36 }; |
37 | 37 |
38 // A subclass of net::UploadFileElementReader which owns ResourceRequestBody. | 38 // A subclass of net::UploadFileElementReader which owns ResourceRequestBody. |
39 // This class is necessary to ensure the BlobData and any attached shareable | 39 // This class is necessary to ensure the BlobData and any attached shareable |
40 // files survive until upload completion. | 40 // files survive until upload completion. |
41 class FileElementReader : public net::UploadFileElementReader { | 41 class FileElementReader : public net::UploadFileElementReader { |
42 public: | 42 public: |
43 FileElementReader(ResourceRequestBody* resource_request_body, | 43 FileElementReader(ResourceRequestBody* resource_request_body, |
| 44 base::TaskRunner* task_runner, |
44 const ResourceRequestBody::Element& element) | 45 const ResourceRequestBody::Element& element) |
45 : net::UploadFileElementReader(element.path(), | 46 : net::UploadFileElementReader(task_runner, |
| 47 element.path(), |
46 element.offset(), | 48 element.offset(), |
47 element.length(), | 49 element.length(), |
48 element.expected_modification_time()), | 50 element.expected_modification_time()), |
49 resource_request_body_(resource_request_body) { | 51 resource_request_body_(resource_request_body) { |
50 DCHECK_EQ(ResourceRequestBody::Element::TYPE_FILE, element.type()); | 52 DCHECK_EQ(ResourceRequestBody::Element::TYPE_FILE, element.type()); |
51 } | 53 } |
52 | 54 |
53 virtual ~FileElementReader() {} | 55 virtual ~FileElementReader() {} |
54 | 56 |
55 private: | 57 private: |
(...skipping 30 matching lines...) Expand all Loading... |
86 void ResourceRequestBody::AppendFileSystemFileRange( | 88 void ResourceRequestBody::AppendFileSystemFileRange( |
87 const GURL& url, uint64 offset, uint64 length, | 89 const GURL& url, uint64 offset, uint64 length, |
88 const base::Time& expected_modification_time) { | 90 const base::Time& expected_modification_time) { |
89 elements_.push_back(Element()); | 91 elements_.push_back(Element()); |
90 elements_.back().SetToFileSystemUrlRange(url, offset, length, | 92 elements_.back().SetToFileSystemUrlRange(url, offset, length, |
91 expected_modification_time); | 93 expected_modification_time); |
92 } | 94 } |
93 | 95 |
94 net::UploadDataStream* | 96 net::UploadDataStream* |
95 ResourceRequestBody::ResolveElementsAndCreateUploadDataStream( | 97 ResourceRequestBody::ResolveElementsAndCreateUploadDataStream( |
96 BlobStorageController* blob_controller) { | 98 BlobStorageController* blob_controller, |
| 99 base::TaskRunner* task_runner) { |
97 // Resolve all blob elements. | 100 // Resolve all blob elements. |
98 std::vector<const Element*> resolved_elements; | 101 std::vector<const Element*> resolved_elements; |
99 for (size_t i = 0; i < elements_.size(); ++i) { | 102 for (size_t i = 0; i < elements_.size(); ++i) { |
100 const Element& element = elements_[i]; | 103 const Element& element = elements_[i]; |
101 if (element.type() == Element::TYPE_BLOB) { | 104 if (element.type() == Element::TYPE_BLOB) { |
102 ResolveBlobReference(blob_controller, element.url(), &resolved_elements); | 105 ResolveBlobReference(blob_controller, element.url(), &resolved_elements); |
103 } else { | 106 } else { |
104 // No need to resolve, just append the element. | 107 // No need to resolve, just append the element. |
105 resolved_elements.push_back(&element); | 108 resolved_elements.push_back(&element); |
106 } | 109 } |
107 } | 110 } |
108 | 111 |
109 ScopedVector<net::UploadElementReader> element_readers; | 112 ScopedVector<net::UploadElementReader> element_readers; |
110 for (size_t i = 0; i < resolved_elements.size(); ++i) { | 113 for (size_t i = 0; i < resolved_elements.size(); ++i) { |
111 const Element& element = *resolved_elements[i]; | 114 const Element& element = *resolved_elements[i]; |
112 switch (element.type()) { | 115 switch (element.type()) { |
113 case Element::TYPE_BYTES: | 116 case Element::TYPE_BYTES: |
114 element_readers.push_back(new BytesElementReader(this, element)); | 117 element_readers.push_back(new BytesElementReader(this, element)); |
115 break; | 118 break; |
116 case Element::TYPE_FILE: | 119 case Element::TYPE_FILE: |
117 element_readers.push_back(new FileElementReader(this, element)); | 120 element_readers.push_back( |
| 121 new FileElementReader(this, task_runner, element)); |
118 break; | 122 break; |
119 case Element::TYPE_FILE_FILESYSTEM: | 123 case Element::TYPE_FILE_FILESYSTEM: |
120 // TODO(kinuko): Resolve FileSystemURL before creating UploadData. | 124 // TODO(kinuko): Resolve FileSystemURL before creating UploadData. |
121 NOTREACHED(); | 125 NOTREACHED(); |
122 break; | 126 break; |
123 case Element::TYPE_BLOB: | 127 case Element::TYPE_BLOB: |
124 // Blob elements should be resolved beforehand. | 128 // Blob elements should be resolved beforehand. |
125 NOTREACHED(); | 129 NOTREACHED(); |
126 break; | 130 break; |
127 case Element::TYPE_UNKNOWN: | 131 case Element::TYPE_UNKNOWN: |
(...skipping 26 matching lines...) Expand all Loading... |
154 | 158 |
155 // Append the elements in the referred blob data. | 159 // Append the elements in the referred blob data. |
156 for (size_t i = 0; i < blob_data->items().size(); ++i) { | 160 for (size_t i = 0; i < blob_data->items().size(); ++i) { |
157 const BlobData::Item& item = blob_data->items().at(i); | 161 const BlobData::Item& item = blob_data->items().at(i); |
158 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); | 162 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); |
159 resolved_elements->push_back(&item); | 163 resolved_elements->push_back(&item); |
160 } | 164 } |
161 } | 165 } |
162 | 166 |
163 } // namespace webkit_glue | 167 } // namespace webkit_glue |
OLD | NEW |