1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
#define CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/files/file_util_proxy.h"
#include "base/id_map.h"
#include "base/process.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_platform_file.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_types.h"
namespace base {
class FilePath;
struct PlatformFileInfo;
}
class GURL;
namespace content {
// Dispatches and sends file system related messages sent to/from a child
// process from/to the main browser process. There is one instance
// per child process. Messages are dispatched on the main child thread.
class FileSystemDispatcher : public IPC::Listener {
public:
FileSystemDispatcher();
virtual ~FileSystemDispatcher();
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
bool OpenFileSystem(const GURL& origin_url,
fileapi::FileSystemType type,
long long size,
bool create,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool DeleteFileSystem(const GURL& origin_url,
fileapi::FileSystemType type,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Move(const GURL& src_path,
const GURL& dest_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Copy(const GURL& src_path,
const GURL& dest_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Remove(const GURL& path,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool ReadMetadata(const GURL& path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Create(const GURL& path,
bool exclusive,
bool is_directory,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Exists(const GURL& path,
bool for_directory,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool ReadDirectory(const GURL& path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Truncate(const GURL& path,
int64 offset,
int* request_id_out,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Write(const GURL& path,
const GURL& blob_url,
int64 offset,
int* request_id_out,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool Cancel(int request_id_to_cancel,
fileapi::FileSystemCallbackDispatcher* dispatcher);
bool TouchFile(const GURL& file_path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
fileapi::FileSystemCallbackDispatcher* dispatcher);
// This returns a raw open PlatformFile, unlike the above, which are
// self-contained operations.
bool OpenFile(const GURL& file_path,
int file_flags, // passed to FileUtilProxy::CreateOrOpen
fileapi::FileSystemCallbackDispatcher* dispatcher);
// This must be paired with OpenFile, and called after finished using the
// raw PlatformFile returned from OpenFile.
bool NotifyCloseFile(const GURL& file_path);
bool CreateSnapshotFile(const GURL& blod_url,
const GURL& file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
private:
// Message handlers.
void OnDidOpenFileSystem(int request_id,
const std::string& name,
const GURL& root);
void OnDidSucceed(int request_id);
void OnDidReadMetadata(int request_id,
const base::PlatformFileInfo& file_info,
const base::FilePath& platform_path);
void OnDidReadDirectory(
int request_id,
const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more);
void OnDidFail(int request_id, base::PlatformFileError error_code);
void OnDidWrite(int request_id, int64 bytes, bool complete);
void OnDidOpenFile(
int request_id,
IPC::PlatformFileForTransit file);
IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_;
DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher);
};
} // namespace content
#endif // CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
|