OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file provides the core implementation of fileapi methods. | 5 // This file provides the core implementation of fileapi methods. |
6 // The functions should be called on UI thread. | 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 | 7 // Note that most method invocation of fileapi is done on IO thread. The gap is |
8 // filled by FileSystemProxy. | 8 // filled by FileSystemProxy. |
9 // Also, the order of arguments for the functions which take FileSystemInterface | 9 // Also, the order of arguments for the functions which take FileSystemInterface |
10 // at the last is intentional. The instance of FileSystemInterface should be | 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. | 11 // accessible only on UI thread, but arguments are passed on IO thread. |
12 // So, here is an intended use case: | 12 // So, here is an intended use case: |
13 // 1) Bind arguments on IO thread. Then a callback instance whose type is | 13 // 1) Bind arguments on IO thread. Then a callback instance whose type is |
14 // Callback<void(FileSysstemInterface*)> is created. | 14 // Callback<void(FileSysstemInterface*)> is created. |
15 // 2) Post the task to the UI thread. | 15 // 2) Post the task to the UI thread. |
16 // 3) On UI thread, check if the instance of FileSystemInterface is alive or | 16 // 3) On UI thread, check if the instance of FileSystemInterface is alive or |
17 // not. If yes, Run the callback with it. | 17 // not. If yes, Run the callback with it. |
18 | 18 |
19 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ | 19 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ |
20 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ | 20 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ |
21 | 21 |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/basictypes.h" | 24 #include "base/basictypes.h" |
25 #include "base/callback_forward.h" | 25 #include "base/callback_forward.h" |
26 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
27 #include "chrome/browser/chromeos/drive/file_errors.h" | 27 #include "chrome/browser/chromeos/drive/file_errors.h" |
28 #include "webkit/common/blob/scoped_file.h" | 28 #include "storage/common/blob/scoped_file.h" |
29 | 29 |
30 namespace base { | 30 namespace base { |
31 class FilePath; | 31 class FilePath; |
32 } // namespace base | 32 } // namespace base |
33 | 33 |
34 namespace fileapi { | 34 namespace storage { |
35 struct DirectoryEntry; | 35 struct DirectoryEntry; |
36 class FileSystemURL; | 36 class FileSystemURL; |
37 } // namespace fileapi | 37 } // namespace storage |
38 | 38 |
39 namespace drive { | 39 namespace drive { |
40 | 40 |
41 class FileSystemInterface; | 41 class FileSystemInterface; |
42 | 42 |
43 namespace fileapi_internal { | 43 namespace storage_internal { |
44 | 44 |
45 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; | 45 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; |
46 | 46 |
47 typedef base::Callback< | 47 typedef base::Callback< |
48 void(base::File::Error result)> StatusCallback; | 48 void(base::File::Error result)> StatusCallback; |
49 typedef base::Callback< | 49 typedef base::Callback< |
50 void(base::File::Error result, | 50 void(base::File::Error result, |
51 const base::File::Info& file_info)> GetFileInfoCallback; | 51 const base::File::Info& file_info)> GetFileInfoCallback; |
52 typedef base::Callback< | 52 typedef base::Callback< |
53 void(base::File::Error result, | 53 void(base::File::Error result, |
54 const std::vector<fileapi::DirectoryEntry>& file_list, | 54 const std::vector<storage::DirectoryEntry>& file_list, |
55 bool has_more)> ReadDirectoryCallback; | 55 bool has_more)> ReadDirectoryCallback; |
56 typedef base::Callback< | 56 typedef base::Callback<void(base::File::Error result, |
57 void(base::File::Error result, | 57 const base::File::Info& file_info, |
58 const base::File::Info& file_info, | 58 const base::FilePath& snapshot_file_path, |
59 const base::FilePath& snapshot_file_path, | 59 storage::ScopedFile::ScopeOutPolicy |
60 webkit_blob::ScopedFile::ScopeOutPolicy scope_out_policy)> | 60 scope_out_policy)> CreateSnapshotFileCallback; |
61 CreateSnapshotFileCallback; | |
62 typedef base::Callback< | 61 typedef base::Callback< |
63 void(base::File::Error result, | 62 void(base::File::Error result, |
64 const base::FilePath& snapshot_file_path, | 63 const base::FilePath& snapshot_file_path, |
65 const base::Closure& close_callback)> | 64 const base::Closure& close_callback)> |
66 CreateWritableSnapshotFileCallback; | 65 CreateWritableSnapshotFileCallback; |
67 typedef base::Callback< | 66 typedef base::Callback< |
68 void(base::File file, | 67 void(base::File file, |
69 const base::Closure& close_callback)> OpenFileCallback; | 68 const base::Closure& close_callback)> OpenFileCallback; |
70 | 69 |
71 // Gets the profile of the Drive entry pointed by |url|. Used as | 70 // Gets the profile of the Drive entry pointed by |url|. Used as |
72 // FileSystemGetter callback by binding an URL on the IO thread and passing to | 71 // FileSystemGetter callback by binding an URL on the IO thread and passing to |
73 // the UI thread. | 72 // the UI thread. |
74 FileSystemInterface* GetFileSystemFromUrl(const fileapi::FileSystemURL& url); | 73 FileSystemInterface* GetFileSystemFromUrl(const storage::FileSystemURL& url); |
75 | 74 |
76 // Runs |file_system_getter| to obtain the instance of FileSystemInstance, | 75 // Runs |file_system_getter| to obtain the instance of FileSystemInstance, |
77 // and then runs |callback| with it. | 76 // and then runs |callback| with it. |
78 // If |file_system_getter| returns NULL, runs |error_callback| instead. | 77 // If |file_system_getter| returns NULL, runs |error_callback| instead. |
79 // This function must be called on UI thread. | 78 // This function must be called on UI thread. |
80 // |file_system_getter| and |callback| must not be null, but | 79 // |file_system_getter| and |callback| must not be null, but |
81 // |error_callback| can be null (if no operation is necessary for error | 80 // |error_callback| can be null (if no operation is necessary for error |
82 // case). | 81 // case). |
83 void RunFileSystemCallback( | 82 void RunFileSystemCallback( |
84 const FileSystemGetter& file_system_getter, | 83 const FileSystemGetter& file_system_getter, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 FileSystemInterface* file_system); | 168 FileSystemInterface* file_system); |
170 | 169 |
171 // Changes timestamp of the file at |file_path| to |last_access_time| and | 170 // Changes timestamp of the file at |file_path| to |last_access_time| and |
172 // |last_modified_time|. Called from FileSystemProxy::TouchFile(). | 171 // |last_modified_time|. Called from FileSystemProxy::TouchFile(). |
173 void TouchFile(const base::FilePath& file_path, | 172 void TouchFile(const base::FilePath& file_path, |
174 const base::Time& last_access_time, | 173 const base::Time& last_access_time, |
175 const base::Time& last_modified_time, | 174 const base::Time& last_modified_time, |
176 const StatusCallback& callback, | 175 const StatusCallback& callback, |
177 FileSystemInterface* file_system); | 176 FileSystemInterface* file_system); |
178 | 177 |
179 } // namespace fileapi_internal | 178 } // namespace storage_internal |
180 } // namespace drive | 179 } // namespace drive |
181 | 180 |
182 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ | 181 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_FILEAPI_WORKER_H_ |
OLD | NEW |