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

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

Issue 12084077: FileSystem mods: Changes to snapshot file creation to remove dependencies on blobs. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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
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"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void FileAPIMessageFilter::OnChannelClosing() { 99 void FileAPIMessageFilter::OnChannelClosing() {
100 BrowserMessageFilter::OnChannelClosing(); 100 BrowserMessageFilter::OnChannelClosing();
101 101
102 // Unregister all the blob URLs that are previously registered in this 102 // Unregister all the blob URLs that are previously registered in this
103 // process. 103 // process.
104 for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin(); 104 for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin();
105 iter != blob_urls_.end(); ++iter) { 105 iter != blob_urls_.end(); ++iter) {
106 blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); 106 blob_storage_context_->controller()->RemoveBlob(GURL(*iter));
107 } 107 }
108 108
109 in_transit_snapshot_files_.clear();
110
109 // Close all files that are previously OpenFile()'ed in this process. 111 // Close all files that are previously OpenFile()'ed in this process.
110 if (!open_filesystem_urls_.empty()) { 112 if (!open_filesystem_urls_.empty()) {
111 DLOG(INFO) 113 DLOG(INFO)
112 << "File API: Renderer process shut down before NotifyCloseFile" 114 << "File API: Renderer process shut down before NotifyCloseFile"
113 << " for " << open_filesystem_urls_.size() << " files opened in PPAPI"; 115 << " for " << open_filesystem_urls_.size() << " files opened in PPAPI";
114 } 116 }
115 for (std::multiset<GURL>::const_iterator iter = 117 for (std::multiset<GURL>::const_iterator iter =
116 open_filesystem_urls_.begin(); 118 open_filesystem_urls_.begin();
117 iter != open_filesystem_urls_.end(); ++iter) { 119 iter != open_filesystem_urls_.end(); ++iter) {
118 FileSystemURL url(context_->CrackURL(*iter)); 120 FileSystemURL url(context_->CrackURL(*iter));
(...skipping 26 matching lines...) Expand all
145 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Exists, OnExists) 147 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Exists, OnExists)
146 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadDirectory, OnReadDirectory) 148 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadDirectory, OnReadDirectory)
147 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite) 149 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite)
148 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate) 150 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate)
149 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) 151 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile)
150 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) 152 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel)
151 IPC_MESSAGE_HANDLER(FileSystemHostMsg_OpenFile, OnOpenFile) 153 IPC_MESSAGE_HANDLER(FileSystemHostMsg_OpenFile, OnOpenFile)
152 IPC_MESSAGE_HANDLER(FileSystemHostMsg_NotifyCloseFile, OnNotifyCloseFile) 154 IPC_MESSAGE_HANDLER(FileSystemHostMsg_NotifyCloseFile, OnNotifyCloseFile)
153 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile, 155 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile,
154 OnCreateSnapshotFile) 156 OnCreateSnapshotFile)
157 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidReceiveSnapshotFile,
158 OnDidReceiveSnapshotFile)
159 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile_Deprecated,
160 OnCreateSnapshotFile_Deprecated)
155 IPC_MESSAGE_HANDLER(FileSystemHostMsg_WillUpdate, OnWillUpdate) 161 IPC_MESSAGE_HANDLER(FileSystemHostMsg_WillUpdate, OnWillUpdate)
156 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate) 162 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate)
157 IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath, 163 IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath,
158 OnSyncGetPlatformPath) 164 OnSyncGetPlatformPath)
159 IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob) 165 IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob)
160 IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem) 166 IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem)
161 IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory, 167 IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory,
162 OnAppendSharedMemory) 168 OnAppendSharedMemory)
163 IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob) 169 IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob)
164 IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob) 170 IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob)
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // for the file. (We first need to check if it can already be read not to 538 // for the file. (We first need to check if it can already be read not to
533 // overwrite existing permissions) 539 // overwrite existing permissions)
534 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 540 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
535 process_id_, *platform_path)) { 541 process_id_, *platform_path)) {
536 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( 542 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
537 process_id_, *platform_path); 543 process_id_, *platform_path);
538 } 544 }
539 } 545 }
540 546
541 void FileAPIMessageFilter::OnCreateSnapshotFile( 547 void FileAPIMessageFilter::OnCreateSnapshotFile(
548 int request_id, const GURL& path) {
549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
550 FileSystemURL url(context_->CrackURL(path));
551
552 // Make sure if this file can be read by the renderer as this is
553 // called when the renderer is about to create a new File object
554 // (for reading the file).
555 base::PlatformFileError error;
556 if (!HasPermissionsForFile(url, fileapi::kReadFilePermissions, &error)) {
557 Send(new FileSystemMsg_DidFail(request_id, error));
558 return;
559 }
560
561 FileSystemOperation* operation = GetNewOperation(url, request_id);
562 if (!operation)
563 return;
564 operation->CreateSnapshotFile(
565 url,
566 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot,
567 this, request_id, url));
568 }
569
570 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) {
571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
572 in_transit_snapshot_files_.erase(request_id);
573 }
574
575 void FileAPIMessageFilter::OnCreateSnapshotFile_Deprecated(
542 int request_id, const GURL& blob_url, const GURL& path) { 576 int request_id, const GURL& blob_url, const GURL& path) {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
544 FileSystemURL url(context_->CrackURL(path)); 578 FileSystemURL url(context_->CrackURL(path));
545 base::Callback<void(const base::FilePath&)> register_file_callback = 579 base::Callback<void(const base::FilePath&)> register_file_callback =
546 base::Bind(&FileAPIMessageFilter::RegisterFileAsBlob, 580 base::Bind(&FileAPIMessageFilter::RegisterFileAsBlob,
547 this, blob_url, url); 581 this, blob_url, url);
548 582
549 // Make sure if this file can be read by the renderer as this is 583 // Make sure if this file can be read by the renderer as this is
550 // called when the renderer is about to create a new File object 584 // called when the renderer is about to create a new File object
551 // (for reading the file). 585 // (for reading the file).
552 base::PlatformFileError error; 586 base::PlatformFileError error;
553 if (!HasPermissionsForFile(url, fileapi::kReadFilePermissions, &error)) { 587 if (!HasPermissionsForFile(url, fileapi::kReadFilePermissions, &error)) {
554 Send(new FileSystemMsg_DidFail(request_id, error)); 588 Send(new FileSystemMsg_DidFail(request_id, error));
555 return; 589 return;
556 } 590 }
557 591
558 FileSystemOperation* operation = GetNewOperation(url, request_id); 592 FileSystemOperation* operation = GetNewOperation(url, request_id);
559 if (!operation) 593 if (!operation)
560 return; 594 return;
561 operation->CreateSnapshotFile( 595 operation->CreateSnapshotFile(
562 url, 596 url,
563 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot, 597 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot_Deprecated,
564 this, request_id, register_file_callback)); 598 this, request_id, register_file_callback));
565 } 599 }
566 600
567 void FileAPIMessageFilter::OnStartBuildingBlob(const GURL& url) { 601 void FileAPIMessageFilter::OnStartBuildingBlob(const GURL& url) {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
569 blob_storage_context_->controller()->StartBuildingBlob(url); 603 blob_storage_context_->controller()->StartBuildingBlob(url);
570 blob_urls_.insert(url.spec()); 604 blob_urls_.insert(url.spec());
571 } 605 }
572 606
573 void FileAPIMessageFilter::OnAppendBlobDataItem( 607 void FileAPIMessageFilter::OnAppendBlobDataItem(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 if (result == base::PLATFORM_FILE_OK) 763 if (result == base::PLATFORM_FILE_OK)
730 Send(new FileSystemMsg_DidSucceed(request_id)); 764 Send(new FileSystemMsg_DidSucceed(request_id));
731 else 765 else
732 Send(new FileSystemMsg_DidFail(request_id, result)); 766 Send(new FileSystemMsg_DidFail(request_id, result));
733 // For DeleteFileSystem we do not create a new operation, 767 // For DeleteFileSystem we do not create a new operation,
734 // so no unregister here. 768 // so no unregister here.
735 } 769 }
736 770
737 void FileAPIMessageFilter::DidCreateSnapshot( 771 void FileAPIMessageFilter::DidCreateSnapshot(
738 int request_id, 772 int request_id,
773 const fileapi::FileSystemURL& url,
774 base::PlatformFileError result,
775 const base::PlatformFileInfo& info,
776 const base::FilePath& platform_path,
777 const scoped_refptr<webkit_blob::ShareableFileReference>& snapshot_file) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
779 if (result != base::PLATFORM_FILE_OK) {
780 Send(new FileSystemMsg_DidFail(request_id, result));
781 return;
782 }
783
784 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
785 process_id_, platform_path)) {
786 // In order for the renderer to be able to read the file, it must be granted
787 // read permission for the file's platform path. By now, it has already been
788 // verified that the renderer has sufficient permissions to read the file.
789 // It is still possible that ChildProcessSecurityPolicyImpl doesn't reflect
790 // that the renderer can read the file's platform path. If this is the case
791 // the renderer should be granted read permission for the file's platform
792 // path. This can happen in the following situations:
793 // - the file comes from sandboxed filesystem. Reading sandboxed files is
794 // always permitted, but only implicitly.
795 // - the underlying filesystem returned newly created snapshot file.
796 // - the file comes from an external drive filesystem. The renderer has
797 // already been granted read permission for the file's nominal path, but
798 // for drive files, platform paths differ from the nominal paths.
799 DCHECK(snapshot_file ||
800 fileapi::SandboxMountPointProvider::CanHandleType(url.type()) ||
801 url.type() == fileapi::kFileSystemTypeDrive);
802 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
803 process_id_, platform_path);
804 if (snapshot_file) {
805 // This will revoke all permissions for the file when the last ref
806 // of the file is dropped (assuming it's ok).
807 snapshot_file->AddFinalReleaseCallback(
808 base::Bind(&RevokeFilePermission, process_id_));
809 }
810 }
811
812 if (snapshot_file) {
813 // This ref is held until OnDidReceiveSnapshotFile is called.
814 in_transit_snapshot_files_[request_id] = snapshot_file;
815 }
816
817 // Return the file info and platform_path.
818 Send(new FileSystemMsg_DidCreateSnapshotFile(
819 request_id, info, platform_path));
820 }
821
822 void FileAPIMessageFilter::DidCreateSnapshot_Deprecated(
823 int request_id,
739 const base::Callback<void(const base::FilePath&)>& register_file_callback, 824 const base::Callback<void(const base::FilePath&)>& register_file_callback,
740 base::PlatformFileError result, 825 base::PlatformFileError result,
741 const base::PlatformFileInfo& info, 826 const base::PlatformFileInfo& info,
742 const base::FilePath& platform_path, 827 const base::FilePath& platform_path,
743 const scoped_refptr<webkit_blob::ShareableFileReference>& unused) { 828 const scoped_refptr<webkit_blob::ShareableFileReference>& unused) {
744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
745 if (result != base::PLATFORM_FILE_OK) { 830 if (result != base::PLATFORM_FILE_OK) {
746 Send(new FileSystemMsg_DidFail(request_id, result)); 831 Send(new FileSystemMsg_DidFail(request_id, result));
747 return; 832 return;
748 } 833 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 Send(new FileSystemMsg_DidFail(request_id, error_code)); 951 Send(new FileSystemMsg_DidFail(request_id, error_code));
867 return NULL; 952 return NULL;
868 } 953 }
869 954
870 DCHECK(operation); 955 DCHECK(operation);
871 operations_.AddWithID(operation, request_id); 956 operations_.AddWithID(operation, request_id);
872 return operation; 957 return operation;
873 } 958 }
874 959
875 } // namespace content 960 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.h ('k') | content/common/fileapi/file_system_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698