| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ | |
| 6 #define CONTENT_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/file_util_proxy.h" | |
| 13 #include "base/id_map.h" | |
| 14 #include "base/process.h" | |
| 15 #include "ipc/ipc_channel.h" | |
| 16 #include "ipc/ipc_message.h" | |
| 17 #include "ipc/ipc_platform_file.h" | |
| 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 19 #include "webkit/fileapi/file_system_types.h" | |
| 20 | |
| 21 namespace base { | |
| 22 struct PlatformFileInfo; | |
| 23 } | |
| 24 | |
| 25 class FilePath; | |
| 26 class GURL; | |
| 27 | |
| 28 // Dispatches and sends file system related messages sent to/from a child | |
| 29 // process from/to the main browser process. There is one instance | |
| 30 // per child process. Messages are dispatched on the main child thread. | |
| 31 class FileSystemDispatcher : public IPC::Channel::Listener { | |
| 32 public: | |
| 33 FileSystemDispatcher(); | |
| 34 virtual ~FileSystemDispatcher(); | |
| 35 | |
| 36 // IPC::Channel::Listener implementation. | |
| 37 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
| 38 | |
| 39 bool OpenFileSystem(const GURL& origin_url, | |
| 40 fileapi::FileSystemType type, | |
| 41 long long size, | |
| 42 bool create, | |
| 43 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 44 bool Move(const GURL& src_path, | |
| 45 const GURL& dest_path, | |
| 46 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 47 bool Copy(const GURL& src_path, | |
| 48 const GURL& dest_path, | |
| 49 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 50 bool Remove(const GURL& path, | |
| 51 bool recursive, | |
| 52 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 53 bool ReadMetadata(const GURL& path, | |
| 54 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 55 bool Create(const GURL& path, | |
| 56 bool exclusive, | |
| 57 bool is_directory, | |
| 58 bool recursive, | |
| 59 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 60 bool Exists(const GURL& path, | |
| 61 bool for_directory, | |
| 62 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 63 bool ReadDirectory(const GURL& path, | |
| 64 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 65 bool Truncate(const GURL& path, | |
| 66 int64 offset, | |
| 67 int* request_id_out, | |
| 68 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 69 bool Write(const GURL& path, | |
| 70 const GURL& blob_url, | |
| 71 int64 offset, | |
| 72 int* request_id_out, | |
| 73 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 74 bool Cancel(int request_id_to_cancel, | |
| 75 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 76 bool TouchFile(const GURL& file_path, | |
| 77 const base::Time& last_access_time, | |
| 78 const base::Time& last_modified_time, | |
| 79 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 80 | |
| 81 // This returns a raw open PlatformFile, unlike the above, which are | |
| 82 // self-contained operations. | |
| 83 bool OpenFile(const GURL& file_path, | |
| 84 int file_flags, // passed to FileUtilProxy::CreateOrOpen | |
| 85 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 86 | |
| 87 bool CreateSnapshotFile(const GURL& blod_url, | |
| 88 const GURL& file_path, | |
| 89 fileapi::FileSystemCallbackDispatcher* dispatcher); | |
| 90 private: | |
| 91 // Message handlers. | |
| 92 void OnDidOpenFileSystem(int request_id, | |
| 93 const std::string& name, | |
| 94 const GURL& root); | |
| 95 void OnDidSucceed(int request_id); | |
| 96 void OnDidReadMetadata(int request_id, | |
| 97 const base::PlatformFileInfo& file_info, | |
| 98 const FilePath& platform_path); | |
| 99 void OnDidReadDirectory( | |
| 100 int request_id, | |
| 101 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 102 bool has_more); | |
| 103 void OnDidFail(int request_id, base::PlatformFileError error_code); | |
| 104 void OnDidWrite(int request_id, int64 bytes, bool complete); | |
| 105 void OnDidOpenFile( | |
| 106 int request_id, | |
| 107 IPC::PlatformFileForTransit file); | |
| 108 | |
| 109 IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher); | |
| 112 }; | |
| 113 | |
| 114 #endif // CONTENT_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ | |
| OLD | NEW |