| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/file_system/file_system_dispatcher_host.h" | 5 #include "chrome/browser/file_system/file_system_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/thread.h" | 8 #include "base/thread.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 bool handled = true; | 108 bool handled = true; |
| 109 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) | 109 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) |
| 110 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) | 110 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) |
| 111 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) | 111 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) |
| 112 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Copy, OnCopy) | 112 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Copy, OnCopy) |
| 113 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Remove, OnRemove) | 113 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Remove, OnRemove) |
| 114 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) | 114 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) |
| 115 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) | 115 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) |
| 116 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) | 116 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) |
| 117 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory) | 117 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory) |
| 118 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Write, OnWrite) |
| 119 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Truncate, OnTruncate) |
| 120 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_CancelWrite, OnCancel) |
| 118 IPC_MESSAGE_UNHANDLED(handled = false) | 121 IPC_MESSAGE_UNHANDLED(handled = false) |
| 119 IPC_END_MESSAGE_MAP_EX() | 122 IPC_END_MESSAGE_MAP_EX() |
| 120 return handled; | 123 return handled; |
| 121 } | 124 } |
| 122 | 125 |
| 123 void FileSystemDispatcherHost::OnOpenFileSystem( | 126 void FileSystemDispatcherHost::OnOpenFileSystem( |
| 124 const ViewHostMsg_OpenFileSystemRequest_Params& params) { | 127 const ViewHostMsg_OpenFileSystemRequest_Params& params) { |
| 125 | 128 |
| 126 // TODO(kinuko): hook up ContentSettings cookies type checks. | 129 // TODO(kinuko): hook up ContentSettings cookies type checks. |
| 127 | 130 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 GetNewOperation(request_id)->FileExists(path); | 202 GetNewOperation(request_id)->FileExists(path); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void FileSystemDispatcherHost::OnReadDirectory( | 205 void FileSystemDispatcherHost::OnReadDirectory( |
| 203 int request_id, const FilePath& path) { | 206 int request_id, const FilePath& path) { |
| 204 if (!CheckValidFileSystemPath(path, request_id)) | 207 if (!CheckValidFileSystemPath(path, request_id)) |
| 205 return; | 208 return; |
| 206 GetNewOperation(request_id)->ReadDirectory(path); | 209 GetNewOperation(request_id)->ReadDirectory(path); |
| 207 } | 210 } |
| 208 | 211 |
| 212 void FileSystemDispatcherHost::OnWrite( |
| 213 int request_id, |
| 214 const FilePath& path, |
| 215 const GURL& blob_url, |
| 216 int64 offset) { |
| 217 if (!CheckValidFileSystemPath(path, request_id)) |
| 218 return; |
| 219 GetNewOperation(request_id)->Write(path, blob_url, offset); |
| 220 } |
| 221 |
| 222 void FileSystemDispatcherHost::OnTruncate( |
| 223 int request_id, |
| 224 const FilePath& path, |
| 225 int64 length) { |
| 226 if (!CheckValidFileSystemPath(path, request_id)) |
| 227 return; |
| 228 GetNewOperation(request_id)->Truncate(path, length); |
| 229 } |
| 230 |
| 231 void FileSystemDispatcherHost::OnCancel( |
| 232 int request_id, |
| 233 int request_id_to_cancel) { |
| 234 fileapi::FileSystemOperation* write = |
| 235 operations_.Lookup(request_id_to_cancel); |
| 236 if (write) { |
| 237 write->Cancel(); |
| 238 Send(new ViewMsg_FileSystem_DidSucceed(request_id)); |
| 239 } else { |
| 240 Send(new ViewMsg_FileSystem_DidFail( |
| 241 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); |
| 242 } |
| 243 } |
| 244 |
| 209 void FileSystemDispatcherHost::Send(IPC::Message* message) { | 245 void FileSystemDispatcherHost::Send(IPC::Message* message) { |
| 210 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 246 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 211 if (!shutdown_ && message_sender_) | 247 if (!shutdown_ && message_sender_) |
| 212 message_sender_->Send(message); | 248 message_sender_->Send(message); |
| 213 else | 249 else |
| 214 delete message; | 250 delete message; |
| 215 } | 251 } |
| 216 | 252 |
| 217 bool FileSystemDispatcherHost::CheckValidFileSystemPath( | 253 bool FileSystemDispatcherHost::CheckValidFileSystemPath( |
| 218 const FilePath& path, int request_id) { | 254 const FilePath& path, int request_id) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 234 dispatcher, | 270 dispatcher, |
| 235 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | 271 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); |
| 236 operations_.AddWithID(operation, request_id); | 272 operations_.AddWithID(operation, request_id); |
| 237 return operation; | 273 return operation; |
| 238 } | 274 } |
| 239 | 275 |
| 240 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { | 276 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { |
| 241 DCHECK(operations_.Lookup(request_id)); | 277 DCHECK(operations_.Lookup(request_id)); |
| 242 operations_.Remove(request_id); | 278 operations_.Remove(request_id); |
| 243 } | 279 } |
| OLD | NEW |