Index: content/browser/fileapi/fileapi_message_filter.cc |
diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc |
index 5258fbffd541a9015b580ed36a18ee9c8c53a99d..0ed0853f5e219f2718a8ae91c08b2a20c8ff1b25 100644 |
--- a/content/browser/fileapi/fileapi_message_filter.cc |
+++ b/content/browser/fileapi/fileapi_message_filter.cc |
@@ -119,6 +119,21 @@ void FileAPIMessageFilter::OnChannelClosing() { |
iter != blob_urls_.end(); ++iter) { |
blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); |
} |
+ |
+ // Close all files that are previously OpenFile()'ed in this process. |
+ if (!open_filesystem_urls_.empty()) { |
+ DLOG(INFO) |
+ << "File API: Renderer process shut down before NotifyCloseFile" |
+ << " for " << open_filesystem_urls_.size() << " files opened in PPAPI"; |
+ } |
+ for (std::multiset<GURL>::const_iterator iter = |
+ open_filesystem_urls_.begin(); |
+ iter != open_filesystem_urls_.end(); ++iter) { |
+ FileSystemOperationInterface* operation = |
+ context_->CreateFileSystemOperation(*iter); |
+ if (operation) |
+ operation->NotifyCloseFile(*iter); |
+ } |
} |
void FileAPIMessageFilter::OverrideThreadForMessage( |
@@ -146,6 +161,7 @@ bool FileAPIMessageFilter::OnMessageReceived( |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_OpenFile, OnOpenFile) |
+ IPC_MESSAGE_HANDLER(FileSystemHostMsg_NotifyCloseFile, OnNotifyCloseFile) |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_CreateSnapshotFile, |
OnCreateSnapshotFile) |
IPC_MESSAGE_HANDLER(FileSystemHostMsg_WillUpdate, OnWillUpdate) |
@@ -390,7 +406,24 @@ void FileAPIMessageFilter::OnOpenFile( |
GetNewOperation(path, request_id)->OpenFile( |
path, file_flags, peer_handle(), |
- base::Bind(&FileAPIMessageFilter::DidOpenFile, this, request_id)); |
+ base::Bind(&FileAPIMessageFilter::DidOpenFile, this, request_id, path)); |
+} |
+ |
+void FileAPIMessageFilter::OnNotifyCloseFile(const GURL& path) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ // Remove |path| from the set of opened urls. It must only be called for a URL |
+ // that is successfully opened and enrolled in DidOpenFile. |
+ std::multiset<GURL>::iterator iter = open_filesystem_urls_.find(path); |
+ DCHECK(iter != open_filesystem_urls_.end()); |
+ open_filesystem_urls_.erase(iter); |
+ |
+ // Do not use GetNewOperation() here, because NotifyCloseFile is an one-way |
kinuko
2012/06/26 11:13:36
nit: an one way -> a one-way
kinaba
2012/06/27 03:47:42
Done.
|
+ // operation that does not have request_id by which we respond back. |
+ FileSystemOperationInterface* operation = |
+ context_->CreateFileSystemOperation(path); |
+ if (operation) |
+ operation->NotifyCloseFile(path); |
} |
void FileAPIMessageFilter::OnWillUpdate(const GURL& path) { |
@@ -561,6 +594,7 @@ void FileAPIMessageFilter::DidReadDirectory( |
} |
void FileAPIMessageFilter::DidOpenFile(int request_id, |
+ const GURL& path, |
base::PlatformFileError result, |
base::PlatformFile file, |
base::ProcessHandle peer_handle) { |
@@ -569,6 +603,7 @@ void FileAPIMessageFilter::DidOpenFile(int request_id, |
file != base::kInvalidPlatformFileValue ? |
IPC::GetFileHandleForProcess(file, peer_handle, true) : |
IPC::InvalidPlatformFileForTransit(); |
+ open_filesystem_urls_.insert(path); |
Send(new FileSystemMsg_DidOpenFile(request_id, file_for_transit)); |
} else { |
Send(new FileSystemMsg_DidFail(request_id, result)); |