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/file_util.h" | 8 #include "base/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.h" |
12 #include "content/common/fileapi/file_system_messages.h" | 12 #include "content/common/fileapi/file_system_messages.h" |
13 #include "webkit/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; |
22 typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback; | 22 typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback; |
23 typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback; | 23 typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 metadata_callback_.Run(file_info); | 89 metadata_callback_.Run(file_info); |
90 } | 90 } |
91 | 91 |
92 void DidCreateSnapshotFile( | 92 void DidCreateSnapshotFile( |
93 const base::File::Info& file_info, | 93 const base::File::Info& file_info, |
94 const base::FilePath& platform_path, | 94 const base::FilePath& platform_path, |
95 int request_id) { | 95 int request_id) { |
96 snapshot_callback_.Run(file_info, platform_path, request_id); | 96 snapshot_callback_.Run(file_info, platform_path, request_id); |
97 } | 97 } |
98 | 98 |
99 void DidReadDirectory( | 99 void DidReadDirectory(const std::vector<storage::DirectoryEntry>& entries, |
100 const std::vector<fileapi::DirectoryEntry>& entries, | 100 bool has_more) { |
101 bool has_more) { | |
102 directory_callback_.Run(entries, has_more); | 101 directory_callback_.Run(entries, has_more); |
103 } | 102 } |
104 | 103 |
105 void DidOpenFileSystem(const std::string& name, | 104 void DidOpenFileSystem(const std::string& name, |
106 const GURL& root) { | 105 const GURL& root) { |
107 filesystem_callback_.Run(name, root); | 106 filesystem_callback_.Run(name, root); |
108 } | 107 } |
109 | 108 |
110 void DidResolveURL(const fileapi::FileSystemInfo& info, | 109 void DidResolveURL(const storage::FileSystemInfo& info, |
111 const base::FilePath& file_path, | 110 const base::FilePath& file_path, |
112 bool is_directory) { | 111 bool is_directory) { |
113 resolve_callback_.Run(info, file_path, is_directory); | 112 resolve_callback_.Run(info, file_path, is_directory); |
114 } | 113 } |
115 | 114 |
116 void DidWrite(int64 bytes, bool complete) { | 115 void DidWrite(int64 bytes, bool complete) { |
117 write_callback_.Run(bytes, complete); | 116 write_callback_.Run(bytes, complete); |
118 } | 117 } |
119 | 118 |
120 private: | 119 private: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 OnDidCreateSnapshotFile) | 159 OnDidCreateSnapshotFile) |
161 IPC_MESSAGE_HANDLER(FileSystemMsg_DidFail, OnDidFail) | 160 IPC_MESSAGE_HANDLER(FileSystemMsg_DidFail, OnDidFail) |
162 IPC_MESSAGE_HANDLER(FileSystemMsg_DidWrite, OnDidWrite) | 161 IPC_MESSAGE_HANDLER(FileSystemMsg_DidWrite, OnDidWrite) |
163 IPC_MESSAGE_UNHANDLED(handled = false) | 162 IPC_MESSAGE_UNHANDLED(handled = false) |
164 IPC_END_MESSAGE_MAP() | 163 IPC_END_MESSAGE_MAP() |
165 return handled; | 164 return handled; |
166 } | 165 } |
167 | 166 |
168 void FileSystemDispatcher::OpenFileSystem( | 167 void FileSystemDispatcher::OpenFileSystem( |
169 const GURL& origin_url, | 168 const GURL& origin_url, |
170 fileapi::FileSystemType type, | 169 storage::FileSystemType type, |
171 const OpenFileSystemCallback& success_callback, | 170 const OpenFileSystemCallback& success_callback, |
172 const StatusCallback& error_callback) { | 171 const StatusCallback& error_callback) { |
173 int request_id = dispatchers_.Add( | 172 int request_id = dispatchers_.Add( |
174 CallbackDispatcher::Create(success_callback, error_callback)); | 173 CallbackDispatcher::Create(success_callback, error_callback)); |
175 ChildThread::current()->Send(new FileSystemHostMsg_OpenFileSystem( | 174 ChildThread::current()->Send(new FileSystemHostMsg_OpenFileSystem( |
176 request_id, origin_url, type)); | 175 request_id, origin_url, type)); |
177 } | 176 } |
178 | 177 |
179 void FileSystemDispatcher::ResolveURL( | 178 void FileSystemDispatcher::ResolveURL( |
180 const GURL& filesystem_url, | 179 const GURL& filesystem_url, |
181 const ResolveURLCallback& success_callback, | 180 const ResolveURLCallback& success_callback, |
182 const StatusCallback& error_callback) { | 181 const StatusCallback& error_callback) { |
183 int request_id = dispatchers_.Add( | 182 int request_id = dispatchers_.Add( |
184 CallbackDispatcher::Create(success_callback, error_callback)); | 183 CallbackDispatcher::Create(success_callback, error_callback)); |
185 ChildThread::current()->Send(new FileSystemHostMsg_ResolveURL( | 184 ChildThread::current()->Send(new FileSystemHostMsg_ResolveURL( |
186 request_id, filesystem_url)); | 185 request_id, filesystem_url)); |
187 } | 186 } |
188 | 187 |
189 void FileSystemDispatcher::DeleteFileSystem( | 188 void FileSystemDispatcher::DeleteFileSystem(const GURL& origin_url, |
190 const GURL& origin_url, | 189 storage::FileSystemType type, |
191 fileapi::FileSystemType type, | 190 const StatusCallback& callback) { |
192 const StatusCallback& callback) { | |
193 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 191 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
194 ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem( | 192 ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem( |
195 request_id, origin_url, type)); | 193 request_id, origin_url, type)); |
196 } | 194 } |
197 | 195 |
198 void FileSystemDispatcher::Move( | 196 void FileSystemDispatcher::Move( |
199 const GURL& src_path, | 197 const GURL& src_path, |
200 const GURL& dest_path, | 198 const GURL& dest_path, |
201 const StatusCallback& callback) { | 199 const StatusCallback& callback) { |
202 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); | 200 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 const std::string& name, | 332 const std::string& name, |
335 const GURL& root) { | 333 const GURL& root) { |
336 DCHECK(root.is_valid()); | 334 DCHECK(root.is_valid()); |
337 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 335 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
338 DCHECK(dispatcher); | 336 DCHECK(dispatcher); |
339 dispatcher->DidOpenFileSystem(name, root); | 337 dispatcher->DidOpenFileSystem(name, root); |
340 dispatchers_.Remove(request_id); | 338 dispatchers_.Remove(request_id); |
341 } | 339 } |
342 | 340 |
343 void FileSystemDispatcher::OnDidResolveURL(int request_id, | 341 void FileSystemDispatcher::OnDidResolveURL(int request_id, |
344 const fileapi::FileSystemInfo& info, | 342 const storage::FileSystemInfo& info, |
345 const base::FilePath& file_path, | 343 const base::FilePath& file_path, |
346 bool is_directory) { | 344 bool is_directory) { |
347 DCHECK(info.root_url.is_valid()); | 345 DCHECK(info.root_url.is_valid()); |
348 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 346 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
349 DCHECK(dispatcher); | 347 DCHECK(dispatcher); |
350 dispatcher->DidResolveURL(info, file_path, is_directory); | 348 dispatcher->DidResolveURL(info, file_path, is_directory); |
351 dispatchers_.Remove(request_id); | 349 dispatchers_.Remove(request_id); |
352 } | 350 } |
353 | 351 |
354 void FileSystemDispatcher::OnDidSucceed(int request_id) { | 352 void FileSystemDispatcher::OnDidSucceed(int request_id) { |
(...skipping 15 matching lines...) Expand all Loading... |
370 int request_id, const base::File::Info& file_info, | 368 int request_id, const base::File::Info& file_info, |
371 const base::FilePath& platform_path) { | 369 const base::FilePath& platform_path) { |
372 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 370 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
373 DCHECK(dispatcher); | 371 DCHECK(dispatcher); |
374 dispatcher->DidCreateSnapshotFile(file_info, platform_path, request_id); | 372 dispatcher->DidCreateSnapshotFile(file_info, platform_path, request_id); |
375 dispatchers_.Remove(request_id); | 373 dispatchers_.Remove(request_id); |
376 } | 374 } |
377 | 375 |
378 void FileSystemDispatcher::OnDidReadDirectory( | 376 void FileSystemDispatcher::OnDidReadDirectory( |
379 int request_id, | 377 int request_id, |
380 const std::vector<fileapi::DirectoryEntry>& entries, | 378 const std::vector<storage::DirectoryEntry>& entries, |
381 bool has_more) { | 379 bool has_more) { |
382 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 380 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
383 DCHECK(dispatcher); | 381 DCHECK(dispatcher); |
384 dispatcher->DidReadDirectory(entries, has_more); | 382 dispatcher->DidReadDirectory(entries, has_more); |
385 if (!has_more) | 383 if (!has_more) |
386 dispatchers_.Remove(request_id); | 384 dispatchers_.Remove(request_id); |
387 } | 385 } |
388 | 386 |
389 void FileSystemDispatcher::OnDidFail( | 387 void FileSystemDispatcher::OnDidFail( |
390 int request_id, base::File::Error error_code) { | 388 int request_id, base::File::Error error_code) { |
391 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 389 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
392 DCHECK(dispatcher); | 390 DCHECK(dispatcher); |
393 dispatcher->DidFail(error_code); | 391 dispatcher->DidFail(error_code); |
394 dispatchers_.Remove(request_id); | 392 dispatchers_.Remove(request_id); |
395 } | 393 } |
396 | 394 |
397 void FileSystemDispatcher::OnDidWrite( | 395 void FileSystemDispatcher::OnDidWrite( |
398 int request_id, int64 bytes, bool complete) { | 396 int request_id, int64 bytes, bool complete) { |
399 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 397 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
400 DCHECK(dispatcher); | 398 DCHECK(dispatcher); |
401 dispatcher->DidWrite(bytes, complete); | 399 dispatcher->DidWrite(bytes, complete); |
402 if (complete) | 400 if (complete) |
403 dispatchers_.Remove(request_id); | 401 dispatchers_.Remove(request_id); |
404 } | 402 } |
405 | 403 |
406 } // namespace content | 404 } // namespace content |
OLD | NEW |