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_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
6 #define CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
11 #include "base/basictypes.h"
12 #include "base/files/file_util_proxy.h"
13 #include "base/id_map.h"
14 #include "base/process.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "webkit/fileapi/file_system_callback_dispatcher.h"
18 #include "webkit/fileapi/file_system_types.h"
19 #include "webkit/quota/quota_types.h"
23 struct PlatformFileInfo
;
30 // Dispatches and sends file system related messages sent to/from a child
31 // process from/to the main browser process. There is one instance
32 // per child process. Messages are dispatched on the main child thread.
33 class FileSystemDispatcher
: public IPC::Listener
{
35 FileSystemDispatcher();
36 virtual ~FileSystemDispatcher();
38 // IPC::Listener implementation.
39 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
41 bool OpenFileSystem(const GURL
& origin_url
,
42 fileapi::FileSystemType type
,
45 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
46 bool DeleteFileSystem(const GURL
& origin_url
,
47 fileapi::FileSystemType type
,
48 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
49 bool Move(const GURL
& src_path
,
50 const GURL
& dest_path
,
51 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
52 bool Copy(const GURL
& src_path
,
53 const GURL
& dest_path
,
54 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
55 bool Remove(const GURL
& path
,
57 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
58 bool ReadMetadata(const GURL
& path
,
59 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
60 bool Create(const GURL
& path
,
64 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
65 bool Exists(const GURL
& path
,
67 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
68 bool ReadDirectory(const GURL
& path
,
69 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
70 bool Truncate(const GURL
& path
,
73 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
74 bool Write(const GURL
& path
,
78 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
79 bool Cancel(int request_id_to_cancel
,
80 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
81 bool TouchFile(const GURL
& file_path
,
82 const base::Time
& last_access_time
,
83 const base::Time
& last_modified_time
,
84 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
86 // This returns a raw open PlatformFile, unlike the above, which are
87 // self-contained operations.
88 bool OpenFile(const GURL
& file_path
,
89 int file_flags
, // passed to FileUtilProxy::CreateOrOpen
90 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
91 // This must be paired with OpenFile, and called after finished using the
92 // raw PlatformFile returned from OpenFile.
93 bool NotifyCloseFile(const GURL
& file_path
);
95 bool CreateSnapshotFile(const GURL
& file_path
,
96 fileapi::FileSystemCallbackDispatcher
* dispatcher
);
100 void OnDidOpenFileSystem(int request_id
,
101 const std::string
& name
,
103 void OnDidSucceed(int request_id
);
104 void OnDidReadMetadata(int request_id
,
105 const base::PlatformFileInfo
& file_info
,
106 const base::FilePath
& platform_path
);
107 void OnDidCreateSnapshotFile(int request_id
,
108 const base::PlatformFileInfo
& file_info
,
109 const base::FilePath
& platform_path
);
110 void OnDidReadDirectory(
112 const std::vector
<base::FileUtilProxy::Entry
>& entries
,
114 void OnDidFail(int request_id
, base::PlatformFileError error_code
);
115 void OnDidWrite(int request_id
, int64 bytes
, bool complete
);
118 IPC::PlatformFileForTransit file
,
119 quota::QuotaLimitType quota_policy
);
121 IDMap
<fileapi::FileSystemCallbackDispatcher
, IDMapOwnPointer
> dispatchers_
;
123 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher
);
126 } // namespace content
128 #endif // CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_