| 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/common/file_system/file_system_dispatcher.h" | 5 #include "chrome/common/file_system/file_system_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "chrome/common/child_thread.h" | 8 #include "chrome/common/child_thread.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/render_messages_params.h" | 10 #include "chrome/common/render_messages_params.h" |
| 11 #include "webkit/glue/webkit_glue.h" | |
| 12 | 11 |
| 13 FileSystemDispatcher::FileSystemDispatcher() { | 12 FileSystemDispatcher::FileSystemDispatcher() { |
| 14 } | 13 } |
| 15 | 14 |
| 16 FileSystemDispatcher::~FileSystemDispatcher() { | 15 FileSystemDispatcher::~FileSystemDispatcher() { |
| 17 // Make sure we fire all the remaining callbacks. | 16 // Make sure we fire all the remaining callbacks. |
| 18 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator | 17 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator |
| 19 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { | 18 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { |
| 20 int request_id = iter.GetCurrentKey(); | 19 int request_id = iter.GetCurrentKey(); |
| 21 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); | 20 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); |
| 22 DCHECK(dispatcher); | 21 DCHECK(dispatcher); |
| 23 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 22 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); |
| 24 dispatchers_.Remove(request_id); | 23 dispatchers_.Remove(request_id); |
| 25 } | 24 } |
| 26 } | 25 } |
| 27 | 26 |
| 28 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { | 27 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 29 bool handled = true; | 28 bool handled = true; |
| 30 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) | 29 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) |
| 30 IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, |
| 31 OnOpenFileSystemRequestComplete) |
| 31 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) | 32 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) |
| 32 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) | 33 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) |
| 33 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) | 34 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) |
| 34 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidFail, DidFail) | 35 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidFail, DidFail) |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 36 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() | 37 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 38 return handled; |
| 38 } | 39 } |
| 39 | 40 |
| 41 void FileSystemDispatcher::OpenFileSystem( |
| 42 const GURL& origin_url, fileapi::FileSystemType type, |
| 43 long long size, fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 44 int request_id = dispatchers_.Add(dispatcher); |
| 45 ChildThread::current()->Send(new ViewHostMsg_OpenFileSystemRequest( |
| 46 request_id, origin_url, type, size)); |
| 47 } |
| 48 |
| 40 bool FileSystemDispatcher::Move( | 49 bool FileSystemDispatcher::Move( |
| 41 const FilePath& src_path, | 50 const FilePath& src_path, |
| 42 const FilePath& dest_path, | 51 const FilePath& dest_path, |
| 43 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 52 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 44 int request_id = dispatchers_.Add(dispatcher); | 53 int request_id = dispatchers_.Add(dispatcher); |
| 45 return ChildThread::current()->Send(new ViewHostMsg_FileSystem_Move( | 54 return ChildThread::current()->Send(new ViewHostMsg_FileSystem_Move( |
| 46 request_id, src_path, dest_path)); | 55 request_id, src_path, dest_path)); |
| 47 } | 56 } |
| 48 | 57 |
| 49 bool FileSystemDispatcher::Copy( | 58 bool FileSystemDispatcher::Copy( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 101 } |
| 93 | 102 |
| 94 bool FileSystemDispatcher::ReadDirectory( | 103 bool FileSystemDispatcher::ReadDirectory( |
| 95 const FilePath& path, | 104 const FilePath& path, |
| 96 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 105 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
| 97 int request_id = dispatchers_.Add(dispatcher); | 106 int request_id = dispatchers_.Add(dispatcher); |
| 98 return ChildThread::current()->Send( | 107 return ChildThread::current()->Send( |
| 99 new ViewHostMsg_FileSystem_ReadDirectory(request_id, path)); | 108 new ViewHostMsg_FileSystem_ReadDirectory(request_id, path)); |
| 100 } | 109 } |
| 101 | 110 |
| 111 void FileSystemDispatcher::OnOpenFileSystemRequestComplete( |
| 112 int request_id, bool accepted, const std::string& name, |
| 113 const FilePath& root_path) { |
| 114 fileapi::FileSystemCallbackDispatcher* dispatcher = |
| 115 dispatchers_.Lookup(request_id); |
| 116 DCHECK(dispatcher); |
| 117 if (accepted) |
| 118 dispatcher->DidOpenFileSystem(name, root_path); |
| 119 else |
| 120 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 121 dispatchers_.Remove(request_id); |
| 122 } |
| 123 |
| 102 void FileSystemDispatcher::DidSucceed(int request_id) { | 124 void FileSystemDispatcher::DidSucceed(int request_id) { |
| 103 fileapi::FileSystemCallbackDispatcher* dispatcher = | 125 fileapi::FileSystemCallbackDispatcher* dispatcher = |
| 104 dispatchers_.Lookup(request_id); | 126 dispatchers_.Lookup(request_id); |
| 105 DCHECK(dispatcher); | 127 DCHECK(dispatcher); |
| 106 dispatcher->DidSucceed(); | 128 dispatcher->DidSucceed(); |
| 107 dispatchers_.Remove(request_id); | 129 dispatchers_.Remove(request_id); |
| 108 } | 130 } |
| 109 | 131 |
| 110 void FileSystemDispatcher::DidReadMetadata( | 132 void FileSystemDispatcher::DidReadMetadata( |
| 111 int request_id, const base::PlatformFileInfo& file_info) { | 133 int request_id, const base::PlatformFileInfo& file_info) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 } | 150 } |
| 129 | 151 |
| 130 void FileSystemDispatcher::DidFail( | 152 void FileSystemDispatcher::DidFail( |
| 131 int request_id, base::PlatformFileError error_code) { | 153 int request_id, base::PlatformFileError error_code) { |
| 132 fileapi::FileSystemCallbackDispatcher* dispatcher = | 154 fileapi::FileSystemCallbackDispatcher* dispatcher = |
| 133 dispatchers_.Lookup(request_id); | 155 dispatchers_.Lookup(request_id); |
| 134 DCHECK(dispatcher); | 156 DCHECK(dispatcher); |
| 135 dispatcher->DidFail(error_code); | 157 dispatcher->DidFail(error_code); |
| 136 dispatchers_.Remove(request_id); | 158 dispatchers_.Remove(request_id); |
| 137 } | 159 } |
| OLD | NEW |