OLD | NEW |
| (Empty) |
1 // Copyright 2013 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. | |
4 // | |
5 // This file provides the core implementation of fileapi methods. | |
6 // The functions should be called on UI thread. | |
7 // Note that most method invocation of fileapi is done on IO thread. The gap is | |
8 // filled by FileSystemProxy. | |
9 // Also, the order of arguments for the functions which take FileSystemInterface | |
10 // at the last is intentional. The instance of FileSystemInterface should be | |
11 // accessible only on UI thread, but arguments are passed on IO thread. | |
12 // So, here is an intended use case: | |
13 // 1) Bind arguments on IO thread. Then a callback instance whose type is | |
14 // Callback<void(FileSysstemInterface*)> is created. | |
15 // 2) Post the task to the UI thread. | |
16 // 3) On UI thread, check if the instance of FileSystemInterface is alive or | |
17 // not. If yes, Run the callback with it. | |
18 | |
19 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_ | |
20 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_ | |
21 | |
22 #include <vector> | |
23 | |
24 #include "base/basictypes.h" | |
25 #include "base/callback_forward.h" | |
26 #include "base/memory/weak_ptr.h" | |
27 #include "base/platform_file.h" | |
28 #include "chrome/browser/chromeos/drive/file_errors.h" | |
29 #include "webkit/common/blob/scoped_file.h" | |
30 | |
31 namespace base { | |
32 class FilePath; | |
33 } // namespace base | |
34 | |
35 namespace fileapi { | |
36 struct DirectoryEntry; | |
37 } // namespace fileapi | |
38 | |
39 namespace drive { | |
40 | |
41 class FileSystemInterface; | |
42 | |
43 namespace fileapi_internal { | |
44 | |
45 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; | |
46 | |
47 typedef base::Callback< | |
48 void(base::File::Error result)> StatusCallback; | |
49 typedef base::Callback< | |
50 void(base::File::Error result, | |
51 const base::File::Info& file_info)> GetFileInfoCallback; | |
52 typedef base::Callback< | |
53 void(base::File::Error result, | |
54 const std::vector<fileapi::DirectoryEntry>& file_list, | |
55 bool has_more)> ReadDirectoryCallback; | |
56 typedef base::Callback< | |
57 void(base::File::Error result, | |
58 const base::File::Info& file_info, | |
59 const base::FilePath& snapshot_file_path, | |
60 webkit_blob::ScopedFile::ScopeOutPolicy scope_out_policy)> | |
61 CreateSnapshotFileCallback; | |
62 typedef base::Callback< | |
63 void(base::File::Error result, | |
64 const base::FilePath& snapshot_file_path, | |
65 const base::Closure& close_callback)> | |
66 CreateWritableSnapshotFileCallback; | |
67 typedef base::Callback< | |
68 void(base::File::Error result, | |
69 base::PlatformFile platform_file, | |
70 const base::Closure& close_callback)> OpenFileCallback; | |
71 | |
72 // Runs |file_system_getter| to obtain the instance of FileSystemInstance, | |
73 // and then runs |callback| with it. | |
74 // If |file_system_getter| returns NULL, runs |error_callback| instead. | |
75 // This function must be called on UI thread. | |
76 // |file_system_getter| and |callback| must not be null, but | |
77 // |error_callback| can be null (if no operation is necessary for error | |
78 // case). | |
79 void RunFileSystemCallback( | |
80 const FileSystemGetter& file_system_getter, | |
81 const base::Callback<void(FileSystemInterface*)>& callback, | |
82 const base::Closure& error_callback); | |
83 | |
84 // Returns the metadata info of the file at |file_path|. | |
85 // Called from FileSystemProxy::GetFileInfo(). | |
86 void GetFileInfo(const base::FilePath& file_path, | |
87 const GetFileInfoCallback& callback, | |
88 FileSystemInterface* file_system); | |
89 | |
90 // Copies a file from |src_file_path| to |dest_file_path|. | |
91 // Called from FileSystemProxy::Copy(). | |
92 void Copy(const base::FilePath& src_file_path, | |
93 const base::FilePath& dest_file_path, | |
94 bool preserve_last_modified, | |
95 const StatusCallback& callback, | |
96 FileSystemInterface* file_system); | |
97 | |
98 // Moves a file from |src_file_path| to |dest_file_path|. | |
99 // Called from FileSystemProxy::Move(). | |
100 void Move(const base::FilePath& src_file_path, | |
101 const base::FilePath& dest_file_path, | |
102 bool preserve_last_modified, | |
103 const StatusCallback& callback, | |
104 FileSystemInterface* file_system); | |
105 | |
106 | |
107 // Copies a file at |src_foreign_file_path|, which is not managed by Drive File | |
108 // System, to |dest_file_path|. | |
109 void CopyInForeignFile(const base::FilePath& src_foreign_file_path, | |
110 const base::FilePath& dest_file_path, | |
111 const StatusCallback& callback, | |
112 FileSystemInterface* file_system); | |
113 | |
114 // Reads the contents of the directory at |file_path|. | |
115 // Called from FileSystemProxy::ReadDirectory(). | |
116 void ReadDirectory(const base::FilePath& file_path, | |
117 const ReadDirectoryCallback& callback, | |
118 FileSystemInterface* file_system); | |
119 | |
120 // Removes a file at |file_path|. Called from FileSystemProxy::Remove(). | |
121 void Remove(const base::FilePath& file_path, | |
122 bool is_recursive, | |
123 const StatusCallback& callback, | |
124 FileSystemInterface* file_system); | |
125 | |
126 // Creates a new directory at |file_path|. | |
127 // Called from FileSystemProxy::CreateDirectory(). | |
128 void CreateDirectory(const base::FilePath& file_path, | |
129 bool is_exclusive, | |
130 bool is_recursive, | |
131 const StatusCallback& callback, | |
132 FileSystemInterface* file_system); | |
133 | |
134 // Creates a new file at |file_path|. | |
135 // Called from FileSystemProxy::CreateFile(). | |
136 void CreateFile(const base::FilePath& file_path, | |
137 bool is_exclusive, | |
138 const StatusCallback& callback, | |
139 FileSystemInterface* file_system); | |
140 | |
141 // Truncates the file at |file_path| to |length| bytes. | |
142 // Called from FileSystemProxy::Truncate(). | |
143 void Truncate(const base::FilePath& file_path, | |
144 int64 length, | |
145 const StatusCallback& callback, | |
146 FileSystemInterface* file_system); | |
147 | |
148 // Creates a snapshot for the file at |file_path|. | |
149 // Called from FileSystemProxy::CreateSnapshotFile(). | |
150 void CreateSnapshotFile(const base::FilePath& file_path, | |
151 const CreateSnapshotFileCallback& callback, | |
152 FileSystemInterface* file_system); | |
153 | |
154 // Creates a writable snapshot for the file at |file_path|. | |
155 // After writing operation is done, |close_callback| must be called. | |
156 void CreateWritableSnapshotFile( | |
157 const base::FilePath& file_path, | |
158 const CreateWritableSnapshotFileCallback& callback, | |
159 FileSystemInterface* file_system); | |
160 | |
161 // Opens the file at |file_path| with options |file_flags|. | |
162 // Called from FileSystemProxy::OpenFile. | |
163 void OpenFile(const base::FilePath& file_path, | |
164 int file_flags, | |
165 const OpenFileCallback& callback, | |
166 FileSystemInterface* file_system); | |
167 | |
168 // Changes timestamp of the file at |file_path| to |last_access_time| and | |
169 // |last_modified_time|. Called from FileSystemProxy::TouchFile(). | |
170 void TouchFile(const base::FilePath& file_path, | |
171 const base::Time& last_access_time, | |
172 const base::Time& last_modified_time, | |
173 const StatusCallback& callback, | |
174 FileSystemInterface* file_system); | |
175 | |
176 } // namespace fileapi_internal | |
177 } // namespace drive | |
178 | |
179 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_ | |
OLD | NEW |