Index: content/browser/fileapi/fileapi_message_filter.cc |
=================================================================== |
--- content/browser/fileapi/fileapi_message_filter.cc (revision 183651) |
+++ content/browser/fileapi/fileapi_message_filter.cc (working copy) |
@@ -24,7 +24,7 @@ |
#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "webkit/blob/blob_data.h" |
-#include "webkit/blob/blob_storage_controller.h" |
+#include "webkit/blob/blob_storage_context.h" |
#include "webkit/blob/shareable_file_reference.h" |
#include "webkit/fileapi/file_observers.h" |
#include "webkit/fileapi/file_permission_policy.h" |
@@ -43,7 +43,8 @@ |
using fileapi::LocalFileSystemOperation; |
using fileapi::UpdateObserverList; |
using webkit_blob::BlobData; |
-using webkit_blob::BlobStorageController; |
+using webkit_blob::BlobStorageContext; |
+using webkit_blob::BlobStorageConsumer; |
namespace content { |
@@ -94,18 +95,15 @@ |
request_context_getter_ = NULL; |
DCHECK(request_context_); |
} |
+ |
+ blob_storage_consumer_.reset( |
+ new webkit_blob::BlobStorageConsumer(blob_storage_context_->context())); |
} |
void FileAPIMessageFilter::OnChannelClosing() { |
BrowserMessageFilter::OnChannelClosing(); |
- // Unregister all the blob URLs that are previously registered in this |
- // process. |
- for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin(); |
- iter != blob_urls_.end(); ++iter) { |
- blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); |
- } |
- |
+ blob_storage_consumer_.reset(); |
in_transit_snapshot_files_.clear(); |
// Close all files that are previously OpenFile()'ed in this process. |
@@ -162,13 +160,18 @@ |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate) |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath, |
OnSyncGetPlatformPath) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory, |
- OnAppendSharedMemory) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob) |
- IPC_MESSAGE_HANDLER(BlobHostMsg_RemoveBlob, OnRemoveBlob) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob2, OnStartBuildingBlob2) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem2, OnAppendBlobDataItem2) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_AppendSharedMemory2, |
+ OnAppendSharedMemory2) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob2, OnFinishBuildingBlob2) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementBlobRefCount, |
+ OnIncrementBlobRefCount) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementBlobRefCount, |
+ OnDecrementBlobRefCount) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicBlobURL, |
+ OnRegisterPublicBlobURL) |
+ IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicBlobURL, OnRevokePublicBlobURL) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP_EX() |
return handled; |
@@ -359,7 +362,7 @@ |
void FileAPIMessageFilter::OnWrite( |
int request_id, |
const GURL& path, |
- const GURL& blob_url, |
+ const std::string& blob_uuid, |
int64 offset) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
if (!request_context_) { |
@@ -378,8 +381,10 @@ |
FileSystemOperation* operation = GetNewOperation(url, request_id); |
if (!operation) |
return; |
+ scoped_ptr<webkit_blob::BlobDataHandle> blob = |
+ blob_storage_context_->context()->GetBlobDataFromUUID(blob_uuid); |
operation->Write( |
- request_context_, url, blob_url, offset, |
+ request_context_, url, blob.Pass(), offset, |
base::Bind(&FileAPIMessageFilter::DidWrite, this, request_id)); |
} |
@@ -598,36 +603,37 @@ |
this, request_id, register_file_callback)); |
} |
-void FileAPIMessageFilter::OnStartBuildingBlob(const GURL& url) { |
+void FileAPIMessageFilter::OnStartBuildingBlob2(const std::string& uuid) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- blob_storage_context_->controller()->StartBuildingBlob(url); |
- blob_urls_.insert(url.spec()); |
+ blob_storage_consumer_->StartBuildingBlob(uuid); |
} |
-void FileAPIMessageFilter::OnAppendBlobDataItem( |
- const GURL& url, const BlobData::Item& item) { |
+void FileAPIMessageFilter::OnAppendBlobDataItem2( |
+ const std::string& uuid, const webkit_blob::BlobData::Item& item) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
if (item.type() == BlobData::Item::TYPE_FILE_FILESYSTEM) { |
// TODO(kinuko): Implement permission check for filesystem files. |
// http://crbug.com/169423 |
- OnRemoveBlob(url); |
+ blob_storage_consumer_->CancelBuildingBlob(uuid); |
return; |
} |
if (item.type() == BlobData::Item::TYPE_FILE && |
!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
process_id_, item.path())) { |
- OnRemoveBlob(url); |
+ blob_storage_consumer_->CancelBuildingBlob(uuid); |
return; |
} |
if (item.length() == 0) { |
BadMessageReceived(); |
return; |
} |
- blob_storage_context_->controller()->AppendBlobDataItem(url, item); |
+ blob_storage_consumer_->AppendBlobDataItem(uuid, item); |
} |
-void FileAPIMessageFilter::OnAppendSharedMemory( |
- const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { |
+void FileAPIMessageFilter::OnAppendSharedMemory2( |
+ const std::string& uuid, |
+ base::SharedMemoryHandle handle, |
+ size_t buffer_size) { |
DCHECK(base::SharedMemory::IsHandleValid(handle)); |
if (!buffer_size) { |
BadMessageReceived(); |
@@ -639,35 +645,43 @@ |
base::SharedMemory shared_memory(handle, true); |
#endif |
if (!shared_memory.Map(buffer_size)) { |
- OnRemoveBlob(url); |
+ blob_storage_consumer_->CancelBuildingBlob(uuid); |
return; |
} |
BlobData::Item item; |
item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()), |
buffer_size); |
- blob_storage_context_->controller()->AppendBlobDataItem(url, item); |
+ blob_storage_consumer_->AppendBlobDataItem(uuid, item); |
} |
-void FileAPIMessageFilter::OnFinishBuildingBlob( |
- const GURL& url, const std::string& content_type) { |
+void FileAPIMessageFilter::OnFinishBuildingBlob2(const std::string& uuid, |
+ const std::string& content_type) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- blob_storage_context_->controller()->FinishBuildingBlob(url, content_type); |
+ blob_storage_consumer_->FinishBuildingBlob(uuid, content_type); |
} |
-void FileAPIMessageFilter::OnCloneBlob( |
- const GURL& url, const GURL& src_url) { |
+void FileAPIMessageFilter::OnIncrementBlobRefCount(const std::string& uuid) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- blob_storage_context_->controller()->CloneBlob(url, src_url); |
- blob_urls_.insert(url.spec()); |
+ blob_storage_consumer_->IncrementBlobRefCount(uuid); |
} |
-void FileAPIMessageFilter::OnRemoveBlob(const GURL& url) { |
+void FileAPIMessageFilter::OnDecrementBlobRefCount(const std::string& uuid) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- blob_storage_context_->controller()->RemoveBlob(url); |
- blob_urls_.erase(url.spec()); |
+ blob_storage_consumer_->DecrementBlobRefCount(uuid); |
} |
+void FileAPIMessageFilter::OnRegisterPublicBlobURL( |
+ const GURL& public_url, const std::string& uuid) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ blob_storage_consumer_->RegisterPublicBlobURL(public_url, uuid); |
+} |
+ |
+void FileAPIMessageFilter::OnRevokePublicBlobURL(const GURL& public_url) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ blob_storage_consumer_->RevokePublicBlobURL(public_url); |
+} |
+ |
void FileAPIMessageFilter::DidFinish(int request_id, |
base::PlatformFileError result) { |
if (result == base::PLATFORM_FILE_OK) |
@@ -827,70 +841,14 @@ |
const base::FilePath& platform_path, |
const scoped_refptr<webkit_blob::ShareableFileReference>& unused) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- if (result != base::PLATFORM_FILE_OK) { |
- Send(new FileSystemMsg_DidFail(request_id, result)); |
- return; |
- } |
- |
- // Register the created file to the blob registry by calling |
- // RegisterFileAsBlob. |
- // Blob storage automatically finds and refs the file_ref, so we don't |
- // need to do anything for the returned file reference (|unused|) here. |
- register_file_callback.Run(platform_path); |
- |
- // Return the file info and platform_path. |
- Send(new FileSystemMsg_DidReadMetadata(request_id, info, platform_path)); |
+ NOTREACHED(); |
} |
void FileAPIMessageFilter::RegisterFileAsBlob( |
const GURL& blob_url, |
const FileSystemURL& url, |
const base::FilePath& platform_path) { |
- // Use the virtual path's extension to determine MIME type. |
- base::FilePath::StringType extension = url.path().Extension(); |
- if (!extension.empty()) |
- extension = extension.substr(1); // Strip leading ".". |
- |
- scoped_refptr<webkit_blob::ShareableFileReference> shareable_file = |
- webkit_blob::ShareableFileReference::Get(platform_path); |
- if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
- process_id_, platform_path)) { |
- // In order for the renderer to be able to read the file, it must be granted |
- // read permission for the file's platform path. By now, it has already been |
- // verified that the renderer has sufficient permissions to read the file. |
- // It is still possible that ChildProcessSecurityPolicyImpl doesn't reflect |
- // that the renderer can read the file's platform path. If this is the case |
- // the renderer should be granted read permission for the file's platform |
- // path. This can happen in the following situations: |
- // - the file comes from sandboxed filesystem. Reading sandboxed files is |
- // always permitted, but only implicitly. |
- // - the underlying filesystem returned newly created snapshot file. |
- // - the file comes from an external drive filesystem. The renderer has |
- // already been granted read permission for the file's nominal path, but |
- // for drive files, platform paths differ from the nominal paths. |
- DCHECK(shareable_file || |
- fileapi::SandboxMountPointProvider::CanHandleType(url.type()) || |
- url.type() == fileapi::kFileSystemTypeDrive); |
- ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
- process_id_, platform_path); |
- if (shareable_file) { |
- // This will revoke all permissions for the file when the last ref |
- // of the file is dropped (assuming it's ok). |
- shareable_file->AddFinalReleaseCallback( |
- base::Bind(&RevokeFilePermission, process_id_)); |
- } |
- } |
- |
- // This may fail, but then we'll be just setting the empty mime type. |
- std::string mime_type; |
- net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); |
- BlobData::Item item; |
- item.SetToFilePathRange(platform_path, 0, -1, base::Time()); |
- BlobStorageController* controller = blob_storage_context_->controller(); |
- controller->StartBuildingBlob(blob_url); |
- controller->AppendBlobDataItem(blob_url, item); |
- controller->FinishBuildingBlob(blob_url, mime_type); |
- blob_urls_.insert(blob_url.spec()); |
+ NOTREACHED(); |
} |
bool FileAPIMessageFilter::HasPermissionsForFile( |