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
;
27 struct FileSystemInfo
;
34 // Dispatches and sends file system related messages sent to/from a child
35 // process from/to the main browser process. There is one instance
36 // per child process. Messages are dispatched on the main child thread.
37 class FileSystemDispatcher
: public IPC::Listener
{
39 typedef base::Callback
<void(base::PlatformFileError error
)> StatusCallback
;
40 typedef base::Callback
<void(
41 const base::PlatformFileInfo
& file_info
)> MetadataCallback
;
42 typedef base::Callback
<void(
43 const base::PlatformFileInfo
& file_info
,
44 const base::FilePath
& platform_path
,
45 int request_id
)> CreateSnapshotFileCallback
;
46 typedef base::Callback
<void(
47 const std::vector
<fileapi::DirectoryEntry
>& entries
,
48 bool has_more
)> ReadDirectoryCallback
;
49 typedef base::Callback
<void(
50 const std::string
& name
,
51 const GURL
& root
)> OpenFileSystemCallback
;
52 typedef base::Callback
<void(
53 const fileapi::FileSystemInfo
& info
,
54 const base::FilePath
& file_path
,
55 bool is_directory
)> ResolveURLCallback
;
56 typedef base::Callback
<void(
58 bool complete
)> WriteCallback
;
59 typedef base::Callback
<void(
60 base::PlatformFile file
,
62 quota::QuotaLimitType quota_policy
)> OpenFileCallback
;
64 FileSystemDispatcher();
65 virtual ~FileSystemDispatcher();
67 // IPC::Listener implementation.
68 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
70 void OpenFileSystem(const GURL
& origin_url
,
71 fileapi::FileSystemType type
,
72 const OpenFileSystemCallback
& success_callback
,
73 const StatusCallback
& error_callback
);
74 void ResolveURL(const GURL
& filesystem_url
,
75 const ResolveURLCallback
& success_callback
,
76 const StatusCallback
& error_callback
);
77 void DeleteFileSystem(const GURL
& origin_url
,
78 fileapi::FileSystemType type
,
79 const StatusCallback
& callback
);
80 void Move(const GURL
& src_path
,
81 const GURL
& dest_path
,
82 const StatusCallback
& callback
);
83 void Copy(const GURL
& src_path
,
84 const GURL
& dest_path
,
85 const StatusCallback
& callback
);
86 void Remove(const GURL
& path
,
88 const StatusCallback
& callback
);
89 void ReadMetadata(const GURL
& path
,
90 const MetadataCallback
& success_callback
,
91 const StatusCallback
& error_callback
);
92 void CreateFile(const GURL
& path
,
94 const StatusCallback
& callback
);
95 void CreateDirectory(const GURL
& path
,
98 const StatusCallback
& callback
);
99 void Exists(const GURL
& path
,
101 const StatusCallback
& callback
);
102 void ReadDirectory(const GURL
& path
,
103 const ReadDirectoryCallback
& success_callback
,
104 const StatusCallback
& error_callback
);
105 void Truncate(const GURL
& path
,
108 const StatusCallback
& callback
);
109 void Write(const GURL
& path
,
110 const std::string
& blob_id
,
113 const WriteCallback
& success_callback
,
114 const StatusCallback
& error_callback
);
115 void Cancel(int request_id_to_cancel
,
116 const StatusCallback
& callback
);
117 void TouchFile(const GURL
& file_path
,
118 const base::Time
& last_access_time
,
119 const base::Time
& last_modified_time
,
120 const StatusCallback
& callback
);
122 // The caller must send FileSystemHostMsg_DidReceiveSnapshot message
123 // with |request_id| passed to |success_callback| after the snapshot file
124 // is successfully received.
125 void CreateSnapshotFile(const GURL
& file_path
,
126 const CreateSnapshotFileCallback
& success_callback
,
127 const StatusCallback
& error_callback
);
130 class CallbackDispatcher
;
133 void OnDidOpenFileSystem(int request_id
,
134 const std::string
& name
,
136 void OnDidResolveURL(int request_id
,
137 const fileapi::FileSystemInfo
& info
,
138 const base::FilePath
& file_path
,
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_