file_manager: Remove fileBrowserPrivate.viewFiles()
[chromium-blink-merge.git] / content / child / fileapi / file_system_dispatcher.h
blobe0260fda17e2274f9e30bf3c457f4b81c5e76e8c
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_
8 #include <string>
9 #include <vector>
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"
20 namespace base {
21 class FilePath;
22 struct PlatformFileInfo;
25 namespace fileapi {
26 struct DirectoryEntry;
29 class GURL;
31 namespace content {
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 {
37 public:
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(
52 int64 bytes,
53 bool complete)> WriteCallback;
54 typedef base::Callback<void(
55 base::PlatformFile file,
56 int file_open_id,
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,
67 long long size,
68 bool create,
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,
81 bool recursive,
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,
87 bool exclusive,
88 const StatusCallback& callback);
89 void CreateDirectory(const GURL& path,
90 bool exclusive,
91 bool recursive,
92 const StatusCallback& callback);
93 void Exists(const GURL& path,
94 bool for_directory,
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,
100 int64 offset,
101 int* request_id_out,
102 const StatusCallback& callback);
103 void Write(const GURL& path,
104 const GURL& blob_url,
105 int64 offset,
106 int* request_id_out,
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);
133 private:
134 class CallbackDispatcher;
136 // Message handlers.
137 void OnDidOpenFileSystem(int request_id,
138 const std::string& name,
139 const GURL& root);
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,
148 bool has_more);
149 void OnDidFail(int request_id, base::PlatformFileError error_code);
150 void OnDidWrite(int request_id, int64 bytes, bool complete);
151 void OnDidOpenFile(
152 int request_id,
153 IPC::PlatformFileForTransit file,
154 int file_open_id,
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_