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.
5 #ifndef CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
6 #define CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/id_map.h"
14 #include "base/process/process.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "webkit/common/fileapi/file_system_types.h"
18 #include "webkit/common/quota/quota_types.h"
22 struct PlatformFileInfo
;
26 struct DirectoryEntry
;
33 // Dispatches and sends file system related messages sent to/from a child
34 // process from/to the main browser process. There is one instance
35 // per child process. Messages are dispatched on the main child thread.
36 class FileSystemDispatcher
: public IPC::Listener
{
38 typedef base::Callback
<void(base::PlatformFileError error
)> StatusCallback
;
39 typedef base::Callback
<void(
40 const base::PlatformFileInfo
& file_info
)> MetadataCallback
;
41 typedef base::Callback
<void(
42 const base::PlatformFileInfo
& file_info
,
43 const base::FilePath
& platform_path
,
44 int request_id
)> CreateSnapshotFileCallback
;
45 typedef base::Callback
<void(
46 const std::vector
<fileapi::DirectoryEntry
>& entries
,
47 bool has_more
)> ReadDirectoryCallback
;
48 typedef base::Callback
<void(
49 const std::string
& name
,
50 const GURL
& root
)> OpenFileSystemCallback
;
51 typedef base::Callback
<void(
53 bool complete
)> WriteCallback
;
54 typedef base::Callback
<void(
55 base::PlatformFile file
,
57 quota::QuotaLimitType quota_policy
)> OpenFileCallback
;
59 FileSystemDispatcher();
60 virtual ~FileSystemDispatcher();
62 // IPC::Listener implementation.
63 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
65 void OpenFileSystem(const GURL
& origin_url
,
66 fileapi::FileSystemType type
,
69 const OpenFileSystemCallback
& success_callback
,
70 const StatusCallback
& error_callback
);
71 void DeleteFileSystem(const GURL
& origin_url
,
72 fileapi::FileSystemType type
,
73 const StatusCallback
& callback
);
74 void Move(const GURL
& src_path
,
75 const GURL
& dest_path
,
76 const StatusCallback
& callback
);
77 void Copy(const GURL
& src_path
,
78 const GURL
& dest_path
,
79 const StatusCallback
& callback
);
80 void Remove(const GURL
& path
,
82 const StatusCallback
& callback
);
83 void ReadMetadata(const GURL
& path
,
84 const MetadataCallback
& success_callback
,
85 const StatusCallback
& error_callback
);
86 void CreateFile(const GURL
& path
,
88 const StatusCallback
& callback
);
89 void CreateDirectory(const GURL
& path
,
92 const StatusCallback
& callback
);
93 void Exists(const GURL
& path
,
95 const StatusCallback
& callback
);
96 void ReadDirectory(const GURL
& path
,
97 const ReadDirectoryCallback
& success_callback
,
98 const StatusCallback
& error_callback
);
99 void Truncate(const GURL
& path
,
102 const StatusCallback
& callback
);
103 void Write(const GURL
& path
,
104 const GURL
& blob_url
,
107 const WriteCallback
& success_callback
,
108 const StatusCallback
& error_callback
);
109 void Cancel(int request_id_to_cancel
,
110 const StatusCallback
& callback
);
111 void TouchFile(const GURL
& file_path
,
112 const base::Time
& last_access_time
,
113 const base::Time
& last_modified_time
,
114 const StatusCallback
& callback
);
116 // This returns a raw open PlatformFile, unlike the above, which are
117 // self-contained operations.
118 void OpenFile(const GURL
& file_path
,
119 int file_flags
, // passed to FileUtilProxy::CreateOrOpen
120 const OpenFileCallback
& success_callback
,
121 const StatusCallback
& error_callback
);
122 // This must be paired with OpenFile, and called after finished using the
123 // raw PlatformFile returned from OpenFile.
124 void NotifyCloseFile(int file_open_id
);
126 // The caller must send FileSystemHostMsg_DidReceiveSnapshot message
127 // with |request_id| passed to |success_callback| after the snapshot file
128 // is successfully received.
129 void CreateSnapshotFile(const GURL
& file_path
,
130 const CreateSnapshotFileCallback
& success_callback
,
131 const StatusCallback
& error_callback
);
134 class CallbackDispatcher
;
137 void OnDidOpenFileSystem(int request_id
,
138 const std::string
& name
,
140 void OnDidSucceed(int request_id
);
141 void OnDidReadMetadata(int request_id
,
142 const base::PlatformFileInfo
& file_info
);
143 void OnDidCreateSnapshotFile(int request_id
,
144 const base::PlatformFileInfo
& file_info
,
145 const base::FilePath
& platform_path
);
146 void OnDidReadDirectory(int request_id
,
147 const std::vector
<fileapi::DirectoryEntry
>& entries
,
149 void OnDidFail(int request_id
, base::PlatformFileError error_code
);
150 void OnDidWrite(int request_id
, int64 bytes
, bool complete
);
153 IPC::PlatformFileForTransit file
,
155 quota::QuotaLimitType quota_policy
);
157 IDMap
<CallbackDispatcher
, IDMapOwnPointer
> dispatchers_
;
159 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher
);
162 } // namespace content
164 #endif // CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_