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

Side by Side Diff: content/child/webblobregistry_impl.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BUILD.gn file changes Created 5 years, 11 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/child/webblobregistry_impl.h" 5 #include "content/child/webblobregistry_impl.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "content/child/child_thread.h" 12 #include "content/child/child_thread.h"
13 #include "content/child/thread_safe_sender.h" 13 #include "content/child/thread_safe_sender.h"
14 #include "content/common/fileapi/webblob_messages.h" 14 #include "content/common/fileapi/webblob_messages.h"
15 #include "storage/common/blob/blob_data.h"
16 #include "third_party/WebKit/public/platform/WebBlobData.h" 15 #include "third_party/WebKit/public/platform/WebBlobData.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" 17 #include "third_party/WebKit/public/platform/WebThreadSafeData.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 18 #include "third_party/WebKit/public/platform/WebURL.h"
20 19
21 using blink::WebBlobData; 20 using blink::WebBlobData;
22 using blink::WebString; 21 using blink::WebString;
23 using blink::WebThreadSafeData; 22 using blink::WebThreadSafeData;
24 using blink::WebURL; 23 using blink::WebURL;
25 24
(...skipping 23 matching lines...) Expand all
49 while (data.itemAt(i++, data_item)) { 48 while (data.itemAt(i++, data_item)) {
50 switch (data_item.type) { 49 switch (data_item.type) {
51 case WebBlobData::Item::TypeData: { 50 case WebBlobData::Item::TypeData: {
52 // WebBlobData does not allow partial data items. 51 // WebBlobData does not allow partial data items.
53 DCHECK(!data_item.offset && data_item.length == -1); 52 DCHECK(!data_item.offset && data_item.length == -1);
54 SendDataForBlob(uuid_str, data_item.data); 53 SendDataForBlob(uuid_str, data_item.data);
55 break; 54 break;
56 } 55 }
57 case WebBlobData::Item::TypeFile: 56 case WebBlobData::Item::TypeFile:
58 if (data_item.length) { 57 if (data_item.length) {
59 storage::BlobData::Item item; 58 storage::DataElement item;
60 item.SetToFilePathRange( 59 item.SetToFilePathRange(
61 base::FilePath::FromUTF16Unsafe(data_item.filePath), 60 base::FilePath::FromUTF16Unsafe(data_item.filePath),
62 static_cast<uint64>(data_item.offset), 61 static_cast<uint64>(data_item.offset),
63 static_cast<uint64>(data_item.length), 62 static_cast<uint64>(data_item.length),
64 base::Time::FromDoubleT(data_item.expectedModificationTime)); 63 base::Time::FromDoubleT(data_item.expectedModificationTime));
65 sender_->Send( 64 sender_->Send(
66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 65 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
67 } 66 }
68 break; 67 break;
69 case WebBlobData::Item::TypeBlob: 68 case WebBlobData::Item::TypeBlob:
70 if (data_item.length) { 69 if (data_item.length) {
71 storage::BlobData::Item item; 70 storage::DataElement item;
72 item.SetToBlobRange( 71 item.SetToBlobRange(
73 data_item.blobUUID.utf8(), 72 data_item.blobUUID.utf8(),
74 static_cast<uint64>(data_item.offset), 73 static_cast<uint64>(data_item.offset),
75 static_cast<uint64>(data_item.length)); 74 static_cast<uint64>(data_item.length));
76 sender_->Send( 75 sender_->Send(
77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 76 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
78 } 77 }
79 break; 78 break;
80 case WebBlobData::Item::TypeFileSystemURL: 79 case WebBlobData::Item::TypeFileSystemURL:
81 if (data_item.length) { 80 if (data_item.length) {
82 // We only support filesystem URL as of now. 81 // We only support filesystem URL as of now.
83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); 82 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem());
84 storage::BlobData::Item item; 83 storage::DataElement item;
85 item.SetToFileSystemUrlRange( 84 item.SetToFileSystemUrlRange(
86 data_item.fileSystemURL, 85 data_item.fileSystemURL,
87 static_cast<uint64>(data_item.offset), 86 static_cast<uint64>(data_item.offset),
88 static_cast<uint64>(data_item.length), 87 static_cast<uint64>(data_item.length),
89 base::Time::FromDoubleT(data_item.expectedModificationTime)); 88 base::Time::FromDoubleT(data_item.expectedModificationTime));
90 sender_->Send( 89 sender_->Send(
91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 90 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
92 } 91 }
93 break; 92 break;
94 default: 93 default:
(...skipping 20 matching lines...) Expand all
115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { 114 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); 115 sender_->Send(new BlobHostMsg_RevokePublicURL(url));
117 } 116 }
118 117
119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, 118 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str,
120 const WebThreadSafeData& data) { 119 const WebThreadSafeData& data) {
121 120
122 if (data.size() == 0) 121 if (data.size() == 0)
123 return; 122 return;
124 if (data.size() < kLargeThresholdBytes) { 123 if (data.size() < kLargeThresholdBytes) {
125 storage::BlobData::Item item; 124 storage::DataElement item;
126 item.SetToBytes(data.data(), data.size()); 125 item.SetToBytes(data.data(), data.size());
127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 126 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
128 } else { 127 } else {
129 // We handle larger amounts of data via SharedMemory instead of 128 // We handle larger amounts of data via SharedMemory instead of
130 // writing it directly to the IPC channel. 129 // writing it directly to the IPC channel.
131 size_t shared_memory_size = std::min( 130 size_t shared_memory_size = std::min(
132 data.size(), kMaxSharedMemoryBytes); 131 data.size(), kMaxSharedMemoryBytes);
133 scoped_ptr<base::SharedMemory> shared_memory( 132 scoped_ptr<base::SharedMemory> shared_memory(
134 ChildThread::AllocateSharedMemory(shared_memory_size, 133 ChildThread::AllocateSharedMemory(shared_memory_size,
135 sender_.get())); 134 sender_.get()));
(...skipping 27 matching lines...) Expand all
163 DCHECK(ChildThread::current()); 162 DCHECK(ChildThread::current());
164 sender_->Send(new StreamHostMsg_Clone(url, src_url)); 163 sender_->Send(new StreamHostMsg_Clone(url, src_url));
165 } 164 }
166 165
167 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, 166 void WebBlobRegistryImpl::addDataToStream(const WebURL& url,
168 const char* data, size_t length) { 167 const char* data, size_t length) {
169 DCHECK(ChildThread::current()); 168 DCHECK(ChildThread::current());
170 if (length == 0) 169 if (length == 0)
171 return; 170 return;
172 if (length < kLargeThresholdBytes) { 171 if (length < kLargeThresholdBytes) {
173 storage::BlobData::Item item; 172 storage::DataElement item;
174 item.SetToBytes(data, length); 173 item.SetToBytes(data, length);
175 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); 174 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item));
176 } else { 175 } else {
177 // We handle larger amounts of data via SharedMemory instead of 176 // We handle larger amounts of data via SharedMemory instead of
178 // writing it directly to the IPC channel. 177 // writing it directly to the IPC channel.
179 size_t shared_memory_size = std::min( 178 size_t shared_memory_size = std::min(
180 length, kMaxSharedMemoryBytes); 179 length, kMaxSharedMemoryBytes);
181 scoped_ptr<base::SharedMemory> shared_memory( 180 scoped_ptr<base::SharedMemory> shared_memory(
182 ChildThread::AllocateSharedMemory(shared_memory_size, 181 ChildThread::AllocateSharedMemory(shared_memory_size,
183 sender_.get())); 182 sender_.get()));
(...skipping 28 matching lines...) Expand all
212 DCHECK(ChildThread::current()); 211 DCHECK(ChildThread::current());
213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); 212 sender_->Send(new StreamHostMsg_AbortBuilding(url));
214 } 213 }
215 214
216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { 215 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
217 DCHECK(ChildThread::current()); 216 DCHECK(ChildThread::current());
218 sender_->Send(new StreamHostMsg_Remove(url)); 217 sender_->Send(new StreamHostMsg_Remove(url));
219 } 218 }
220 219
221 } // namespace content 220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698