| OLD | NEW |
| 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/child/fileapi/file_system_dispatcher.h" | 5 #include "content/child/fileapi/file_system_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "content/child/child_thread.h" | 11 #include "content/child/child_thread_impl.h" |
| 12 #include "content/common/fileapi/file_system_messages.h" | 12 #include "content/common/fileapi/file_system_messages.h" |
| 13 #include "storage/common/fileapi/file_system_info.h" | 13 #include "storage/common/fileapi/file_system_info.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 class FileSystemDispatcher::CallbackDispatcher { | 17 class FileSystemDispatcher::CallbackDispatcher { |
| 18 public: | 18 public: |
| 19 typedef CallbackDispatcher self; | 19 typedef CallbackDispatcher self; |
| 20 typedef FileSystemDispatcher::StatusCallback StatusCallback; | 20 typedef FileSystemDispatcher::StatusCallback StatusCallback; |
| 21 typedef FileSystemDispatcher::MetadataCallback MetadataCallback; | 21 typedef FileSystemDispatcher::MetadataCallback MetadataCallback; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 return handled; | 164 return handled; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FileSystemDispatcher::OpenFileSystem( | 167 void FileSystemDispatcher::OpenFileSystem( |
| 168 const GURL& origin_url, | 168 const GURL& origin_url, |
| 169 storage::FileSystemType type, | 169 storage::FileSystemType type, |
| 170 const OpenFileSystemCallback& success_callback, | 170 const OpenFileSystemCallback& success_callback, |
| 171 const StatusCallback& error_callback) { | 171 const StatusCallback& error_callback) { |
| 172 int request_id = dispatchers_.Add( | 172 int request_id = dispatchers_.Add( |
| 173 CallbackDispatcher::Create(success_callback, error_callback)); | 173 CallbackDispatcher::Create(success_callback, error_callback)); |
| 174 ChildThread::current()->Send(new FileSystemHostMsg_OpenFileSystem( | 174 ChildThreadImpl::current()->Send(new FileSystemHostMsg_OpenFileSystem( |
| 175 request_id, origin_url, type)); | 175 request_id, origin_url, type)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void FileSystemDispatcher::ResolveURL( | 178 void FileSystemDispatcher::ResolveURL( |
| 179 const GURL& filesystem_url, | 179 const GURL& filesystem_url, |
| 180 const ResolveURLCallback& success_callback, | 180 const ResolveURLCallback& success_callback, |
| 181 const StatusCallback& error_callback) { | 181 const StatusCallback& error_callback) { |
| 182 int request_id = dispatchers_.Add( | 182 int request_id = dispatchers_.Add( |
| 183 CallbackDispatcher::Create(success_callback, error_callback)); | 183 CallbackDispatcher::Create(success_callback, error_callback)); |
| 184 ChildThread::current()->Send(new FileSystemHostMsg_ResolveURL( | 184 ChildThreadImpl::current()->Send(new FileSystemHostMsg_ResolveURL( |
| 185 request_id, filesystem_url)); | 185 request_id, filesystem_url)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void FileSystemDispatcher::DeleteFileSystem(const GURL& origin_url, | 188 void FileSystemDispatcher::DeleteFileSystem(const GURL& origin_url, |
| 189 storage::FileSystemType type, | 189 storage::FileSystemType type, |
| 190 const StatusCallback& callback) { | 190 const StatusCallback& callback) { |
| 191 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 191 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 192 ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem( | 192 ChildThreadImpl::current()->Send(new FileSystemHostMsg_DeleteFileSystem( |
| 193 request_id, origin_url, type)); | 193 request_id, origin_url, type)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void FileSystemDispatcher::Move( | 196 void FileSystemDispatcher::Move( |
| 197 const GURL& src_path, | 197 const GURL& src_path, |
| 198 const GURL& dest_path, | 198 const GURL& dest_path, |
| 199 const StatusCallback& callback) { | 199 const StatusCallback& callback) { |
| 200 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 200 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 201 ChildThread::current()->Send(new FileSystemHostMsg_Move( | 201 ChildThreadImpl::current()->Send(new FileSystemHostMsg_Move( |
| 202 request_id, src_path, dest_path)); | 202 request_id, src_path, dest_path)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void FileSystemDispatcher::Copy( | 205 void FileSystemDispatcher::Copy( |
| 206 const GURL& src_path, | 206 const GURL& src_path, |
| 207 const GURL& dest_path, | 207 const GURL& dest_path, |
| 208 const StatusCallback& callback) { | 208 const StatusCallback& callback) { |
| 209 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 209 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 210 ChildThread::current()->Send(new FileSystemHostMsg_Copy( | 210 ChildThreadImpl::current()->Send(new FileSystemHostMsg_Copy( |
| 211 request_id, src_path, dest_path)); | 211 request_id, src_path, dest_path)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void FileSystemDispatcher::Remove( | 214 void FileSystemDispatcher::Remove( |
| 215 const GURL& path, | 215 const GURL& path, |
| 216 bool recursive, | 216 bool recursive, |
| 217 const StatusCallback& callback) { | 217 const StatusCallback& callback) { |
| 218 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 218 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 219 ChildThread::current()->Send( | 219 ChildThreadImpl::current()->Send( |
| 220 new FileSystemHostMsg_Remove(request_id, path, recursive)); | 220 new FileSystemHostMsg_Remove(request_id, path, recursive)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void FileSystemDispatcher::ReadMetadata( | 223 void FileSystemDispatcher::ReadMetadata( |
| 224 const GURL& path, | 224 const GURL& path, |
| 225 const MetadataCallback& success_callback, | 225 const MetadataCallback& success_callback, |
| 226 const StatusCallback& error_callback) { | 226 const StatusCallback& error_callback) { |
| 227 int request_id = dispatchers_.Add( | 227 int request_id = dispatchers_.Add( |
| 228 CallbackDispatcher::Create(success_callback, error_callback)); | 228 CallbackDispatcher::Create(success_callback, error_callback)); |
| 229 ChildThread::current()->Send( | 229 ChildThreadImpl::current()->Send( |
| 230 new FileSystemHostMsg_ReadMetadata(request_id, path)); | 230 new FileSystemHostMsg_ReadMetadata(request_id, path)); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void FileSystemDispatcher::CreateFile( | 233 void FileSystemDispatcher::CreateFile( |
| 234 const GURL& path, | 234 const GURL& path, |
| 235 bool exclusive, | 235 bool exclusive, |
| 236 const StatusCallback& callback) { | 236 const StatusCallback& callback) { |
| 237 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 237 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 238 ChildThread::current()->Send(new FileSystemHostMsg_Create( | 238 ChildThreadImpl::current()->Send(new FileSystemHostMsg_Create( |
| 239 request_id, path, exclusive, | 239 request_id, path, exclusive, |
| 240 false /* is_directory */, false /* recursive */)); | 240 false /* is_directory */, false /* recursive */)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void FileSystemDispatcher::CreateDirectory( | 243 void FileSystemDispatcher::CreateDirectory( |
| 244 const GURL& path, | 244 const GURL& path, |
| 245 bool exclusive, | 245 bool exclusive, |
| 246 bool recursive, | 246 bool recursive, |
| 247 const StatusCallback& callback) { | 247 const StatusCallback& callback) { |
| 248 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 248 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 249 ChildThread::current()->Send(new FileSystemHostMsg_Create( | 249 ChildThreadImpl::current()->Send(new FileSystemHostMsg_Create( |
| 250 request_id, path, exclusive, true /* is_directory */, recursive)); | 250 request_id, path, exclusive, true /* is_directory */, recursive)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void FileSystemDispatcher::Exists( | 253 void FileSystemDispatcher::Exists( |
| 254 const GURL& path, | 254 const GURL& path, |
| 255 bool is_directory, | 255 bool is_directory, |
| 256 const StatusCallback& callback) { | 256 const StatusCallback& callback) { |
| 257 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 257 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 258 ChildThread::current()->Send( | 258 ChildThreadImpl::current()->Send( |
| 259 new FileSystemHostMsg_Exists(request_id, path, is_directory)); | 259 new FileSystemHostMsg_Exists(request_id, path, is_directory)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void FileSystemDispatcher::ReadDirectory( | 262 void FileSystemDispatcher::ReadDirectory( |
| 263 const GURL& path, | 263 const GURL& path, |
| 264 const ReadDirectoryCallback& success_callback, | 264 const ReadDirectoryCallback& success_callback, |
| 265 const StatusCallback& error_callback) { | 265 const StatusCallback& error_callback) { |
| 266 int request_id = dispatchers_.Add( | 266 int request_id = dispatchers_.Add( |
| 267 CallbackDispatcher::Create(success_callback, error_callback)); | 267 CallbackDispatcher::Create(success_callback, error_callback)); |
| 268 ChildThread::current()->Send( | 268 ChildThreadImpl::current()->Send( |
| 269 new FileSystemHostMsg_ReadDirectory(request_id, path)); | 269 new FileSystemHostMsg_ReadDirectory(request_id, path)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void FileSystemDispatcher::Truncate( | 272 void FileSystemDispatcher::Truncate( |
| 273 const GURL& path, | 273 const GURL& path, |
| 274 int64 offset, | 274 int64 offset, |
| 275 int* request_id_out, | 275 int* request_id_out, |
| 276 const StatusCallback& callback) { | 276 const StatusCallback& callback) { |
| 277 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 277 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 278 ChildThread::current()->Send( | 278 ChildThreadImpl::current()->Send( |
| 279 new FileSystemHostMsg_Truncate(request_id, path, offset)); | 279 new FileSystemHostMsg_Truncate(request_id, path, offset)); |
| 280 | 280 |
| 281 if (request_id_out) | 281 if (request_id_out) |
| 282 *request_id_out = request_id; | 282 *request_id_out = request_id; |
| 283 } | 283 } |
| 284 | 284 |
| 285 void FileSystemDispatcher::Write( | 285 void FileSystemDispatcher::Write( |
| 286 const GURL& path, | 286 const GURL& path, |
| 287 const std::string& blob_id, | 287 const std::string& blob_id, |
| 288 int64 offset, | 288 int64 offset, |
| 289 int* request_id_out, | 289 int* request_id_out, |
| 290 const WriteCallback& success_callback, | 290 const WriteCallback& success_callback, |
| 291 const StatusCallback& error_callback) { | 291 const StatusCallback& error_callback) { |
| 292 int request_id = dispatchers_.Add( | 292 int request_id = dispatchers_.Add( |
| 293 CallbackDispatcher::Create(success_callback, error_callback)); | 293 CallbackDispatcher::Create(success_callback, error_callback)); |
| 294 ChildThread::current()->Send( | 294 ChildThreadImpl::current()->Send( |
| 295 new FileSystemHostMsg_Write(request_id, path, blob_id, offset)); | 295 new FileSystemHostMsg_Write(request_id, path, blob_id, offset)); |
| 296 | 296 |
| 297 if (request_id_out) | 297 if (request_id_out) |
| 298 *request_id_out = request_id; | 298 *request_id_out = request_id; |
| 299 } | 299 } |
| 300 | 300 |
| 301 void FileSystemDispatcher::Cancel( | 301 void FileSystemDispatcher::Cancel( |
| 302 int request_id_to_cancel, | 302 int request_id_to_cancel, |
| 303 const StatusCallback& callback) { | 303 const StatusCallback& callback) { |
| 304 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 304 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 305 ChildThread::current()->Send(new FileSystemHostMsg_CancelWrite( | 305 ChildThreadImpl::current()->Send(new FileSystemHostMsg_CancelWrite( |
| 306 request_id, request_id_to_cancel)); | 306 request_id, request_id_to_cancel)); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void FileSystemDispatcher::TouchFile( | 309 void FileSystemDispatcher::TouchFile( |
| 310 const GURL& path, | 310 const GURL& path, |
| 311 const base::Time& last_access_time, | 311 const base::Time& last_access_time, |
| 312 const base::Time& last_modified_time, | 312 const base::Time& last_modified_time, |
| 313 const StatusCallback& callback) { | 313 const StatusCallback& callback) { |
| 314 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 314 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
| 315 ChildThread::current()->Send( | 315 ChildThreadImpl::current()->Send( |
| 316 new FileSystemHostMsg_TouchFile( | 316 new FileSystemHostMsg_TouchFile( |
| 317 request_id, path, last_access_time, last_modified_time)); | 317 request_id, path, last_access_time, last_modified_time)); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void FileSystemDispatcher::CreateSnapshotFile( | 320 void FileSystemDispatcher::CreateSnapshotFile( |
| 321 const GURL& file_path, | 321 const GURL& file_path, |
| 322 const CreateSnapshotFileCallback& success_callback, | 322 const CreateSnapshotFileCallback& success_callback, |
| 323 const StatusCallback& error_callback) { | 323 const StatusCallback& error_callback) { |
| 324 int request_id = dispatchers_.Add( | 324 int request_id = dispatchers_.Add( |
| 325 CallbackDispatcher::Create(success_callback, error_callback)); | 325 CallbackDispatcher::Create(success_callback, error_callback)); |
| 326 ChildThread::current()->Send( | 326 ChildThreadImpl::current()->Send( |
| 327 new FileSystemHostMsg_CreateSnapshotFile( | 327 new FileSystemHostMsg_CreateSnapshotFile( |
| 328 request_id, file_path)); | 328 request_id, file_path)); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void FileSystemDispatcher::OnDidOpenFileSystem(int request_id, | 331 void FileSystemDispatcher::OnDidOpenFileSystem(int request_id, |
| 332 const std::string& name, | 332 const std::string& name, |
| 333 const GURL& root) { | 333 const GURL& root) { |
| 334 DCHECK(root.is_valid()); | 334 DCHECK(root.is_valid()); |
| 335 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 335 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
| 336 DCHECK(dispatcher); | 336 DCHECK(dispatcher); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 void FileSystemDispatcher::OnDidWrite( | 395 void FileSystemDispatcher::OnDidWrite( |
| 396 int request_id, int64 bytes, bool complete) { | 396 int request_id, int64 bytes, bool complete) { |
| 397 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 397 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
| 398 DCHECK(dispatcher); | 398 DCHECK(dispatcher); |
| 399 dispatcher->DidWrite(bytes, complete); | 399 dispatcher->DidWrite(bytes, complete); |
| 400 if (complete) | 400 if (complete) |
| 401 dispatchers_.Remove(request_id); | 401 dispatchers_.Remove(request_id); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace content | 404 } // namespace content |
| OLD | NEW |