Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / device_media_async_file_util.h
blob82f313ad6fdedc4951dbd21ff8a2f943eee77d39
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_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/platform_file.h"
12 #include "webkit/browser/fileapi/async_file_util.h"
13 #include "webkit/common/blob/shareable_file_reference.h"
15 namespace base {
16 class SequencedTaskRunner;
17 class Time;
20 namespace fileapi {
21 class FileSystemOperationContext;
22 class FileSystemURL;
25 class DeviceMediaAsyncFileUtil : public fileapi::AsyncFileUtil {
26 public:
27 virtual ~DeviceMediaAsyncFileUtil();
29 // Returns an instance of DeviceMediaAsyncFileUtil. Returns NULL if
30 // asynchronous operation is not supported. Callers own the returned
31 // object.
32 static DeviceMediaAsyncFileUtil* Create(const base::FilePath& profile_path);
34 // AsyncFileUtil overrides.
35 virtual void CreateOrOpen(
36 scoped_ptr<fileapi::FileSystemOperationContext> context,
37 const fileapi::FileSystemURL& url,
38 int file_flags,
39 const CreateOrOpenCallback& callback) OVERRIDE;
40 virtual void EnsureFileExists(
41 scoped_ptr<fileapi::FileSystemOperationContext> context,
42 const fileapi::FileSystemURL& url,
43 const EnsureFileExistsCallback& callback) OVERRIDE;
44 virtual void CreateDirectory(
45 scoped_ptr<fileapi::FileSystemOperationContext> context,
46 const fileapi::FileSystemURL& url,
47 bool exclusive,
48 bool recursive,
49 const StatusCallback& callback) OVERRIDE;
50 virtual void GetFileInfo(
51 scoped_ptr<fileapi::FileSystemOperationContext> context,
52 const fileapi::FileSystemURL& url,
53 const GetFileInfoCallback& callback) OVERRIDE;
54 virtual void ReadDirectory(
55 scoped_ptr<fileapi::FileSystemOperationContext> context,
56 const fileapi::FileSystemURL& url,
57 const ReadDirectoryCallback& callback) OVERRIDE;
58 virtual void Touch(
59 scoped_ptr<fileapi::FileSystemOperationContext> context,
60 const fileapi::FileSystemURL& url,
61 const base::Time& last_access_time,
62 const base::Time& last_modified_time,
63 const StatusCallback& callback) OVERRIDE;
64 virtual void Truncate(
65 scoped_ptr<fileapi::FileSystemOperationContext> context,
66 const fileapi::FileSystemURL& url,
67 int64 length,
68 const StatusCallback& callback) OVERRIDE;
69 virtual void CopyFileLocal(
70 scoped_ptr<fileapi::FileSystemOperationContext> context,
71 const fileapi::FileSystemURL& src_url,
72 const fileapi::FileSystemURL& dest_url,
73 CopyOrMoveOption option,
74 const CopyFileProgressCallback& progress_callback,
75 const StatusCallback& callback) OVERRIDE;
76 virtual void MoveFileLocal(
77 scoped_ptr<fileapi::FileSystemOperationContext> context,
78 const fileapi::FileSystemURL& src_url,
79 const fileapi::FileSystemURL& dest_url,
80 CopyOrMoveOption option,
81 const StatusCallback& callback) OVERRIDE;
82 virtual void CopyInForeignFile(
83 scoped_ptr<fileapi::FileSystemOperationContext> context,
84 const base::FilePath& src_file_path,
85 const fileapi::FileSystemURL& dest_url,
86 const StatusCallback& callback) OVERRIDE;
87 virtual void DeleteFile(
88 scoped_ptr<fileapi::FileSystemOperationContext> context,
89 const fileapi::FileSystemURL& url,
90 const StatusCallback& callback) OVERRIDE;
91 virtual void DeleteDirectory(
92 scoped_ptr<fileapi::FileSystemOperationContext> context,
93 const fileapi::FileSystemURL& url,
94 const StatusCallback& callback) OVERRIDE;
95 virtual void DeleteRecursively(
96 scoped_ptr<fileapi::FileSystemOperationContext> context,
97 const fileapi::FileSystemURL& url,
98 const StatusCallback& callback) OVERRIDE;
99 virtual void CreateSnapshotFile(
100 scoped_ptr<fileapi::FileSystemOperationContext> context,
101 const fileapi::FileSystemURL& url,
102 const CreateSnapshotFileCallback& callback) OVERRIDE;
104 private:
105 // Use Create() to get an instance of DeviceMediaAsyncFileUtil.
106 explicit DeviceMediaAsyncFileUtil(const base::FilePath& profile_path);
108 // Called when GetFileInfo method call succeeds. |file_info| contains the
109 // file details of the requested url. |callback| is invoked to complete the
110 // GetFileInfo request.
111 void OnDidGetFileInfo(
112 const AsyncFileUtil::GetFileInfoCallback& callback,
113 const base::PlatformFileInfo& file_info);
115 // Called when GetFileInfo method call failed to get the details of file
116 // specified by the requested url. |callback| is invoked to notify the
117 // caller about the platform file |error|.
118 void OnGetFileInfoError(
119 const AsyncFileUtil::GetFileInfoCallback& callback,
120 base::PlatformFileError error);
122 // Called when ReadDirectory method call succeeds. |callback| is invoked to
123 // complete the ReadDirectory request.
125 // If the contents of the given directory are reported in one batch, then
126 // |file_list| will have the list of all files/directories in the given
127 // directory and |has_more| will be false.
129 // If the contents of the given directory are reported in multiple chunks,
130 // |file_list| will have only a subset of all contents (the subsets reported
131 // in any two calls are disjoint), and |has_more| will be true, except for
132 // the last chunk.
133 void OnDidReadDirectory(
134 const AsyncFileUtil::ReadDirectoryCallback& callback,
135 const AsyncFileUtil::EntryList& file_list,
136 bool has_more);
138 // Called when ReadDirectory method call failed to enumerate the directory
139 // objects. |callback| is invoked to notify the caller about the |error|
140 // that occured while reading the directory objects.
141 void OnReadDirectoryError(
142 const AsyncFileUtil::ReadDirectoryCallback& callback,
143 base::PlatformFileError error);
145 // Called when the snapshot file specified by the |platform_path| is
146 // successfully created. |file_info| contains the device media file details
147 // for which the snapshot file is created.
148 void OnDidCreateSnapshotFile(
149 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
150 base::SequencedTaskRunner* media_task_runner,
151 const base::PlatformFileInfo& file_info,
152 const base::FilePath& platform_path);
154 // Called after OnDidCreateSnapshotFile finishes media check.
155 // |callback| is invoked to complete the CreateSnapshotFile request.
156 void OnDidCheckMedia(
157 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
158 const base::PlatformFileInfo& file_info,
159 scoped_refptr<webkit_blob::ShareableFileReference> platform_file,
160 base::PlatformFileError error);
162 // Called when CreateSnapshotFile method call fails. |callback| is invoked to
163 // notify the caller about the |error|.
164 void OnCreateSnapshotFileError(
165 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
166 base::PlatformFileError error);
168 // Called when the snapshot file specified by the |snapshot_file_path| is
169 // created to hold the contents of the url.path(). If the snapshot
170 // file is successfully created, |snapshot_file_path| will be an non-empty
171 // file path. In case of failure, |snapshot_file_path| will be an empty file
172 // path. Forwards the CreateSnapshot request to the delegate to copy the
173 // contents of url.path() to |snapshot_file_path|.
174 void OnSnapshotFileCreatedRunTask(
175 scoped_ptr<fileapi::FileSystemOperationContext> context,
176 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
177 const fileapi::FileSystemURL& url,
178 base::FilePath* snapshot_file_path);
180 // Profile path.
181 const base::FilePath profile_path_;
183 // For callbacks that may run after destruction.
184 base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_;
186 DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil);
189 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_