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

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

Issue 2954343005: Merge ResourceRequestBodyImpl and ResourceRequestBody. (Closed)
Patch Set: Remove comment Created 3 years, 5 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "content/browser/fileapi/upload_file_system_file_element_reader.h" 18 #include "content/browser/fileapi/upload_file_system_file_element_reader.h"
19 #include "content/common/resource_request_body_impl.h" 19 #include "content/public/common/resource_request_body.h"
20 #include "net/base/elements_upload_data_stream.h" 20 #include "net/base/elements_upload_data_stream.h"
21 #include "net/base/upload_bytes_element_reader.h" 21 #include "net/base/upload_bytes_element_reader.h"
22 #include "net/base/upload_file_element_reader.h" 22 #include "net/base/upload_file_element_reader.h"
23 #include "storage/browser/blob/blob_data_handle.h" 23 #include "storage/browser/blob/blob_data_handle.h"
24 #include "storage/browser/blob/blob_reader.h" 24 #include "storage/browser/blob/blob_reader.h"
25 #include "storage/browser/blob/blob_storage_context.h" 25 #include "storage/browser/blob/blob_storage_context.h"
26 #include "storage/browser/blob/upload_blob_element_reader.h" 26 #include "storage/browser/blob/upload_blob_element_reader.h"
27 27
28 namespace base { 28 namespace base {
29 class TaskRunner; 29 class TaskRunner;
30 } 30 }
31 31
32 namespace disk_cache { 32 namespace disk_cache {
33 class Entry; 33 class Entry;
34 } 34 }
35 35
36 namespace content { 36 namespace content {
37 namespace { 37 namespace {
38 38
39 // A subclass of net::UploadBytesElementReader which owns 39 // A subclass of net::UploadBytesElementReader which owns
40 // ResourceRequestBodyImpl. 40 // ResourceRequestBody.
41 class BytesElementReader : public net::UploadBytesElementReader { 41 class BytesElementReader : public net::UploadBytesElementReader {
42 public: 42 public:
43 BytesElementReader(ResourceRequestBodyImpl* resource_request_body, 43 BytesElementReader(ResourceRequestBody* resource_request_body,
44 const ResourceRequestBodyImpl::Element& element) 44 const ResourceRequestBody::Element& element)
45 : net::UploadBytesElementReader(element.bytes(), element.length()), 45 : net::UploadBytesElementReader(element.bytes(), element.length()),
46 resource_request_body_(resource_request_body) { 46 resource_request_body_(resource_request_body) {
47 DCHECK_EQ(ResourceRequestBodyImpl::Element::TYPE_BYTES, element.type()); 47 DCHECK_EQ(ResourceRequestBody::Element::TYPE_BYTES, element.type());
48 } 48 }
49 49
50 ~BytesElementReader() override {} 50 ~BytesElementReader() override {}
51 51
52 private: 52 private:
53 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 53 scoped_refptr<ResourceRequestBody> resource_request_body_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(BytesElementReader); 55 DISALLOW_COPY_AND_ASSIGN(BytesElementReader);
56 }; 56 };
57 57
58 // A subclass of net::UploadFileElementReader which owns 58 // A subclass of net::UploadFileElementReader which owns
59 // ResourceRequestBodyImpl. 59 // ResourceRequestBody.
60 // This class is necessary to ensure the BlobData and any attached shareable 60 // This class is necessary to ensure the BlobData and any attached shareable
61 // files survive until upload completion. 61 // files survive until upload completion.
62 class FileElementReader : public net::UploadFileElementReader { 62 class FileElementReader : public net::UploadFileElementReader {
63 public: 63 public:
64 FileElementReader(ResourceRequestBodyImpl* resource_request_body, 64 FileElementReader(ResourceRequestBody* resource_request_body,
65 base::TaskRunner* task_runner, 65 base::TaskRunner* task_runner,
66 const ResourceRequestBodyImpl::Element& element) 66 const ResourceRequestBody::Element& element)
67 : net::UploadFileElementReader(task_runner, 67 : net::UploadFileElementReader(task_runner,
68 element.path(), 68 element.path(),
69 element.offset(), 69 element.offset(),
70 element.length(), 70 element.length(),
71 element.expected_modification_time()), 71 element.expected_modification_time()),
72 resource_request_body_(resource_request_body) { 72 resource_request_body_(resource_request_body) {
73 DCHECK_EQ(ResourceRequestBodyImpl::Element::TYPE_FILE, element.type()); 73 DCHECK_EQ(ResourceRequestBody::Element::TYPE_FILE, element.type());
74 } 74 }
75 75
76 ~FileElementReader() override {} 76 ~FileElementReader() override {}
77 77
78 private: 78 private:
79 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 79 scoped_refptr<ResourceRequestBody> resource_request_body_;
80 80
81 DISALLOW_COPY_AND_ASSIGN(FileElementReader); 81 DISALLOW_COPY_AND_ASSIGN(FileElementReader);
82 }; 82 };
83 83
84 } // namespace 84 } // namespace
85 85
86 std::unique_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( 86 std::unique_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build(
87 ResourceRequestBodyImpl* body, 87 ResourceRequestBody* body,
88 storage::BlobStorageContext* blob_context, 88 storage::BlobStorageContext* blob_context,
89 storage::FileSystemContext* file_system_context, 89 storage::FileSystemContext* file_system_context,
90 base::SingleThreadTaskRunner* file_task_runner) { 90 base::SingleThreadTaskRunner* file_task_runner) {
91 std::vector<std::unique_ptr<net::UploadElementReader>> element_readers; 91 std::vector<std::unique_ptr<net::UploadElementReader>> element_readers;
92 for (const auto& element : *body->elements()) { 92 for (const auto& element : *body->elements()) {
93 switch (element.type()) { 93 switch (element.type()) {
94 case ResourceRequestBodyImpl::Element::TYPE_BYTES: 94 case ResourceRequestBody::Element::TYPE_BYTES:
95 element_readers.push_back( 95 element_readers.push_back(
96 base::MakeUnique<BytesElementReader>(body, element)); 96 base::MakeUnique<BytesElementReader>(body, element));
97 break; 97 break;
98 case ResourceRequestBodyImpl::Element::TYPE_FILE: 98 case ResourceRequestBody::Element::TYPE_FILE:
99 element_readers.push_back(base::MakeUnique<FileElementReader>( 99 element_readers.push_back(base::MakeUnique<FileElementReader>(
100 body, file_task_runner, element)); 100 body, file_task_runner, element));
101 break; 101 break;
102 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM: 102 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM:
103 // If |body| contains any filesystem URLs, the caller should have 103 // If |body| contains any filesystem URLs, the caller should have
104 // supplied a FileSystemContext. 104 // supplied a FileSystemContext.
105 DCHECK(file_system_context); 105 DCHECK(file_system_context);
106 element_readers.push_back( 106 element_readers.push_back(
107 base::MakeUnique<content::UploadFileSystemFileElementReader>( 107 base::MakeUnique<content::UploadFileSystemFileElementReader>(
108 file_system_context, element.filesystem_url(), element.offset(), 108 file_system_context, element.filesystem_url(), element.offset(),
109 element.length(), element.expected_modification_time())); 109 element.length(), element.expected_modification_time()));
110 break; 110 break;
111 case ResourceRequestBodyImpl::Element::TYPE_BLOB: { 111 case ResourceRequestBody::Element::TYPE_BLOB: {
112 DCHECK_EQ(std::numeric_limits<uint64_t>::max(), element.length()); 112 DCHECK_EQ(std::numeric_limits<uint64_t>::max(), element.length());
113 DCHECK_EQ(0ul, element.offset()); 113 DCHECK_EQ(0ul, element.offset());
114 std::unique_ptr<storage::BlobDataHandle> handle = 114 std::unique_ptr<storage::BlobDataHandle> handle =
115 blob_context->GetBlobDataFromUUID(element.blob_uuid()); 115 blob_context->GetBlobDataFromUUID(element.blob_uuid());
116 element_readers.push_back( 116 element_readers.push_back(
117 base::MakeUnique<storage::UploadBlobElementReader>( 117 base::MakeUnique<storage::UploadBlobElementReader>(
118 std::move(handle), file_system_context, file_task_runner)); 118 std::move(handle), file_system_context, file_task_runner));
119 break; 119 break;
120 } 120 }
121 case ResourceRequestBodyImpl::Element::TYPE_DISK_CACHE_ENTRY: 121 case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY:
122 case ResourceRequestBodyImpl::Element::TYPE_BYTES_DESCRIPTION: 122 case ResourceRequestBody::Element::TYPE_BYTES_DESCRIPTION:
123 case ResourceRequestBodyImpl::Element::TYPE_UNKNOWN: 123 case ResourceRequestBody::Element::TYPE_UNKNOWN:
124 NOTREACHED(); 124 NOTREACHED();
125 break; 125 break;
126 } 126 }
127 } 127 }
128 128
129 return base::MakeUnique<net::ElementsUploadDataStream>( 129 return base::MakeUnique<net::ElementsUploadDataStream>(
130 std::move(element_readers), body->identifier()); 130 std::move(element_readers), body->identifier());
131 } 131 }
132 132
133 } // namespace content 133 } // 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