OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 // static | 77 // static |
78 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( | 78 DeviceMediaAsyncFileUtil* DeviceMediaAsyncFileUtil::Create( |
79 const base::FilePath& profile_path) { | 79 const base::FilePath& profile_path) { |
80 DCHECK(!profile_path.empty()); | 80 DCHECK(!profile_path.empty()); |
81 return new DeviceMediaAsyncFileUtil(profile_path); | 81 return new DeviceMediaAsyncFileUtil(profile_path); |
82 } | 82 } |
83 | 83 |
84 bool DeviceMediaAsyncFileUtil::CreateOrOpen( | 84 bool DeviceMediaAsyncFileUtil::CreateOrOpen( |
85 FileSystemOperationContext* context, | 85 scoped_ptr<FileSystemOperationContext> context, |
86 const FileSystemURL& url, | 86 const FileSystemURL& url, |
87 int file_flags, | 87 int file_flags, |
88 const CreateOrOpenCallback& callback) { | 88 const CreateOrOpenCallback& callback) { |
89 DCHECK(IsOnIOThread(context)); | 89 DCHECK(IsOnIOThread(context.get())); |
90 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
91 if (!callback.is_null()) { | 91 if (!callback.is_null()) { |
92 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; | 92 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; |
93 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, | 93 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, |
94 base::PassPlatformFile(&invalid_file), | 94 base::PassPlatformFile(&invalid_file), |
95 false); | 95 false); |
96 } | 96 } |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 bool DeviceMediaAsyncFileUtil::EnsureFileExists( | 100 bool DeviceMediaAsyncFileUtil::EnsureFileExists( |
101 FileSystemOperationContext* context, | 101 scoped_ptr<FileSystemOperationContext> context, |
102 const FileSystemURL& url, | 102 const FileSystemURL& url, |
103 const EnsureFileExistsCallback& callback) { | 103 const EnsureFileExistsCallback& callback) { |
104 DCHECK(IsOnIOThread(context)); | 104 DCHECK(IsOnIOThread(context.get())); |
105 NOTIMPLEMENTED(); | 105 NOTIMPLEMENTED(); |
106 if (!callback.is_null()) | 106 if (!callback.is_null()) |
107 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); | 107 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 bool DeviceMediaAsyncFileUtil::CreateDirectory( | 111 bool DeviceMediaAsyncFileUtil::CreateDirectory( |
112 FileSystemOperationContext* context, | 112 scoped_ptr<FileSystemOperationContext> context, |
113 const FileSystemURL& url, | 113 const FileSystemURL& url, |
114 bool exclusive, | 114 bool exclusive, |
115 bool recursive, | 115 bool recursive, |
116 const StatusCallback& callback) { | 116 const StatusCallback& callback) { |
117 DCHECK(IsOnIOThread(context)); | 117 DCHECK(IsOnIOThread(context.get())); |
118 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
119 if (!callback.is_null()) | 119 if (!callback.is_null()) |
120 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 120 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 bool DeviceMediaAsyncFileUtil::GetFileInfo( | 124 bool DeviceMediaAsyncFileUtil::GetFileInfo( |
125 FileSystemOperationContext* context, | 125 scoped_ptr<FileSystemOperationContext> context, |
126 const FileSystemURL& url, | 126 const FileSystemURL& url, |
127 const GetFileInfoCallback& callback) { | 127 const GetFileInfoCallback& callback) { |
128 DCHECK(IsOnIOThread(context)); | 128 DCHECK(IsOnIOThread(context.get())); |
129 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 129 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context.get()); |
130 if (!delegate) { | 130 if (!delegate) { |
131 OnGetFileInfoError(callback, url.path(), | 131 OnGetFileInfoError(callback, url.path(), |
132 base::PLATFORM_FILE_ERROR_NOT_FOUND); | 132 base::PLATFORM_FILE_ERROR_NOT_FOUND); |
133 return true; | 133 return true; |
134 } | 134 } |
135 delegate->GetFileInfo( | 135 delegate->GetFileInfo( |
136 url.path(), | 136 url.path(), |
137 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo, | 137 base::Bind(&DeviceMediaAsyncFileUtil::OnDidGetFileInfo, |
138 weak_ptr_factory_.GetWeakPtr(), | 138 weak_ptr_factory_.GetWeakPtr(), |
139 callback, | 139 callback, |
140 url.path()), | 140 url.path()), |
141 base::Bind(&DeviceMediaAsyncFileUtil::OnGetFileInfoError, | 141 base::Bind(&DeviceMediaAsyncFileUtil::OnGetFileInfoError, |
142 weak_ptr_factory_.GetWeakPtr(), | 142 weak_ptr_factory_.GetWeakPtr(), |
143 callback, | 143 callback, |
144 url.path())); | 144 url.path())); |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 bool DeviceMediaAsyncFileUtil::ReadDirectory( | 148 bool DeviceMediaAsyncFileUtil::ReadDirectory( |
149 FileSystemOperationContext* context, | 149 scoped_ptr<FileSystemOperationContext> context, |
150 const FileSystemURL& url, | 150 const FileSystemURL& url, |
151 const ReadDirectoryCallback& callback) { | 151 const ReadDirectoryCallback& callback) { |
152 DCHECK(IsOnIOThread(context)); | 152 DCHECK(IsOnIOThread(context.get())); |
153 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 153 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context.get()); |
154 if (!delegate) { | 154 if (!delegate) { |
155 OnReadDirectoryError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 155 OnReadDirectoryError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); |
156 return true; | 156 return true; |
157 } | 157 } |
158 delegate->ReadDirectory( | 158 delegate->ReadDirectory( |
159 url.path(), | 159 url.path(), |
160 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, | 160 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, |
161 weak_ptr_factory_.GetWeakPtr(), | 161 weak_ptr_factory_.GetWeakPtr(), |
162 callback), | 162 callback), |
163 base::Bind(&DeviceMediaAsyncFileUtil::OnReadDirectoryError, | 163 base::Bind(&DeviceMediaAsyncFileUtil::OnReadDirectoryError, |
164 weak_ptr_factory_.GetWeakPtr(), | 164 weak_ptr_factory_.GetWeakPtr(), |
165 callback)); | 165 callback)); |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 bool DeviceMediaAsyncFileUtil::Touch( | 169 bool DeviceMediaAsyncFileUtil::Touch( |
170 FileSystemOperationContext* context, | 170 scoped_ptr<FileSystemOperationContext> context, |
171 const FileSystemURL& url, | 171 const FileSystemURL& url, |
172 const base::Time& last_access_time, | 172 const base::Time& last_access_time, |
173 const base::Time& last_modified_time, | 173 const base::Time& last_modified_time, |
174 const StatusCallback& callback) { | 174 const StatusCallback& callback) { |
175 DCHECK(IsOnIOThread(context)); | 175 DCHECK(IsOnIOThread(context.get())); |
176 NOTIMPLEMENTED(); | 176 NOTIMPLEMENTED(); |
177 if (!callback.is_null()) | 177 if (!callback.is_null()) |
178 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 178 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
179 return true; | 179 return true; |
180 } | 180 } |
181 | 181 |
182 bool DeviceMediaAsyncFileUtil::Truncate( | 182 bool DeviceMediaAsyncFileUtil::Truncate( |
183 FileSystemOperationContext* context, | 183 scoped_ptr<FileSystemOperationContext> context, |
184 const FileSystemURL& url, | 184 const FileSystemURL& url, |
185 int64 length, | 185 int64 length, |
186 const StatusCallback& callback) { | 186 const StatusCallback& callback) { |
187 DCHECK(IsOnIOThread(context)); | 187 DCHECK(IsOnIOThread(context.get())); |
188 NOTIMPLEMENTED(); | 188 NOTIMPLEMENTED(); |
189 if (!callback.is_null()) | 189 if (!callback.is_null()) |
190 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 190 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
191 return true; | 191 return true; |
192 } | 192 } |
193 | 193 |
194 bool DeviceMediaAsyncFileUtil::CopyFileLocal( | 194 bool DeviceMediaAsyncFileUtil::CopyFileLocal( |
195 FileSystemOperationContext* context, | 195 scoped_ptr<FileSystemOperationContext> context, |
196 const FileSystemURL& src_url, | 196 const FileSystemURL& src_url, |
197 const FileSystemURL& dest_url, | 197 const FileSystemURL& dest_url, |
198 const StatusCallback& callback) { | 198 const StatusCallback& callback) { |
199 DCHECK(IsOnIOThread(context)); | 199 DCHECK(IsOnIOThread(context.get())); |
200 NOTIMPLEMENTED(); | 200 NOTIMPLEMENTED(); |
201 if (!callback.is_null()) | 201 if (!callback.is_null()) |
202 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 202 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
203 return true; | 203 return true; |
204 } | 204 } |
205 | 205 |
206 bool DeviceMediaAsyncFileUtil::MoveFileLocal( | 206 bool DeviceMediaAsyncFileUtil::MoveFileLocal( |
207 FileSystemOperationContext* context, | 207 scoped_ptr<FileSystemOperationContext> context, |
208 const FileSystemURL& src_url, | 208 const FileSystemURL& src_url, |
209 const FileSystemURL& dest_url, | 209 const FileSystemURL& dest_url, |
210 const StatusCallback& callback) { | 210 const StatusCallback& callback) { |
211 DCHECK(IsOnIOThread(context)); | 211 DCHECK(IsOnIOThread(context.get())); |
212 NOTIMPLEMENTED(); | 212 NOTIMPLEMENTED(); |
213 if (!callback.is_null()) | 213 if (!callback.is_null()) |
214 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 214 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
215 return true; | 215 return true; |
216 } | 216 } |
217 | 217 |
218 bool DeviceMediaAsyncFileUtil::CopyInForeignFile( | 218 bool DeviceMediaAsyncFileUtil::CopyInForeignFile( |
219 FileSystemOperationContext* context, | 219 scoped_ptr<FileSystemOperationContext> context, |
220 const base::FilePath& src_file_path, | 220 const base::FilePath& src_file_path, |
221 const FileSystemURL& dest_url, | 221 const FileSystemURL& dest_url, |
222 const StatusCallback& callback) { | 222 const StatusCallback& callback) { |
223 DCHECK(IsOnIOThread(context)); | 223 DCHECK(IsOnIOThread(context.get())); |
224 NOTIMPLEMENTED(); | 224 NOTIMPLEMENTED(); |
225 if (!callback.is_null()) | 225 if (!callback.is_null()) |
226 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 226 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
227 return true; | 227 return true; |
228 } | 228 } |
229 | 229 |
230 bool DeviceMediaAsyncFileUtil::DeleteFile( | 230 bool DeviceMediaAsyncFileUtil::DeleteFile( |
231 FileSystemOperationContext* context, | 231 scoped_ptr<FileSystemOperationContext> context, |
232 const FileSystemURL& url, | 232 const FileSystemURL& url, |
233 const StatusCallback& callback) { | 233 const StatusCallback& callback) { |
234 DCHECK(IsOnIOThread(context)); | 234 DCHECK(IsOnIOThread(context.get())); |
235 NOTIMPLEMENTED(); | 235 NOTIMPLEMENTED(); |
236 if (!callback.is_null()) | 236 if (!callback.is_null()) |
237 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 237 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
238 return true; | 238 return true; |
239 } | 239 } |
240 | 240 |
241 bool DeviceMediaAsyncFileUtil::DeleteDirectory( | 241 bool DeviceMediaAsyncFileUtil::DeleteDirectory( |
242 FileSystemOperationContext* context, | 242 scoped_ptr<FileSystemOperationContext> context, |
243 const FileSystemURL& url, | 243 const FileSystemURL& url, |
244 const StatusCallback& callback) { | 244 const StatusCallback& callback) { |
245 DCHECK(IsOnIOThread(context)); | 245 DCHECK(IsOnIOThread(context.get())); |
246 NOTIMPLEMENTED(); | 246 NOTIMPLEMENTED(); |
247 if (!callback.is_null()) | 247 if (!callback.is_null()) |
248 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 248 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
249 return true; | 249 return true; |
250 } | 250 } |
251 | 251 |
252 bool DeviceMediaAsyncFileUtil::CreateSnapshotFile( | 252 bool DeviceMediaAsyncFileUtil::CreateSnapshotFile( |
253 FileSystemOperationContext* context, | 253 scoped_ptr<FileSystemOperationContext> context, |
254 const FileSystemURL& url, | 254 const FileSystemURL& url, |
255 const CreateSnapshotFileCallback& callback) { | 255 const CreateSnapshotFileCallback& callback) { |
256 DCHECK(IsOnIOThread(context)); | 256 DCHECK(IsOnIOThread(context.get())); |
257 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 257 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context.get()); |
258 if (!delegate) { | 258 if (!delegate) { |
259 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 259 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); |
260 return true; | 260 return true; |
261 } | 261 } |
262 base::FilePath* snapshot_file_path = new base::FilePath; | 262 base::FilePath* snapshot_file_path = new base::FilePath; |
263 return context->task_runner()->PostTaskAndReply( | 263 base::SequencedTaskRunner* task_runner = context->task_runner(); |
| 264 return task_runner->PostTaskAndReply( |
264 FROM_HERE, | 265 FROM_HERE, |
265 base::Bind(&CreateSnapshotFileOnBlockingPool, | 266 base::Bind(&CreateSnapshotFileOnBlockingPool, |
266 url.path(), | 267 url.path(), |
267 profile_path_, | 268 profile_path_, |
268 base::Unretained(snapshot_file_path)), | 269 base::Unretained(snapshot_file_path)), |
269 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask, | 270 base::Bind(&DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask, |
270 weak_ptr_factory_.GetWeakPtr(), | 271 weak_ptr_factory_.GetWeakPtr(), |
271 context, | 272 base::Passed(&context), |
272 callback, | 273 callback, |
273 url.path(), | 274 url.path(), |
274 base::Owned(snapshot_file_path))); | 275 base::Owned(snapshot_file_path))); |
275 } | 276 } |
276 | 277 |
277 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( | 278 DeviceMediaAsyncFileUtil::DeviceMediaAsyncFileUtil( |
278 const base::FilePath& profile_path) | 279 const base::FilePath& profile_path) |
279 : profile_path_(profile_path), | 280 : profile_path_(profile_path), |
280 weak_ptr_factory_(this) { | 281 weak_ptr_factory_(this) { |
281 } | 282 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 348 |
348 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( | 349 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( |
349 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 350 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
350 base::PlatformFileError error) { | 351 base::PlatformFileError error) { |
351 if (!callback.is_null()) | 352 if (!callback.is_null()) |
352 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), | 353 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), |
353 scoped_refptr<ShareableFileReference>()); | 354 scoped_refptr<ShareableFileReference>()); |
354 } | 355 } |
355 | 356 |
356 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask( | 357 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask( |
357 FileSystemOperationContext* context, | 358 scoped_ptr<FileSystemOperationContext> context, |
358 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | 359 const AsyncFileUtil::CreateSnapshotFileCallback& callback, |
359 const base::FilePath& device_file_path, | 360 const base::FilePath& device_file_path, |
360 base::FilePath* snapshot_file_path) { | 361 base::FilePath* snapshot_file_path) { |
361 DCHECK(IsOnIOThread(context)); | 362 DCHECK(IsOnIOThread(context.get())); |
362 if (!snapshot_file_path || snapshot_file_path->empty()) { | 363 if (!snapshot_file_path || snapshot_file_path->empty()) { |
363 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED); | 364 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED); |
364 return; | 365 return; |
365 } | 366 } |
366 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); | 367 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context.get()); |
367 if (!delegate) { | 368 if (!delegate) { |
368 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 369 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); |
369 return; | 370 return; |
370 } | 371 } |
371 delegate->CreateSnapshotFile( | 372 delegate->CreateSnapshotFile( |
372 device_file_path, | 373 device_file_path, |
373 *snapshot_file_path, | 374 *snapshot_file_path, |
374 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, | 375 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, |
375 weak_ptr_factory_.GetWeakPtr(), | 376 weak_ptr_factory_.GetWeakPtr(), |
376 callback, | 377 callback, |
377 make_scoped_refptr(context->task_runner())), | 378 make_scoped_refptr(context->task_runner())), |
378 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, | 379 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, |
379 weak_ptr_factory_.GetWeakPtr(), | 380 weak_ptr_factory_.GetWeakPtr(), |
380 callback)); | 381 callback)); |
381 } | 382 } |
382 | 383 |
383 } // namespace chrome | 384 } // namespace chrome |
OLD | NEW |