Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / device_media_async_file_util.h
blob6b32d8498518967e60a91a5866458555af98bfad
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"
15 #include "storage/browser/fileapi/watcher_manager.h"
17 namespace storage {
18 class FileSystemOperationContext;
19 class FileSystemURL;
22 namespace storage {
23 class FileStreamReader;
26 enum MediaFileValidationType {
27 NO_MEDIA_FILE_VALIDATION,
28 APPLY_MEDIA_FILE_VALIDATION,
31 class DeviceMediaAsyncFileUtil : public storage::AsyncFileUtil {
32 public:
33 ~DeviceMediaAsyncFileUtil() override;
35 // Returns an instance of DeviceMediaAsyncFileUtil.
36 static scoped_ptr<DeviceMediaAsyncFileUtil> Create(
37 const base::FilePath& profile_path,
38 MediaFileValidationType validation_type);
40 bool SupportsStreaming(const storage::FileSystemURL& url);
42 // AsyncFileUtil overrides.
43 void CreateOrOpen(scoped_ptr<storage::FileSystemOperationContext> context,
44 const storage::FileSystemURL& url,
45 int file_flags,
46 const CreateOrOpenCallback& callback) override;
47 void EnsureFileExists(scoped_ptr<storage::FileSystemOperationContext> context,
48 const storage::FileSystemURL& url,
49 const EnsureFileExistsCallback& callback) override;
50 void CreateDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
51 const storage::FileSystemURL& url,
52 bool exclusive,
53 bool recursive,
54 const StatusCallback& callback) override;
55 void GetFileInfo(scoped_ptr<storage::FileSystemOperationContext> context,
56 const storage::FileSystemURL& url,
57 const GetFileInfoCallback& callback) override;
58 void ReadDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
59 const storage::FileSystemURL& url,
60 const ReadDirectoryCallback& callback) override;
61 void Touch(scoped_ptr<storage::FileSystemOperationContext> context,
62 const storage::FileSystemURL& url,
63 const base::Time& last_access_time,
64 const base::Time& last_modified_time,
65 const StatusCallback& callback) override;
66 void Truncate(scoped_ptr<storage::FileSystemOperationContext> context,
67 const storage::FileSystemURL& url,
68 int64 length,
69 const StatusCallback& callback) override;
70 void CopyFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
71 const storage::FileSystemURL& src_url,
72 const storage::FileSystemURL& dest_url,
73 CopyOrMoveOption option,
74 const CopyFileProgressCallback& progress_callback,
75 const StatusCallback& callback) override;
76 void MoveFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
77 const storage::FileSystemURL& src_url,
78 const storage::FileSystemURL& dest_url,
79 CopyOrMoveOption option,
80 const StatusCallback& callback) override;
81 void CopyInForeignFile(
82 scoped_ptr<storage::FileSystemOperationContext> context,
83 const base::FilePath& src_file_path,
84 const storage::FileSystemURL& dest_url,
85 const StatusCallback& callback) override;
86 void DeleteFile(scoped_ptr<storage::FileSystemOperationContext> context,
87 const storage::FileSystemURL& url,
88 const StatusCallback& callback) override;
89 void DeleteDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
90 const storage::FileSystemURL& url,
91 const StatusCallback& callback) override;
92 void DeleteRecursively(
93 scoped_ptr<storage::FileSystemOperationContext> context,
94 const storage::FileSystemURL& url,
95 const StatusCallback& callback) override;
96 void CreateSnapshotFile(
97 scoped_ptr<storage::FileSystemOperationContext> context,
98 const storage::FileSystemURL& url,
99 const CreateSnapshotFileCallback& callback) override;
101 // This method is called when existing Blobs are read.
102 // |expected_modification_time| indicates the expected snapshot state of the
103 // underlying storage. The returned FileStreamReader must return an error
104 // when the state of the underlying storage changes. Any errors associated
105 // with reading this file are returned by the FileStreamReader itself.
106 virtual scoped_ptr<storage::FileStreamReader> GetFileStreamReader(
107 const storage::FileSystemURL& url,
108 int64 offset,
109 const base::Time& expected_modification_time,
110 storage::FileSystemContext* context);
112 // Adds watcher to |url|.
113 void AddWatcher(const storage::FileSystemURL& url,
114 bool recursive,
115 const storage::WatcherManager::StatusCallback& callback,
116 const storage::WatcherManager::NotificationCallback&
117 notification_callback);
119 // Removes watcher of |url|.
120 void RemoveWatcher(const storage::FileSystemURL& url,
121 const bool recursive,
122 const storage::WatcherManager::StatusCallback& callback);
124 private:
125 class MediaPathFilterWrapper;
127 // Use Create() to get an instance of DeviceMediaAsyncFileUtil.
128 DeviceMediaAsyncFileUtil(const base::FilePath& profile_path,
129 MediaFileValidationType validation_type);
131 // Called when CreateDirectory method call succeeds. |callback| is invoked to
132 // complete the CreateDirectory request.
133 void OnDidCreateDirectory(const StatusCallback& callback);
135 // Called when GetFileInfo method call succeeds. |file_info| contains the
136 // file details of the requested url. |callback| is invoked to complete the
137 // GetFileInfo request.
138 void OnDidGetFileInfo(
139 base::SequencedTaskRunner* task_runner,
140 const base::FilePath& path,
141 const GetFileInfoCallback& callback,
142 const base::File::Info& file_info);
144 // Called when ReadDirectory method call succeeds. |callback| is invoked to
145 // complete the ReadDirectory request.
147 // If the contents of the given directory are reported in one batch, then
148 // |file_list| will have the list of all files/directories in the given
149 // directory and |has_more| will be false.
151 // If the contents of the given directory are reported in multiple chunks,
152 // |file_list| will have only a subset of all contents (the subsets reported
153 // in any two calls are disjoint), and |has_more| will be true, except for
154 // the last chunk.
155 void OnDidReadDirectory(
156 base::SequencedTaskRunner* task_runner,
157 const ReadDirectoryCallback& callback,
158 const EntryList& file_list,
159 bool has_more);
161 // Called when MoveFileLocal method call succeeds. |callback| is invoked to
162 // complete the MoveFileLocal request.
163 void OnDidMoveFileLocal(const StatusCallback& callback);
165 // Called when CopyFileLocal method call succeeds. |callback| is invoked to
166 // complete the CopyFileLocal request.
167 void OnDidCopyFileLocal(const StatusCallback& callback);
169 // Called when CopyInForeignFile method call succeeds. |callback| is invoked
170 // to complete the CopyInForeignFile request.
171 void OnDidCopyInForeignFile(const StatusCallback& callback);
173 // Called when DeleteFile method call succeeeds. |callback| is invoked to
174 // complete the DeleteFile request.
175 void OnDidDeleteFile(const StatusCallback& callback);
177 // Called when DeleteDirectory method call succeeds. |callback| is invoked to
178 // complete the DeleteDirectory request.
179 void OnDidDeleteDirectory(const StatusCallback& callback);
181 bool validate_media_files() const;
183 // Profile path.
184 const base::FilePath profile_path_;
186 scoped_refptr<MediaPathFilterWrapper> media_path_filter_wrapper_;
188 // For callbacks that may run after destruction.
189 base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_;
191 DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil);
194 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_