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

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

Issue 16325022: move content/common_child to content/child (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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
« no previous file with comments | « content/common_child/webblobregistry_impl.h ('k') | content/content.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common_child/webblobregistry_impl.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h"
9 #include "base/shared_memory.h"
10 #include "content/common/child_thread.h"
11 #include "content/common/fileapi/webblob_messages.h"
12 #include "content/common/thread_safe_sender.h"
13 #include "third_party/WebKit/public/platform/WebBlobData.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebURL.h"
16 #include "webkit/base/file_path_string_conversions.h"
17 #include "webkit/common/blob/blob_data.h"
18
19 using WebKit::WebBlobData;
20 using WebKit::WebString;
21 using WebKit::WebURL;
22
23 namespace content {
24
25 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender)
26 : sender_(sender) {
27 }
28
29 WebBlobRegistryImpl::~WebBlobRegistryImpl() {
30 }
31
32 void WebBlobRegistryImpl::registerBlobURL(
33 const WebURL& url, WebBlobData& data) {
34 DCHECK(ChildThread::current()->message_loop() ==
35 base::MessageLoop::current());
36 const size_t kLargeThresholdBytes = 250 * 1024;
37 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024;
38
39 sender_->Send(new BlobHostMsg_StartBuildingBlob(url));
40 size_t i = 0;
41 WebBlobData::Item data_item;
42 while (data.itemAt(i++, data_item)) {
43 webkit_blob::BlobData::Item item;
44 switch (data_item.type) {
45 case WebBlobData::Item::TypeData: {
46 // WebBlobData does not allow partial data items.
47 DCHECK(!data_item.offset && data_item.length == -1);
48 if (data_item.data.size() == 0)
49 break;
50 if (data_item.data.size() < kLargeThresholdBytes) {
51 item.SetToBytes(data_item.data.data(), data_item.data.size());
52 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
53 } else {
54 // We handle larger amounts of data via SharedMemory instead of
55 // writing it directly to the IPC channel.
56 size_t data_size = data_item.data.size();
57 const char* data_ptr = data_item.data.data();
58 size_t shared_memory_size = std::min(
59 data_size, kMaxSharedMemoryBytes);
60 scoped_ptr<base::SharedMemory> shared_memory(
61 ChildThread::AllocateSharedMemory(shared_memory_size,
62 sender_.get()));
63 CHECK(shared_memory.get());
64 while (data_size) {
65 size_t chunk_size = std::min(data_size, shared_memory_size);
66 memcpy(shared_memory->memory(), data_ptr, chunk_size);
67 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
68 url, shared_memory->handle(), chunk_size));
69 data_size -= chunk_size;
70 data_ptr += chunk_size;
71 }
72 }
73 break;
74 }
75 case WebBlobData::Item::TypeFile:
76 if (data_item.length) {
77 item.SetToFilePathRange(
78 webkit_base::WebStringToFilePath(data_item.filePath),
79 static_cast<uint64>(data_item.offset),
80 static_cast<uint64>(data_item.length),
81 base::Time::FromDoubleT(data_item.expectedModificationTime));
82 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
83 }
84 break;
85 case WebBlobData::Item::TypeBlob:
86 if (data_item.length) {
87 item.SetToBlobUrlRange(
88 data_item.blobURL,
89 static_cast<uint64>(data_item.offset),
90 static_cast<uint64>(data_item.length));
91 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
92 }
93 break;
94 case WebBlobData::Item::TypeURL:
95 if (data_item.length) {
96 // We only support filesystem URL as of now.
97 DCHECK(GURL(data_item.url).SchemeIsFileSystem());
98 item.SetToFileSystemUrlRange(
99 data_item.url,
100 static_cast<uint64>(data_item.offset),
101 static_cast<uint64>(data_item.length),
102 base::Time::FromDoubleT(data_item.expectedModificationTime));
103 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
104 }
105 break;
106 default:
107 NOTREACHED();
108 }
109 }
110 sender_->Send(new BlobHostMsg_FinishBuildingBlob(
111 url, data.contentType().utf8().data()));
112 }
113
114 void WebBlobRegistryImpl::registerBlobURL(
115 const WebURL& url, const WebURL& src_url) {
116 DCHECK(ChildThread::current()->message_loop() ==
117 base::MessageLoop::current());
118 sender_->Send(new BlobHostMsg_CloneBlob(url, src_url));
119 }
120
121 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
122 DCHECK(ChildThread::current()->message_loop() ==
123 base::MessageLoop::current());
124 sender_->Send(new BlobHostMsg_RemoveBlob(url));
125 }
126
127 } // namespace content
OLDNEW
« no previous file with comments | « content/common_child/webblobregistry_impl.h ('k') | content/content.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698