OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/drive/fileapi/async_file_util.h" | 5 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" | 14 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "google_apis/drive/task_util.h" | 16 #include "google_apis/drive/task_util.h" |
16 #include "webkit/browser/fileapi/file_system_operation_context.h" | 17 #include "webkit/browser/fileapi/file_system_operation_context.h" |
17 #include "webkit/browser/fileapi/file_system_url.h" | 18 #include "webkit/browser/fileapi/file_system_url.h" |
18 #include "webkit/common/blob/shareable_file_reference.h" | 19 #include "webkit/common/blob/shareable_file_reference.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
(...skipping 17 matching lines...) Expand all Loading... | |
39 file_system_getter, function, | 40 file_system_getter, function, |
40 on_error_callback.is_null() ? | 41 on_error_callback.is_null() ? |
41 base::Closure() : | 42 base::Closure() : |
42 base::Bind(&google_apis::RunTaskOnThread, | 43 base::Bind(&google_apis::RunTaskOnThread, |
43 base::MessageLoopProxy::current(), | 44 base::MessageLoopProxy::current(), |
44 on_error_callback))); | 45 on_error_callback))); |
45 } | 46 } |
46 | 47 |
47 // Runs CreateOrOpenFile callback based on the given |error| and |file|. | 48 // Runs CreateOrOpenFile callback based on the given |error| and |file|. |
48 void RunCreateOrOpenFileCallback( | 49 void RunCreateOrOpenFileCallback( |
49 const AsyncFileUtil::FileSystemGetter& file_system_getter, | 50 const fileapi_internal::FileSystemGetter& file_system_getter, |
50 const base::FilePath& file_path, | 51 const base::FilePath& file_path, |
51 const AsyncFileUtil::CreateOrOpenCallback& callback, | 52 const AsyncFileUtil::CreateOrOpenCallback& callback, |
52 base::File::Error error, | 53 base::File::Error error, |
53 base::PlatformFile file, | 54 base::PlatformFile file, |
54 const base::Closure& close_callback_on_ui_thread) { | 55 const base::Closure& close_callback_on_ui_thread) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
56 | 57 |
57 // It is necessary to make a closure, which runs on file closing here. | 58 // It is necessary to make a closure, which runs on file closing here. |
58 // It will be provided as a FileSystem::OpenFileCallback's argument later. | 59 // It will be provided as a FileSystem::OpenFileCallback's argument later. |
59 // (crbug.com/259184). | 60 // (crbug.com/259184). |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 scoped_refptr<webkit_blob::ShareableFileReference> file_reference = | 108 scoped_refptr<webkit_blob::ShareableFileReference> file_reference = |
108 webkit_blob::ShareableFileReference::GetOrCreate(webkit_blob::ScopedFile( | 109 webkit_blob::ShareableFileReference::GetOrCreate(webkit_blob::ScopedFile( |
109 local_path, | 110 local_path, |
110 scope_out_policy, | 111 scope_out_policy, |
111 BrowserThread::GetBlockingPool())); | 112 BrowserThread::GetBlockingPool())); |
112 callback.Run(error, file_info, local_path, file_reference); | 113 callback.Run(error, file_info, local_path, file_reference); |
113 } | 114 } |
114 | 115 |
115 } // namespace | 116 } // namespace |
116 | 117 |
117 AsyncFileUtil::AsyncFileUtil(const FileSystemGetter& file_system_getter) | 118 AsyncFileUtil::AsyncFileUtil() { |
118 : file_system_getter_(file_system_getter) { | |
119 } | 119 } |
120 | 120 |
121 AsyncFileUtil::~AsyncFileUtil() { | 121 AsyncFileUtil::~AsyncFileUtil() { |
122 } | 122 } |
123 | 123 |
124 void AsyncFileUtil::CreateOrOpen( | 124 void AsyncFileUtil::CreateOrOpen( |
125 scoped_ptr<fileapi::FileSystemOperationContext> context, | 125 scoped_ptr<fileapi::FileSystemOperationContext> context, |
126 const fileapi::FileSystemURL& url, | 126 const fileapi::FileSystemURL& url, |
127 int file_flags, | 127 int file_flags, |
128 const CreateOrOpenCallback& callback) { | 128 const CreateOrOpenCallback& callback) { |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
130 | 130 |
131 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 131 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
132 if (file_path.empty()) { | 132 if (file_path.empty()) { |
133 base::PlatformFile platform_file = base::kInvalidPlatformFileValue; | 133 base::PlatformFile platform_file = base::kInvalidPlatformFileValue; |
134 callback.Run(base::File::FILE_ERROR_NOT_FOUND, | 134 callback.Run(base::File::FILE_ERROR_NOT_FOUND, |
135 base::PassPlatformFile(&platform_file), | 135 base::PassPlatformFile(&platform_file), |
136 base::Closure()); | 136 base::Closure()); |
137 return; | 137 return; |
138 } | 138 } |
139 | 139 |
140 const fileapi_internal::FileSystemGetter getter = | |
141 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url); | |
140 PostFileSystemCallback( | 142 PostFileSystemCallback( |
141 file_system_getter_, | 143 getter, |
142 base::Bind(&fileapi_internal::OpenFile, | 144 base::Bind(&fileapi_internal::OpenFile, |
143 file_path, file_flags, | 145 file_path, file_flags, |
144 google_apis::CreateRelayCallback( | 146 google_apis::CreateRelayCallback( |
145 base::Bind(&RunCreateOrOpenFileCallback, | 147 base::Bind(&RunCreateOrOpenFileCallback, |
146 file_system_getter_, file_path, callback))), | 148 getter, file_path, callback))), |
147 base::Bind(&RunCreateOrOpenFileCallbackOnError, | 149 base::Bind(&RunCreateOrOpenFileCallbackOnError, |
148 callback, base::File::FILE_ERROR_FAILED)); | 150 callback, base::File::FILE_ERROR_FAILED)); |
149 } | 151 } |
150 | 152 |
151 void AsyncFileUtil::EnsureFileExists( | 153 void AsyncFileUtil::EnsureFileExists( |
152 scoped_ptr<fileapi::FileSystemOperationContext> context, | 154 scoped_ptr<fileapi::FileSystemOperationContext> context, |
153 const fileapi::FileSystemURL& url, | 155 const fileapi::FileSystemURL& url, |
154 const EnsureFileExistsCallback& callback) { | 156 const EnsureFileExistsCallback& callback) { |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
156 | 158 |
157 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 159 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
158 if (file_path.empty()) { | 160 if (file_path.empty()) { |
159 callback.Run(base::File::FILE_ERROR_NOT_FOUND, false); | 161 callback.Run(base::File::FILE_ERROR_NOT_FOUND, false); |
160 return; | 162 return; |
161 } | 163 } |
162 | 164 |
163 PostFileSystemCallback( | 165 PostFileSystemCallback( |
164 file_system_getter_, | 166 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
165 base::Bind(&fileapi_internal::CreateFile, | 167 base::Bind(&fileapi_internal::CreateFile, |
166 file_path, true /* is_exlusive */, | 168 file_path, true /* is_exlusive */, |
167 google_apis::CreateRelayCallback( | 169 google_apis::CreateRelayCallback( |
168 base::Bind(&RunEnsureFileExistsCallback, callback))), | 170 base::Bind(&RunEnsureFileExistsCallback, callback))), |
169 base::Bind(callback, base::File::FILE_ERROR_FAILED, false)); | 171 base::Bind(callback, base::File::FILE_ERROR_FAILED, false)); |
170 } | 172 } |
171 | 173 |
172 void AsyncFileUtil::CreateDirectory( | 174 void AsyncFileUtil::CreateDirectory( |
173 scoped_ptr<fileapi::FileSystemOperationContext> context, | 175 scoped_ptr<fileapi::FileSystemOperationContext> context, |
174 const fileapi::FileSystemURL& url, | 176 const fileapi::FileSystemURL& url, |
175 bool exclusive, | 177 bool exclusive, |
176 bool recursive, | 178 bool recursive, |
177 const StatusCallback& callback) { | 179 const StatusCallback& callback) { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
179 | 181 |
180 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 182 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
181 if (file_path.empty()) { | 183 if (file_path.empty()) { |
182 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 184 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
183 return; | 185 return; |
184 } | 186 } |
185 | 187 |
186 PostFileSystemCallback( | 188 PostFileSystemCallback( |
187 file_system_getter_, | 189 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
188 base::Bind(&fileapi_internal::CreateDirectory, | 190 base::Bind(&fileapi_internal::CreateDirectory, |
189 file_path, exclusive, recursive, | 191 file_path, exclusive, recursive, |
190 google_apis::CreateRelayCallback(callback)), | 192 google_apis::CreateRelayCallback(callback)), |
191 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 193 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
192 } | 194 } |
193 | 195 |
194 void AsyncFileUtil::GetFileInfo( | 196 void AsyncFileUtil::GetFileInfo( |
195 scoped_ptr<fileapi::FileSystemOperationContext> context, | 197 scoped_ptr<fileapi::FileSystemOperationContext> context, |
196 const fileapi::FileSystemURL& url, | 198 const fileapi::FileSystemURL& url, |
197 const GetFileInfoCallback& callback) { | 199 const GetFileInfoCallback& callback) { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
199 | 201 |
200 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 202 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
201 if (file_path.empty()) { | 203 if (file_path.empty()) { |
202 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); | 204 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); |
203 return; | 205 return; |
204 } | 206 } |
205 | 207 |
206 PostFileSystemCallback( | 208 PostFileSystemCallback( |
207 file_system_getter_, | 209 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
208 base::Bind(&fileapi_internal::GetFileInfo, | 210 base::Bind(&fileapi_internal::GetFileInfo, |
209 file_path, google_apis::CreateRelayCallback(callback)), | 211 file_path, google_apis::CreateRelayCallback(callback)), |
210 base::Bind(callback, base::File::FILE_ERROR_FAILED, | 212 base::Bind(callback, base::File::FILE_ERROR_FAILED, |
211 base::File::Info())); | 213 base::File::Info())); |
212 } | 214 } |
213 | 215 |
214 void AsyncFileUtil::ReadDirectory( | 216 void AsyncFileUtil::ReadDirectory( |
215 scoped_ptr<fileapi::FileSystemOperationContext> context, | 217 scoped_ptr<fileapi::FileSystemOperationContext> context, |
216 const fileapi::FileSystemURL& url, | 218 const fileapi::FileSystemURL& url, |
217 const ReadDirectoryCallback& callback) { | 219 const ReadDirectoryCallback& callback) { |
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
219 | 221 |
220 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 222 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
221 if (file_path.empty()) { | 223 if (file_path.empty()) { |
222 callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), false); | 224 callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), false); |
223 return; | 225 return; |
224 } | 226 } |
225 | 227 |
226 PostFileSystemCallback( | 228 PostFileSystemCallback( |
227 file_system_getter_, | 229 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
228 base::Bind(&fileapi_internal::ReadDirectory, | 230 base::Bind(&fileapi_internal::ReadDirectory, |
229 file_path, google_apis::CreateRelayCallback(callback)), | 231 file_path, google_apis::CreateRelayCallback(callback)), |
230 base::Bind(callback, base::File::FILE_ERROR_FAILED, | 232 base::Bind(callback, base::File::FILE_ERROR_FAILED, |
231 EntryList(), false)); | 233 EntryList(), false)); |
232 } | 234 } |
233 | 235 |
234 void AsyncFileUtil::Touch( | 236 void AsyncFileUtil::Touch( |
235 scoped_ptr<fileapi::FileSystemOperationContext> context, | 237 scoped_ptr<fileapi::FileSystemOperationContext> context, |
236 const fileapi::FileSystemURL& url, | 238 const fileapi::FileSystemURL& url, |
237 const base::Time& last_access_time, | 239 const base::Time& last_access_time, |
238 const base::Time& last_modified_time, | 240 const base::Time& last_modified_time, |
239 const StatusCallback& callback) { | 241 const StatusCallback& callback) { |
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
241 | 243 |
242 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 244 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
243 if (file_path.empty()) { | 245 if (file_path.empty()) { |
244 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 246 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
245 return; | 247 return; |
246 } | 248 } |
247 | 249 |
248 PostFileSystemCallback( | 250 PostFileSystemCallback( |
249 file_system_getter_, | 251 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
250 base::Bind(&fileapi_internal::TouchFile, | 252 base::Bind(&fileapi_internal::TouchFile, |
251 file_path, last_access_time, last_modified_time, | 253 file_path, last_access_time, last_modified_time, |
252 google_apis::CreateRelayCallback(callback)), | 254 google_apis::CreateRelayCallback(callback)), |
253 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 255 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
254 } | 256 } |
255 | 257 |
256 void AsyncFileUtil::Truncate( | 258 void AsyncFileUtil::Truncate( |
257 scoped_ptr<fileapi::FileSystemOperationContext> context, | 259 scoped_ptr<fileapi::FileSystemOperationContext> context, |
258 const fileapi::FileSystemURL& url, | 260 const fileapi::FileSystemURL& url, |
259 int64 length, | 261 int64 length, |
260 const StatusCallback& callback) { | 262 const StatusCallback& callback) { |
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
262 | 264 |
263 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 265 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
264 if (file_path.empty()) { | 266 if (file_path.empty()) { |
265 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 267 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
266 return; | 268 return; |
267 } | 269 } |
268 | 270 |
269 PostFileSystemCallback( | 271 PostFileSystemCallback( |
270 file_system_getter_, | 272 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
271 base::Bind(&fileapi_internal::Truncate, | 273 base::Bind(&fileapi_internal::Truncate, |
272 file_path, length, google_apis::CreateRelayCallback(callback)), | 274 file_path, length, google_apis::CreateRelayCallback(callback)), |
273 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 275 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
274 } | 276 } |
275 | 277 |
276 void AsyncFileUtil::CopyFileLocal( | 278 void AsyncFileUtil::CopyFileLocal( |
277 scoped_ptr<fileapi::FileSystemOperationContext> context, | 279 scoped_ptr<fileapi::FileSystemOperationContext> context, |
278 const fileapi::FileSystemURL& src_url, | 280 const fileapi::FileSystemURL& src_url, |
279 const fileapi::FileSystemURL& dest_url, | 281 const fileapi::FileSystemURL& dest_url, |
280 CopyOrMoveOption option, | 282 CopyOrMoveOption option, |
281 const CopyFileProgressCallback& progress_callback, | 283 const CopyFileProgressCallback& progress_callback, |
282 const StatusCallback& callback) { | 284 const StatusCallback& callback) { |
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
284 | 286 |
285 base::FilePath src_path = util::ExtractDrivePathFromFileSystemUrl(src_url); | 287 base::FilePath src_path = util::ExtractDrivePathFromFileSystemUrl(src_url); |
286 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); | 288 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); |
287 if (src_path.empty() || dest_path.empty()) { | 289 if (src_path.empty() || dest_path.empty()) { |
288 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 290 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
289 return; | 291 return; |
290 } | 292 } |
291 | 293 |
294 // Check that src_url and dest_url are from the same profile. | |
hashimoto
2014/02/04 05:44:36
What does this comment mean?
New check is introduc
kinaba
2014/02/04 06:10:59
Oops, I meant TODO comment by this. Updated in det
| |
292 PostFileSystemCallback( | 295 PostFileSystemCallback( |
293 file_system_getter_, | 296 base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url), |
294 base::Bind( | 297 base::Bind( |
295 &fileapi_internal::Copy, | 298 &fileapi_internal::Copy, |
296 src_path, dest_path, | 299 src_path, dest_path, |
297 option == fileapi::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, | 300 option == fileapi::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, |
298 google_apis::CreateRelayCallback(callback)), | 301 google_apis::CreateRelayCallback(callback)), |
299 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 302 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
300 } | 303 } |
301 | 304 |
302 void AsyncFileUtil::MoveFileLocal( | 305 void AsyncFileUtil::MoveFileLocal( |
303 scoped_ptr<fileapi::FileSystemOperationContext> context, | 306 scoped_ptr<fileapi::FileSystemOperationContext> context, |
304 const fileapi::FileSystemURL& src_url, | 307 const fileapi::FileSystemURL& src_url, |
305 const fileapi::FileSystemURL& dest_url, | 308 const fileapi::FileSystemURL& dest_url, |
306 CopyOrMoveOption option, | 309 CopyOrMoveOption option, |
307 const StatusCallback& callback) { | 310 const StatusCallback& callback) { |
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
309 | 312 |
310 base::FilePath src_path = util::ExtractDrivePathFromFileSystemUrl(src_url); | 313 base::FilePath src_path = util::ExtractDrivePathFromFileSystemUrl(src_url); |
311 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); | 314 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); |
312 if (src_path.empty() || dest_path.empty()) { | 315 if (src_path.empty() || dest_path.empty()) { |
313 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 316 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
314 return; | 317 return; |
315 } | 318 } |
316 | 319 |
320 // Check that src_url and dest_url are from the same profile. | |
317 PostFileSystemCallback( | 321 PostFileSystemCallback( |
318 file_system_getter_, | 322 base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url), |
319 base::Bind( | 323 base::Bind( |
320 &fileapi_internal::Move, | 324 &fileapi_internal::Move, |
321 src_path, dest_path, | 325 src_path, dest_path, |
322 option == fileapi::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, | 326 option == fileapi::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, |
323 google_apis::CreateRelayCallback(callback)), | 327 google_apis::CreateRelayCallback(callback)), |
324 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 328 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
325 } | 329 } |
326 | 330 |
327 void AsyncFileUtil::CopyInForeignFile( | 331 void AsyncFileUtil::CopyInForeignFile( |
328 scoped_ptr<fileapi::FileSystemOperationContext> context, | 332 scoped_ptr<fileapi::FileSystemOperationContext> context, |
329 const base::FilePath& src_file_path, | 333 const base::FilePath& src_file_path, |
330 const fileapi::FileSystemURL& dest_url, | 334 const fileapi::FileSystemURL& dest_url, |
331 const StatusCallback& callback) { | 335 const StatusCallback& callback) { |
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
333 | 337 |
334 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); | 338 base::FilePath dest_path = util::ExtractDrivePathFromFileSystemUrl(dest_url); |
335 if (dest_path.empty()) { | 339 if (dest_path.empty()) { |
336 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 340 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
337 return; | 341 return; |
338 } | 342 } |
339 | 343 |
340 PostFileSystemCallback( | 344 PostFileSystemCallback( |
341 file_system_getter_, | 345 base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url), |
342 base::Bind(&fileapi_internal::CopyInForeignFile, | 346 base::Bind(&fileapi_internal::CopyInForeignFile, |
343 src_file_path, dest_path, | 347 src_file_path, dest_path, |
344 google_apis::CreateRelayCallback(callback)), | 348 google_apis::CreateRelayCallback(callback)), |
345 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 349 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
346 } | 350 } |
347 | 351 |
348 void AsyncFileUtil::DeleteFile( | 352 void AsyncFileUtil::DeleteFile( |
349 scoped_ptr<fileapi::FileSystemOperationContext> context, | 353 scoped_ptr<fileapi::FileSystemOperationContext> context, |
350 const fileapi::FileSystemURL& url, | 354 const fileapi::FileSystemURL& url, |
351 const StatusCallback& callback) { | 355 const StatusCallback& callback) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
353 | 357 |
354 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 358 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
355 if (file_path.empty()) { | 359 if (file_path.empty()) { |
356 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 360 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
357 return; | 361 return; |
358 } | 362 } |
359 | 363 |
360 PostFileSystemCallback( | 364 PostFileSystemCallback( |
361 file_system_getter_, | 365 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
362 base::Bind(&fileapi_internal::Remove, | 366 base::Bind(&fileapi_internal::Remove, |
363 file_path, false /* not recursive */, | 367 file_path, false /* not recursive */, |
364 google_apis::CreateRelayCallback(callback)), | 368 google_apis::CreateRelayCallback(callback)), |
365 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 369 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
366 } | 370 } |
367 | 371 |
368 void AsyncFileUtil::DeleteDirectory( | 372 void AsyncFileUtil::DeleteDirectory( |
369 scoped_ptr<fileapi::FileSystemOperationContext> context, | 373 scoped_ptr<fileapi::FileSystemOperationContext> context, |
370 const fileapi::FileSystemURL& url, | 374 const fileapi::FileSystemURL& url, |
371 const StatusCallback& callback) { | 375 const StatusCallback& callback) { |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
373 | 377 |
374 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 378 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
375 if (file_path.empty()) { | 379 if (file_path.empty()) { |
376 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 380 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
377 return; | 381 return; |
378 } | 382 } |
379 | 383 |
380 PostFileSystemCallback( | 384 PostFileSystemCallback( |
381 file_system_getter_, | 385 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
382 base::Bind(&fileapi_internal::Remove, | 386 base::Bind(&fileapi_internal::Remove, |
383 file_path, false /* not recursive */, | 387 file_path, false /* not recursive */, |
384 google_apis::CreateRelayCallback(callback)), | 388 google_apis::CreateRelayCallback(callback)), |
385 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 389 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
386 } | 390 } |
387 | 391 |
388 void AsyncFileUtil::DeleteRecursively( | 392 void AsyncFileUtil::DeleteRecursively( |
389 scoped_ptr<fileapi::FileSystemOperationContext> context, | 393 scoped_ptr<fileapi::FileSystemOperationContext> context, |
390 const fileapi::FileSystemURL& url, | 394 const fileapi::FileSystemURL& url, |
391 const StatusCallback& callback) { | 395 const StatusCallback& callback) { |
392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
393 | 397 |
394 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 398 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
395 if (file_path.empty()) { | 399 if (file_path.empty()) { |
396 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 400 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
397 return; | 401 return; |
398 } | 402 } |
399 | 403 |
400 PostFileSystemCallback( | 404 PostFileSystemCallback( |
401 file_system_getter_, | 405 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
402 base::Bind(&fileapi_internal::Remove, | 406 base::Bind(&fileapi_internal::Remove, |
403 file_path, true /* recursive */, | 407 file_path, true /* recursive */, |
404 google_apis::CreateRelayCallback(callback)), | 408 google_apis::CreateRelayCallback(callback)), |
405 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 409 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
406 } | 410 } |
407 | 411 |
408 void AsyncFileUtil::CreateSnapshotFile( | 412 void AsyncFileUtil::CreateSnapshotFile( |
409 scoped_ptr<fileapi::FileSystemOperationContext> context, | 413 scoped_ptr<fileapi::FileSystemOperationContext> context, |
410 const fileapi::FileSystemURL& url, | 414 const fileapi::FileSystemURL& url, |
411 const CreateSnapshotFileCallback& callback) { | 415 const CreateSnapshotFileCallback& callback) { |
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
413 | 417 |
414 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); | 418 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
415 if (file_path.empty()) { | 419 if (file_path.empty()) { |
416 callback.Run(base::File::FILE_ERROR_NOT_FOUND, | 420 callback.Run(base::File::FILE_ERROR_NOT_FOUND, |
417 base::File::Info(), | 421 base::File::Info(), |
418 base::FilePath(), | 422 base::FilePath(), |
419 scoped_refptr<webkit_blob::ShareableFileReference>()); | 423 scoped_refptr<webkit_blob::ShareableFileReference>()); |
420 return; | 424 return; |
421 } | 425 } |
422 | 426 |
423 PostFileSystemCallback( | 427 PostFileSystemCallback( |
424 file_system_getter_, | 428 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url), |
425 base::Bind(&fileapi_internal::CreateSnapshotFile, | 429 base::Bind(&fileapi_internal::CreateSnapshotFile, |
426 file_path, | 430 file_path, |
427 google_apis::CreateRelayCallback( | 431 google_apis::CreateRelayCallback( |
428 base::Bind(&RunCreateSnapshotFileCallback, callback))), | 432 base::Bind(&RunCreateSnapshotFileCallback, callback))), |
429 base::Bind(callback, | 433 base::Bind(callback, |
430 base::File::FILE_ERROR_FAILED, | 434 base::File::FILE_ERROR_FAILED, |
431 base::File::Info(), | 435 base::File::Info(), |
432 base::FilePath(), | 436 base::FilePath(), |
433 scoped_refptr<webkit_blob::ShareableFileReference>())); | 437 scoped_refptr<webkit_blob::ShareableFileReference>())); |
434 } | 438 } |
435 | 439 |
436 } // namespace internal | 440 } // namespace internal |
437 } // namespace drive | 441 } // namespace drive |
OLD | NEW |