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/fileapi/async_file_util.h"
14 #include "storage/common/blob/shareable_file_reference.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 GetFileInfo method call succeeds. |file_info| contains the
119 // file details of the requested url. |callback| is invoked to complete the
120 // GetFileInfo request.
121 void OnDidGetFileInfo(
122 base::SequencedTaskRunner* task_runner,
123 const base::FilePath& path,
124 const GetFileInfoCallback& callback,
125 const base::File::Info& file_info);
127 // Called when ReadDirectory method call succeeds. |callback| is invoked to
128 // complete the ReadDirectory request.
130 // If the contents of the given directory are reported in one batch, then
131 // |file_list| will have the list of all files/directories in the given
132 // directory and |has_more| will be false.
134 // If the contents of the given directory are reported in multiple chunks,
135 // |file_list| will have only a subset of all contents (the subsets reported
136 // in any two calls are disjoint), and |has_more| will be true, except for
138 void OnDidReadDirectory(
139 base::SequencedTaskRunner* task_runner,
140 const ReadDirectoryCallback& callback,
141 const EntryList& file_list,
144 bool validate_media_files() const;
147 const base::FilePath profile_path_;
149 scoped_refptr<MediaPathFilterWrapper> media_path_filter_wrapper_;
151 // For callbacks that may run after destruction.
152 base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_;
154 DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil);
157 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_