| 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 "chrome/common/child_thread.h" | 8 #include "chrome/common/child_thread.h" |
| 8 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/render_messages_params.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
| 10 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
| 11 | 16 |
| 12 using WebKit::WebFileError; | 17 using WebKit::WebFileError; |
| 13 using WebKit::WebFileInfo; | 18 using WebKit::WebFileInfo; |
| 14 using WebKit::WebFileSystemCallbacks; | 19 using WebKit::WebFileSystemCallbacks; |
| 20 using WebKit::WebFileSystemEntry; |
| 21 using WebKit::WebVector; |
| 15 | 22 |
| 16 FileSystemDispatcher::FileSystemDispatcher() { | 23 FileSystemDispatcher::FileSystemDispatcher() { |
| 17 } | 24 } |
| 18 | 25 |
| 19 FileSystemDispatcher::~FileSystemDispatcher() { | 26 FileSystemDispatcher::~FileSystemDispatcher() { |
| 20 // Make sure we fire all the remaining callbacks. | 27 // Make sure we fire all the remaining callbacks. |
| 21 for (IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); | 28 for (IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); |
| 22 !iter.IsAtEnd(); | 29 !iter.IsAtEnd(); |
| 23 iter.Advance()) { | 30 iter.Advance()) { |
| 24 int callbacks_id = iter.GetCurrentKey(); | 31 int callbacks_id = iter.GetCurrentKey(); |
| 25 WebFileSystemCallbacks* callbacks = iter.GetCurrentValue(); | 32 WebFileSystemCallbacks* callbacks = iter.GetCurrentValue(); |
| 26 DCHECK(callbacks); | 33 DCHECK(callbacks); |
| 27 callbacks_.Remove(callbacks_id); | 34 callbacks_.Remove(callbacks_id); |
| 28 callbacks->didFail(WebKit::WebFileErrorAbort); | 35 callbacks->didFail(WebKit::WebFileErrorAbort); |
| 29 } | 36 } |
| 30 } | 37 } |
| 31 | 38 |
| 32 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { | 39 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 33 bool handled = true; | 40 bool handled = true; |
| 34 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) | 41 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) |
| 35 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_Succeeded, DidSucceed) | 42 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) |
| 36 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_Failed, DidFail) | 43 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) |
| 44 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) |
| 45 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidFail, DidFail) |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | 46 IPC_MESSAGE_UNHANDLED(handled = false) |
| 38 IPC_END_MESSAGE_MAP() | 47 IPC_END_MESSAGE_MAP() |
| 39 return handled; | 48 return handled; |
| 40 } | 49 } |
| 41 | 50 |
| 42 void FileSystemDispatcher::Move( | 51 void FileSystemDispatcher::Move( |
| 43 const string16& src_path, const string16& dest_path, | 52 const string16& src_path, const string16& dest_path, |
| 44 WebFileSystemCallbacks* callbacks) { | 53 WebFileSystemCallbacks* callbacks) { |
| 45 int request_id = callbacks_.Add(callbacks); | 54 int request_id = callbacks_.Add(callbacks); |
| 46 ChildThread::current()->Send( | 55 ChildThread::current()->Send( |
| 47 new ViewHostMsg_FileSystem_Move(request_id, src_path, dest_path)); | 56 new ViewHostMsg_FileSystem_Move(request_id, src_path, dest_path)); |
| 48 } | 57 } |
| 49 | 58 |
| 59 void FileSystemDispatcher::Copy( |
| 60 const string16& src_path, const string16& dest_path, |
| 61 WebFileSystemCallbacks* callbacks) { |
| 62 int request_id = callbacks_.Add(callbacks); |
| 63 ChildThread::current()->Send( |
| 64 new ViewHostMsg_FileSystem_Copy(request_id, src_path, dest_path)); |
| 65 } |
| 66 |
| 67 void FileSystemDispatcher::Remove( |
| 68 const string16& path, WebFileSystemCallbacks* callbacks) { |
| 69 int request_id = callbacks_.Add(callbacks); |
| 70 ChildThread::current()->Send( |
| 71 new ViewHostMsg_FileSystem_Remove(request_id, path)); |
| 72 } |
| 73 |
| 74 void FileSystemDispatcher::ReadMetadata( |
| 75 const string16& path, WebFileSystemCallbacks* callbacks) { |
| 76 int request_id = callbacks_.Add(callbacks); |
| 77 ChildThread::current()->Send( |
| 78 new ViewHostMsg_FileSystem_ReadMetadata(request_id, path)); |
| 79 } |
| 80 |
| 81 void FileSystemDispatcher::Create( |
| 82 const string16& path, bool exclusive, bool is_directory, |
| 83 WebFileSystemCallbacks* callbacks) { |
| 84 int request_id = callbacks_.Add(callbacks); |
| 85 ChildThread::current()->Send( |
| 86 new ViewHostMsg_FileSystem_Create(request_id, path, exclusive, |
| 87 is_directory)); |
| 88 } |
| 89 |
| 90 void FileSystemDispatcher::Exists( |
| 91 const string16& path, bool is_directory, |
| 92 WebFileSystemCallbacks* callbacks) { |
| 93 int request_id = callbacks_.Add(callbacks); |
| 94 ChildThread::current()->Send( |
| 95 new ViewHostMsg_FileSystem_Exists(request_id, path, is_directory)); |
| 96 } |
| 97 |
| 98 void FileSystemDispatcher::ReadDirectory( |
| 99 const string16& path, WebFileSystemCallbacks* callbacks) { |
| 100 int request_id = callbacks_.Add(callbacks); |
| 101 ChildThread::current()->Send( |
| 102 new ViewHostMsg_FileSystem_ReadDirectory(request_id, path)); |
| 103 } |
| 104 |
| 50 void FileSystemDispatcher::DidSucceed(int request_id) { | 105 void FileSystemDispatcher::DidSucceed(int request_id) { |
| 51 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); | 106 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); |
| 52 DCHECK(callbacks); | 107 DCHECK(callbacks); |
| 53 callbacks_.Remove(request_id); | 108 callbacks_.Remove(request_id); |
| 54 callbacks->didSucceed(); | 109 callbacks->didSucceed(); |
| 55 } | 110 } |
| 56 | 111 |
| 57 void FileSystemDispatcher::DidFail(int request_id, int code) { | 112 void FileSystemDispatcher::DidReadMetadata(int request_id, |
| 113 const file_util::FileInfo& file_info) { |
| 58 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); | 114 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); |
| 59 DCHECK(callbacks); | 115 DCHECK(callbacks); |
| 60 callbacks_.Remove(request_id); | 116 callbacks_.Remove(request_id); |
| 61 callbacks->didFail(static_cast<WebFileError>(code)); | 117 WebFileInfo web_file_info; |
| 118 web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); |
| 119 callbacks->didReadMetadata(web_file_info); |
| 62 } | 120 } |
| 121 |
| 122 void FileSystemDispatcher::DidReadDirectory( |
| 123 const ViewMsg_FileSystem_DidReadDirectory_Params& params) { |
| 124 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(params.request_id); |
| 125 DCHECK(callbacks); |
| 126 if (!params.has_more) |
| 127 callbacks_.Remove(params.request_id); |
| 128 WebVector<WebFileSystemEntry> entries(params.entries.size()); |
| 129 for (size_t i = 0; i < params.entries.size(); ++i) { |
| 130 entries[i].name = webkit_glue::FilePathToWebString(params.entries[i].name); |
| 131 entries[i].isDirectory = params.entries[i].is_directory; |
| 132 } |
| 133 callbacks->didReadDirectory(entries, params.has_more); |
| 134 } |
| 135 |
| 136 void FileSystemDispatcher::DidFail(int request_id, WebFileError code) { |
| 137 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); |
| 138 DCHECK(callbacks); |
| 139 callbacks_.Remove(request_id); |
| 140 callbacks->didFail(code); |
| 141 } |
| OLD | NEW |