1 // Copyright (c) 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.
5 #ifndef WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_
6 #define WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "webkit/browser/fileapi/async_file_util.h"
13 class FileSystemFileUtil
;
15 // An adapter class for FileSystemFileUtil classes to provide asynchronous
18 // A filesystem can do either:
19 // - implement a synchronous version of FileUtil by extending
20 // FileSystemFileUtil and atach it to this adapter, or
21 // - directly implement AsyncFileUtil.
23 // This instance (as thus this->sync_file_util_) is guaranteed to be alive
24 // as far as FileSystemOperationContext given to each operation is kept alive.
25 class WEBKIT_STORAGE_BROWSER_EXPORT AsyncFileUtilAdapter
26 : public NON_EXPORTED_BASE(AsyncFileUtil
) {
28 // Creates a new AsyncFileUtil for |sync_file_util|. This takes the
29 // ownership of |sync_file_util|. (This doesn't take scoped_ptr<> just
30 // to save extra make_scoped_ptr; in all use cases a new fresh FileUtil is
31 // created only for this adapter.)
32 explicit AsyncFileUtilAdapter(FileSystemFileUtil
* sync_file_util
);
34 virtual ~AsyncFileUtilAdapter();
36 FileSystemFileUtil
* sync_file_util() {
37 return sync_file_util_
.get();
40 // AsyncFileUtil overrides.
41 virtual void CreateOrOpen(
42 scoped_ptr
<FileSystemOperationContext
> context
,
43 const FileSystemURL
& url
,
45 const CreateOrOpenCallback
& callback
) OVERRIDE
;
46 virtual void EnsureFileExists(
47 scoped_ptr
<FileSystemOperationContext
> context
,
48 const FileSystemURL
& url
,
49 const EnsureFileExistsCallback
& callback
) OVERRIDE
;
50 virtual void CreateDirectory(
51 scoped_ptr
<FileSystemOperationContext
> context
,
52 const FileSystemURL
& url
,
55 const StatusCallback
& callback
) OVERRIDE
;
56 virtual void GetFileInfo(
57 scoped_ptr
<FileSystemOperationContext
> context
,
58 const FileSystemURL
& url
,
59 const GetFileInfoCallback
& callback
) OVERRIDE
;
60 virtual void ReadDirectory(
61 scoped_ptr
<FileSystemOperationContext
> context
,
62 const FileSystemURL
& url
,
63 const ReadDirectoryCallback
& callback
) OVERRIDE
;
65 scoped_ptr
<FileSystemOperationContext
> context
,
66 const FileSystemURL
& url
,
67 const base::Time
& last_access_time
,
68 const base::Time
& last_modified_time
,
69 const StatusCallback
& callback
) OVERRIDE
;
70 virtual void Truncate(
71 scoped_ptr
<FileSystemOperationContext
> context
,
72 const FileSystemURL
& url
,
74 const StatusCallback
& callback
) OVERRIDE
;
75 virtual void CopyFileLocal(
76 scoped_ptr
<FileSystemOperationContext
> context
,
77 const FileSystemURL
& src_url
,
78 const FileSystemURL
& dest_url
,
79 CopyOrMoveOption option
,
80 const CopyFileProgressCallback
& progress_callback
,
81 const StatusCallback
& callback
) OVERRIDE
;
82 virtual void MoveFileLocal(
83 scoped_ptr
<FileSystemOperationContext
> context
,
84 const FileSystemURL
& src_url
,
85 const FileSystemURL
& dest_url
,
86 CopyOrMoveOption option
,
87 const StatusCallback
& callback
) OVERRIDE
;
88 virtual void CopyInForeignFile(
89 scoped_ptr
<FileSystemOperationContext
> context
,
90 const base::FilePath
& src_file_path
,
91 const FileSystemURL
& dest_url
,
92 const StatusCallback
& callback
) OVERRIDE
;
93 virtual void DeleteFile(
94 scoped_ptr
<FileSystemOperationContext
> context
,
95 const FileSystemURL
& url
,
96 const StatusCallback
& callback
) OVERRIDE
;
97 virtual void DeleteDirectory(
98 scoped_ptr
<FileSystemOperationContext
> context
,
99 const FileSystemURL
& url
,
100 const StatusCallback
& callback
) OVERRIDE
;
101 virtual void DeleteRecursively(
102 scoped_ptr
<FileSystemOperationContext
> context
,
103 const FileSystemURL
& url
,
104 const StatusCallback
& callback
) OVERRIDE
;
105 virtual void CreateSnapshotFile(
106 scoped_ptr
<FileSystemOperationContext
> context
,
107 const FileSystemURL
& url
,
108 const CreateSnapshotFileCallback
& callback
) OVERRIDE
;
111 scoped_ptr
<FileSystemFileUtil
> sync_file_util_
;
113 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtilAdapter
);
116 } // namespace fileapi
118 #endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_