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

Side by Side Diff: content/browser/fileapi/fileapi_message_filter.cc

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments Created 5 years 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 (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 "content/browser/fileapi/fileapi_message_filter.h" 5 #include "content/browser/fileapi/fileapi_message_filter.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/browser/bad_message.h" 18 #include "content/browser/bad_message.h"
19 #include "content/browser/child_process_security_policy_impl.h" 19 #include "content/browser/child_process_security_policy_impl.h"
20 #include "content/browser/fileapi/blob_storage_host.h"
21 #include "content/browser/fileapi/browser_file_system_helper.h" 20 #include "content/browser/fileapi/browser_file_system_helper.h"
22 #include "content/browser/fileapi/chrome_blob_storage_context.h" 21 #include "content/browser/fileapi/chrome_blob_storage_context.h"
23 #include "content/browser/streams/stream_registry.h" 22 #include "content/browser/streams/stream_registry.h"
24 #include "content/common/fileapi/file_system_messages.h" 23 #include "content/common/fileapi/file_system_messages.h"
25 #include "content/common/fileapi/webblob_messages.h" 24 #include "content/common/fileapi/webblob_messages.h"
26 #include "content/public/browser/user_metrics.h" 25 #include "content/public/browser/user_metrics.h"
27 #include "ipc/ipc_platform_file.h" 26 #include "ipc/ipc_platform_file.h"
28 #include "net/base/mime_util.h" 27 #include "net/base/mime_util.h"
29 #include "net/url_request/url_request_context.h" 28 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_context_getter.h" 29 #include "net/url_request/url_request_context_getter.h"
(...skipping 15 matching lines...) Expand all
46 using storage::FileSystemBackend; 45 using storage::FileSystemBackend;
47 using storage::FileSystemOperation; 46 using storage::FileSystemOperation;
48 using storage::FileSystemURL; 47 using storage::FileSystemURL;
49 using storage::BlobDataBuilder; 48 using storage::BlobDataBuilder;
50 using storage::BlobStorageContext; 49 using storage::BlobStorageContext;
51 50
52 namespace content { 51 namespace content {
53 52
54 namespace { 53 namespace {
55 54
56 const uint32 kFilteredMessageClasses[] = { 55 const uint32 kFilteredMessageClasses[] = {BlobMsgStart, FileSystemMsgStart};
michaeln 2015/12/15 02:40:48 does BlobMsgStart still belong here given the new
dmurph 2015/12/18 03:22:50 I don't think so.
57 BlobMsgStart,
58 FileSystemMsgStart,
59 };
60 56
61 void RevokeFilePermission(int child_id, const base::FilePath& path) { 57 void RevokeFilePermission(int child_id, const base::FilePath& path) {
62 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( 58 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile(
63 child_id, path); 59 child_id, path);
64 } 60 }
65 61
66 } // namespace 62 } // namespace
67 63
68 FileAPIMessageFilter::FileAPIMessageFilter( 64 FileAPIMessageFilter::FileAPIMessageFilter(
69 int process_id, 65 int process_id,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) { 105 void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) {
110 DCHECK_CURRENTLY_ON(BrowserThread::IO); 106 DCHECK_CURRENTLY_ON(BrowserThread::IO);
111 107
112 if (request_context_getter_.get()) { 108 if (request_context_getter_.get()) {
113 DCHECK(!request_context_); 109 DCHECK(!request_context_);
114 request_context_ = request_context_getter_->GetURLRequestContext(); 110 request_context_ = request_context_getter_->GetURLRequestContext();
115 request_context_getter_ = NULL; 111 request_context_getter_ = NULL;
116 DCHECK(request_context_); 112 DCHECK(request_context_);
117 } 113 }
118 114
119 blob_storage_host_.reset(
120 new BlobStorageHost(blob_storage_context_->context()));
121
122 operation_runner_ = context_->CreateFileSystemOperationRunner(); 115 operation_runner_ = context_->CreateFileSystemOperationRunner();
123 } 116 }
124 117
125 void FileAPIMessageFilter::OnChannelClosing() { 118 void FileAPIMessageFilter::OnChannelClosing() {
126 DCHECK_CURRENTLY_ON(BrowserThread::IO); 119 DCHECK_CURRENTLY_ON(BrowserThread::IO);
127 120
128 // Unregister all the blob and stream URLs that are previously registered in 121 // Unregister all stream URLs that are previously registered in this process.
129 // this process.
130 blob_storage_host_.reset();
131 for (base::hash_set<std::string>::const_iterator iter = stream_urls_.begin(); 122 for (base::hash_set<std::string>::const_iterator iter = stream_urls_.begin();
132 iter != stream_urls_.end(); ++iter) { 123 iter != stream_urls_.end(); ++iter) {
133 stream_context_->registry()->UnregisterStream(GURL(*iter)); 124 stream_context_->registry()->UnregisterStream(GURL(*iter));
134 } 125 }
135 126
136 in_transit_snapshot_files_.clear(); 127 in_transit_snapshot_files_.clear();
137 128
138 operation_runner_.reset(); 129 operation_runner_.reset();
139 operations_.clear(); 130 operations_.clear();
140 } 131 }
(...skipping 21 matching lines...) Expand all
162 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite) 153 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite)
163 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate) 154 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate)
164 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) 155 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile)
165 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) 156 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel)
166 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile, 157 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile,
167 OnCreateSnapshotFile) 158 OnCreateSnapshotFile)
168 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidReceiveSnapshotFile, 159 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidReceiveSnapshotFile,
169 OnDidReceiveSnapshotFile) 160 OnDidReceiveSnapshotFile)
170 IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath, 161 IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath,
171 OnSyncGetPlatformPath) 162 OnSyncGetPlatformPath)
172 IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuilding, OnStartBuildingBlob)
173 IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem,
174 OnAppendBlobDataItemToBlob)
175 IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory,
176 OnAppendSharedMemoryToBlob)
177 IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuilding, OnFinishBuildingBlob)
178 IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount,
179 OnIncrementBlobRefCount)
180 IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount,
181 OnDecrementBlobRefCount)
182 IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL,
183 OnRegisterPublicBlobURL)
184 IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL)
185 IPC_MESSAGE_HANDLER(StreamHostMsg_StartBuilding, OnStartBuildingStream) 163 IPC_MESSAGE_HANDLER(StreamHostMsg_StartBuilding, OnStartBuildingStream)
186 IPC_MESSAGE_HANDLER(StreamHostMsg_AppendBlobDataItem, 164 IPC_MESSAGE_HANDLER(StreamHostMsg_AppendBlobDataItem,
187 OnAppendBlobDataItemToStream) 165 OnAppendBlobDataItemToStream)
188 IPC_MESSAGE_HANDLER(StreamHostMsg_SyncAppendSharedMemory, 166 IPC_MESSAGE_HANDLER(StreamHostMsg_SyncAppendSharedMemory,
189 OnAppendSharedMemoryToStream) 167 OnAppendSharedMemoryToStream)
190 IPC_MESSAGE_HANDLER(StreamHostMsg_Flush, OnFlushStream) 168 IPC_MESSAGE_HANDLER(StreamHostMsg_Flush, OnFlushStream)
191 IPC_MESSAGE_HANDLER(StreamHostMsg_FinishBuilding, OnFinishBuildingStream) 169 IPC_MESSAGE_HANDLER(StreamHostMsg_FinishBuilding, OnFinishBuildingStream)
192 IPC_MESSAGE_HANDLER(StreamHostMsg_AbortBuilding, OnAbortBuildingStream) 170 IPC_MESSAGE_HANDLER(StreamHostMsg_AbortBuilding, OnAbortBuildingStream)
193 IPC_MESSAGE_HANDLER(StreamHostMsg_Clone, OnCloneStream) 171 IPC_MESSAGE_HANDLER(StreamHostMsg_Clone, OnCloneStream)
194 IPC_MESSAGE_HANDLER(StreamHostMsg_Remove, OnRemoveStream) 172 IPC_MESSAGE_HANDLER(StreamHostMsg_Remove, OnRemoveStream)
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot, 485 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot,
508 this, request_id, url)); 486 this, request_id, url));
509 } 487 }
510 } 488 }
511 489
512 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) { 490 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) {
513 DCHECK_CURRENTLY_ON(BrowserThread::IO); 491 DCHECK_CURRENTLY_ON(BrowserThread::IO);
514 in_transit_snapshot_files_.erase(request_id); 492 in_transit_snapshot_files_.erase(request_id);
515 } 493 }
516 494
517 void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) {
518 DCHECK_CURRENTLY_ON(BrowserThread::IO);
519 ignore_result(blob_storage_host_->StartBuildingBlob(uuid));
520 }
521
522 void FileAPIMessageFilter::OnAppendBlobDataItemToBlob(
523 const std::string& uuid,
524 const storage::DataElement& item) {
525 DCHECK_CURRENTLY_ON(BrowserThread::IO);
526 if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) {
527 FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url()));
528 if (!FileSystemURLIsValid(context_, filesystem_url) ||
529 !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) {
530 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid));
531 return;
532 }
533 }
534 if (item.type() == storage::DataElement::TYPE_FILE &&
535 !security_policy_->CanReadFile(process_id_, item.path())) {
536 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid));
537 return;
538 }
539 if (item.length() == 0) {
540 bad_message::ReceivedBadMessage(this,
541 bad_message::FAMF_APPEND_ITEM_TO_BLOB);
542 return;
543 }
544 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item));
545 }
546
547 void FileAPIMessageFilter::OnAppendSharedMemoryToBlob(
548 const std::string& uuid,
549 base::SharedMemoryHandle handle,
550 size_t buffer_size) {
551 DCHECK(base::SharedMemory::IsHandleValid(handle));
552 if (!buffer_size) {
553 bad_message::ReceivedBadMessage(
554 this, bad_message::FAMF_APPEND_SHARED_MEMORY_TO_BLOB);
555 return;
556 }
557 #if defined(OS_WIN)
558 base::SharedMemory shared_memory(handle, true, PeerHandle());
559 #else
560 base::SharedMemory shared_memory(handle, true);
561 #endif
562 if (!shared_memory.Map(buffer_size)) {
563 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid));
564 return;
565 }
566
567 storage::DataElement item;
568 item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()),
569 buffer_size);
570 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item));
571 }
572
573 void FileAPIMessageFilter::OnFinishBuildingBlob(
574 const std::string& uuid, const std::string& content_type) {
575 DCHECK_CURRENTLY_ON(BrowserThread::IO);
576 ignore_result(blob_storage_host_->FinishBuildingBlob(uuid, content_type));
577 // TODO(michaeln): check return values once blink has migrated, crbug/174200
578 }
579
580 void FileAPIMessageFilter::OnIncrementBlobRefCount(const std::string& uuid) {
581 DCHECK_CURRENTLY_ON(BrowserThread::IO);
582 ignore_result(blob_storage_host_->IncrementBlobRefCount(uuid));
583 }
584
585 void FileAPIMessageFilter::OnDecrementBlobRefCount(const std::string& uuid) {
586 DCHECK_CURRENTLY_ON(BrowserThread::IO);
587 ignore_result(blob_storage_host_->DecrementBlobRefCount(uuid));
588 }
589
590 void FileAPIMessageFilter::OnRegisterPublicBlobURL(
591 const GURL& public_url, const std::string& uuid) {
592 DCHECK_CURRENTLY_ON(BrowserThread::IO);
593 ignore_result(blob_storage_host_->RegisterPublicBlobURL(public_url, uuid));
594 }
595
596 void FileAPIMessageFilter::OnRevokePublicBlobURL(const GURL& public_url) {
597 DCHECK_CURRENTLY_ON(BrowserThread::IO);
598 ignore_result(blob_storage_host_->RevokePublicBlobURL(public_url));
599 }
600
601 void FileAPIMessageFilter::OnStartBuildingStream( 495 void FileAPIMessageFilter::OnStartBuildingStream(
602 const GURL& url, const std::string& content_type) { 496 const GURL& url, const std::string& content_type) {
603 DCHECK_CURRENTLY_ON(BrowserThread::IO); 497 DCHECK_CURRENTLY_ON(BrowserThread::IO);
604 // Only an internal Blob URL is expected here. See the BlobURL of the Blink. 498 // Only an internal Blob URL is expected here. See the BlobURL of the Blink.
605 if (!base::StartsWith(url.path(), "blobinternal%3A///", 499 if (!base::StartsWith(url.path(), "blobinternal%3A///",
606 base::CompareCase::SENSITIVE)) { 500 base::CompareCase::SENSITIVE)) {
607 NOTREACHED() << "Malformed Stream URL: " << url.spec(); 501 NOTREACHED() << "Malformed Stream URL: " << url.spec();
608 bad_message::ReceivedBadMessage(this, 502 bad_message::ReceivedBadMessage(this,
609 bad_message::FAMF_MALFORMED_STREAM_URL); 503 bad_message::FAMF_MALFORMED_STREAM_URL);
610 return; 504 return;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 782 }
889 783
890 return true; 784 return true;
891 } 785 }
892 786
893 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { 787 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) {
894 return stream_context_->registry()->GetStream(url); 788 return stream_context_->registry()->GetStream(url);
895 } 789 }
896 790
897 } // namespace content 791 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698