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"
25 struct DirectoryEntry
;
26 struct FileSystemInfo
;
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::File::Error error
)> StatusCallback
;
39 typedef base::Callback
<void(
40 const base::File::Info
& file_info
)> MetadataCallback
;
41 typedef base::Callback
<void(
42 const base::File::Info
& 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(
52 const fileapi::FileSystemInfo
& info
,
53 const base::FilePath
& file_path
,
54 bool is_directory
)> ResolveURLCallback
;
55 typedef base::Callback
<void(
57 bool complete
)> WriteCallback
;
58 typedef base::Callback
<void(
59 base::PlatformFile file
,
61 quota::QuotaLimitType quota_policy
)> OpenFileCallback
;
63 FileSystemDispatcher();
64 virtual ~FileSystemDispatcher();
66 // IPC::Listener implementation.
67 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
69 void OpenFileSystem(const GURL
& origin_url
,
70 fileapi::FileSystemType type
,
71 const OpenFileSystemCallback
& success_callback
,
72 const StatusCallback
& error_callback
);
73 void ResolveURL(const GURL
& filesystem_url
,
74 const ResolveURLCallback
& success_callback
,
75 const StatusCallback
& error_callback
);
76 void DeleteFileSystem(const GURL
& origin_url
,
77 fileapi::FileSystemType type
,
78 const StatusCallback
& callback
);
79 void Move(const GURL
& src_path
,
80 const GURL
& dest_path
,
81 const StatusCallback
& callback
);
82 void Copy(const GURL
& src_path
,
83 const GURL
& dest_path
,
84 const StatusCallback
& callback
);
85 void Remove(const GURL
& path
,
87 const StatusCallback
& callback
);
88 void ReadMetadata(const GURL
& path
,
89 const MetadataCallback
& success_callback
,
90 const StatusCallback
& error_callback
);
91 void CreateFile(const GURL
& path
,
93 const StatusCallback
& callback
);
94 void CreateDirectory(const GURL
& path
,
97 const StatusCallback
& callback
);
98 void Exists(const GURL
& path
,
100 const StatusCallback
& callback
);
101 void ReadDirectory(const GURL
& path
,
102 const ReadDirectoryCallback
& success_callback
,
103 const StatusCallback
& error_callback
);
104 void Truncate(const GURL
& path
,
107 const StatusCallback
& callback
);
108 void Write(const GURL
& path
,
109 const std::string
& blob_id
,
112 const WriteCallback
& success_callback
,
113 const StatusCallback
& error_callback
);
114 void Cancel(int request_id_to_cancel
,
115 const StatusCallback
& callback
);
116 void TouchFile(const GURL
& file_path
,
117 const base::Time
& last_access_time
,
118 const base::Time
& last_modified_time
,
119 const StatusCallback
& callback
);
121 // The caller must send FileSystemHostMsg_DidReceiveSnapshot message
122 // with |request_id| passed to |success_callback| after the snapshot file
123 // is successfully received.
124 void CreateSnapshotFile(const GURL
& file_path
,
125 const CreateSnapshotFileCallback
& success_callback
,
126 const StatusCallback
& error_callback
);
129 class CallbackDispatcher
;
132 void OnDidOpenFileSystem(int request_id
,
133 const std::string
& name
,
135 void OnDidResolveURL(int request_id
,
136 const fileapi::FileSystemInfo
& info
,
137 const base::FilePath
& file_path
,
139 void OnDidSucceed(int request_id
);
140 void OnDidReadMetadata(int request_id
,
141 const base::File::Info
& file_info
);
142 void OnDidCreateSnapshotFile(int request_id
,
143 const base::File::Info
& file_info
,
144 const base::FilePath
& platform_path
);
145 void OnDidReadDirectory(int request_id
,
146 const std::vector
<fileapi::DirectoryEntry
>& entries
,
148 void OnDidFail(int request_id
, base::File::Error error_code
);
149 void OnDidWrite(int request_id
, int64 bytes
, bool complete
);
152 IPC::PlatformFileForTransit file
,
154 quota::QuotaLimitType quota_policy
);
156 IDMap
<CallbackDispatcher
, IDMapOwnPointer
> dispatchers_
;
158 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher
);
161 } // namespace content
163 #endif // CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_