Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: content/browser/loader/upload_data_stream_builder.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "net/base/upload_data_stream.h" 11 #include "net/base/upload_data_stream.h"
12 #include "net/base/upload_file_element_reader.h" 12 #include "net/base/upload_file_element_reader.h"
13 #include "webkit/browser/blob/blob_data_handle.h" 13 #include "storage/browser/blob/blob_data_handle.h"
14 #include "webkit/browser/blob/blob_storage_context.h" 14 #include "storage/browser/blob/blob_storage_context.h"
15 15
16 using webkit_blob::BlobData; 16 using storage::BlobData;
17 using webkit_blob::BlobDataHandle; 17 using storage::BlobDataHandle;
18 using webkit_blob::BlobStorageContext; 18 using storage::BlobStorageContext;
19 19
20 namespace content { 20 namespace content {
21 namespace { 21 namespace {
22 22
23 // A subclass of net::UploadBytesElementReader which owns ResourceRequestBody. 23 // A subclass of net::UploadBytesElementReader which owns ResourceRequestBody.
24 class BytesElementReader : public net::UploadBytesElementReader { 24 class BytesElementReader : public net::UploadBytesElementReader {
25 public: 25 public:
26 BytesElementReader(ResourceRequestBody* resource_request_body, 26 BytesElementReader(ResourceRequestBody* resource_request_body,
27 const ResourceRequestBody::Element& element) 27 const ResourceRequestBody::Element& element)
28 : net::UploadBytesElementReader(element.bytes(), element.length()), 28 : net::UploadBytesElementReader(element.bytes(), element.length()),
(...skipping 29 matching lines...) Expand all
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, 67 ResourceRequestBody* body,
68 webkit_blob::BlobStorageContext* blob_context, 68 storage::BlobStorageContext* blob_context,
69 const ResourceRequestBody::Element& element, 69 const ResourceRequestBody::Element& element,
70 std::vector<const ResourceRequestBody::Element*>* resolved_elements) { 70 std::vector<const ResourceRequestBody::Element*>* resolved_elements) {
71 DCHECK(blob_context); 71 DCHECK(blob_context);
72 scoped_ptr<webkit_blob::BlobDataHandle> handle = 72 scoped_ptr<storage::BlobDataHandle> handle =
73 blob_context->GetBlobDataFromUUID(element.blob_uuid()); 73 blob_context->GetBlobDataFromUUID(element.blob_uuid());
74 DCHECK(handle); 74 DCHECK(handle);
75 if (!handle) 75 if (!handle)
76 return; 76 return;
77 77
78 // 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.
79 if (handle->data()->items().empty()) 79 if (handle->data()->items().empty())
80 return; 80 return;
81 81
82 // Append the elements in the referenced blob data. 82 // Append the elements in the referenced blob data.
83 for (size_t i = 0; i < handle->data()->items().size(); ++i) { 83 for (size_t i = 0; i < handle->data()->items().size(); ++i) {
84 const BlobData::Item& item = handle->data()->items().at(i); 84 const BlobData::Item& item = handle->data()->items().at(i);
85 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); 85 DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type());
86 resolved_elements->push_back(&item); 86 resolved_elements->push_back(&item);
87 } 87 }
88 88
89 // Ensure the blob and any attached shareable files survive until 89 // Ensure the blob and any attached shareable files survive until
90 // upload completion. The |body| takes ownership of |handle|. 90 // upload completion. The |body| takes ownership of |handle|.
91 const void* key = handle.get(); 91 const void* key = handle.get();
92 body->SetUserData(key, handle.release()); 92 body->SetUserData(key, handle.release());
93 } 93 }
94 94
95 } // namespace 95 } // namespace
96 96
97 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( 97 scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build(
98 ResourceRequestBody* body, 98 ResourceRequestBody* body,
99 BlobStorageContext* blob_context, 99 BlobStorageContext* blob_context,
100 fileapi::FileSystemContext* file_system_context, 100 storage::FileSystemContext* file_system_context,
101 base::TaskRunner* file_task_runner) { 101 base::TaskRunner* file_task_runner) {
102 // Resolve all blob elements. 102 // Resolve all blob elements.
103 std::vector<const ResourceRequestBody::Element*> resolved_elements; 103 std::vector<const ResourceRequestBody::Element*> resolved_elements;
104 for (size_t i = 0; i < body->elements()->size(); ++i) { 104 for (size_t i = 0; i < body->elements()->size(); ++i) {
105 const ResourceRequestBody::Element& element = (*body->elements())[i]; 105 const ResourceRequestBody::Element& element = (*body->elements())[i];
106 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) 106 if (element.type() == ResourceRequestBody::Element::TYPE_BLOB)
107 ResolveBlobReference(body, blob_context, element, &resolved_elements); 107 ResolveBlobReference(body, blob_context, element, &resolved_elements);
108 else 108 else
109 resolved_elements.push_back(&element); 109 resolved_elements.push_back(&element);
110 } 110 }
(...skipping 26 matching lines...) Expand all
137 NOTREACHED(); 137 NOTREACHED();
138 break; 138 break;
139 } 139 }
140 } 140 }
141 141
142 return make_scoped_ptr( 142 return make_scoped_ptr(
143 new net::UploadDataStream(element_readers.Pass(), body->identifier())); 143 new net::UploadDataStream(element_readers.Pass(), body->identifier()));
144 } 144 }
145 145
146 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/upload_data_stream_builder.h ('k') | content/browser/loader/upload_data_stream_builder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698