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 CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "storage/browser/blob/shareable_file_reference.h"
14 #include "storage/browser/fileapi/async_file_util.h"
17 class FileSystemOperationContext
;
22 class FileStreamReader
;
25 enum MediaFileValidationType
{
26 NO_MEDIA_FILE_VALIDATION
,
27 APPLY_MEDIA_FILE_VALIDATION
,
30 class DeviceMediaAsyncFileUtil
: public storage::AsyncFileUtil
{
32 ~DeviceMediaAsyncFileUtil() override
;
34 // Returns an instance of DeviceMediaAsyncFileUtil.
35 static scoped_ptr
<DeviceMediaAsyncFileUtil
> Create(
36 const base::FilePath
& profile_path
,
37 MediaFileValidationType validation_type
);
39 bool SupportsStreaming(const storage::FileSystemURL
& url
);
41 // AsyncFileUtil overrides.
42 void CreateOrOpen(scoped_ptr
<storage::FileSystemOperationContext
> context
,
43 const storage::FileSystemURL
& url
,
45 const CreateOrOpenCallback
& callback
) override
;
46 void EnsureFileExists(scoped_ptr
<storage::FileSystemOperationContext
> context
,
47 const storage::FileSystemURL
& url
,
48 const EnsureFileExistsCallback
& callback
) override
;
49 void CreateDirectory(scoped_ptr
<storage::FileSystemOperationContext
> context
,
50 const storage::FileSystemURL
& url
,
53 const StatusCallback
& callback
) override
;
54 void GetFileInfo(scoped_ptr
<storage::FileSystemOperationContext
> context
,
55 const storage::FileSystemURL
& url
,
56 const GetFileInfoCallback
& callback
) override
;
57 void ReadDirectory(scoped_ptr
<storage::FileSystemOperationContext
> context
,
58 const storage::FileSystemURL
& url
,
59 const ReadDirectoryCallback
& callback
) override
;
60 void Touch(scoped_ptr
<storage::FileSystemOperationContext
> context
,
61 const storage::FileSystemURL
& url
,
62 const base::Time
& last_access_time
,
63 const base::Time
& last_modified_time
,
64 const StatusCallback
& callback
) override
;
65 void Truncate(scoped_ptr
<storage::FileSystemOperationContext
> context
,
66 const storage::FileSystemURL
& url
,
68 const StatusCallback
& callback
) override
;
69 void CopyFileLocal(scoped_ptr
<storage::FileSystemOperationContext
> context
,
70 const storage::FileSystemURL
& src_url
,
71 const storage::FileSystemURL
& dest_url
,
72 CopyOrMoveOption option
,
73 const CopyFileProgressCallback
& progress_callback
,
74 const StatusCallback
& callback
) override
;
75 void MoveFileLocal(scoped_ptr
<storage::FileSystemOperationContext
> context
,
76 const storage::FileSystemURL
& src_url
,
77 const storage::FileSystemURL
& dest_url
,
78 CopyOrMoveOption option
,
79 const StatusCallback
& callback
) override
;
80 void CopyInForeignFile(
81 scoped_ptr
<storage::FileSystemOperationContext
> context
,
82 const base::FilePath
& src_file_path
,
83 const storage::FileSystemURL
& dest_url
,
84 const StatusCallback
& callback
) override
;
85 void DeleteFile(scoped_ptr
<storage::FileSystemOperationContext
> context
,
86 const storage::FileSystemURL
& url
,
87 const StatusCallback
& callback
) override
;
88 void DeleteDirectory(scoped_ptr
<storage::FileSystemOperationContext
> context
,
89 const storage::FileSystemURL
& url
,
90 const StatusCallback
& callback
) override
;
91 void DeleteRecursively(
92 scoped_ptr
<storage::FileSystemOperationContext
> context
,
93 const storage::FileSystemURL
& url
,
94 const StatusCallback
& callback
) override
;
95 void CreateSnapshotFile(
96 scoped_ptr
<storage::FileSystemOperationContext
> context
,
97 const storage::FileSystemURL
& url
,
98 const CreateSnapshotFileCallback
& callback
) override
;
100 // This method is called when existing Blobs are read.
101 // |expected_modification_time| indicates the expected snapshot state of the
102 // underlying storage. The returned FileStreamReader must return an error
103 // when the state of the underlying storage changes. Any errors associated
104 // with reading this file are returned by the FileStreamReader itself.
105 virtual scoped_ptr
<storage::FileStreamReader
> GetFileStreamReader(
106 const storage::FileSystemURL
& url
,
108 const base::Time
& expected_modification_time
,
109 storage::FileSystemContext
* context
);
112 class MediaPathFilterWrapper
;
114 // Use Create() to get an instance of DeviceMediaAsyncFileUtil.
115 DeviceMediaAsyncFileUtil(const base::FilePath
& profile_path
,
116 MediaFileValidationType validation_type
);
118 // Called when CreateDirectory method call succeeds. |callback| is invoked to
119 // complete the CreateDirectory request.
120 void OnDidCreateDirectory(const StatusCallback
& callback
);
122 // Called when GetFileInfo method call succeeds. |file_info| contains the
123 // file details of the requested url. |callback| is invoked to complete the
124 // GetFileInfo request.
125 void OnDidGetFileInfo(
126 base::SequencedTaskRunner
* task_runner
,
127 const base::FilePath
& path
,
128 const GetFileInfoCallback
& callback
,
129 const base::File::Info
& file_info
);
131 // Called when ReadDirectory method call succeeds. |callback| is invoked to
132 // complete the ReadDirectory request.
134 // If the contents of the given directory are reported in one batch, then
135 // |file_list| will have the list of all files/directories in the given
136 // directory and |has_more| will be false.
138 // If the contents of the given directory are reported in multiple chunks,
139 // |file_list| will have only a subset of all contents (the subsets reported
140 // in any two calls are disjoint), and |has_more| will be true, except for
142 void OnDidReadDirectory(
143 base::SequencedTaskRunner
* task_runner
,
144 const ReadDirectoryCallback
& callback
,
145 const EntryList
& file_list
,
148 // Called when MoveFileLocal method call succeeds. |callback| is invoked to
149 // complete the MoveFileLocal request.
150 void OnDidMoveFileLocal(const StatusCallback
& callback
);
152 // Called when CopyFileLocal method call succeeds. |callback| is invoked to
153 // complete the CopyFileLocal request.
154 void OnDidCopyFileLocal(const StatusCallback
& callback
);
156 // Called when CopyInForeignFile method call succeeds. |callback| is invoked
157 // to complete the CopyInForeignFile request.
158 void OnDidCopyInForeignFile(const StatusCallback
& callback
);
160 // Called when DeleteFile method call succeeeds. |callback| is invoked to
161 // complete the DeleteFile request.
162 void OnDidDeleteFile(const StatusCallback
& callback
);
164 // Called when DeleteDirectory method call succeeds. |callback| is invoked to
165 // complete the DeleteDirectory request.
166 void OnDidDeleteDirectory(const StatusCallback
& callback
);
168 bool validate_media_files() const;
171 const base::FilePath profile_path_
;
173 scoped_refptr
<MediaPathFilterWrapper
> media_path_filter_wrapper_
;
175 // For callbacks that may run after destruction.
176 base::WeakPtrFactory
<DeviceMediaAsyncFileUtil
> weak_ptr_factory_
;
178 DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil
);
181 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_