| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/browser/fileapi/remove_operation_delegate.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "webkit/browser/fileapi/file_system_context.h" | |
| 9 #include "webkit/browser/fileapi/file_system_operation_runner.h" | |
| 10 | |
| 11 namespace storage { | |
| 12 | |
| 13 RemoveOperationDelegate::RemoveOperationDelegate( | |
| 14 FileSystemContext* file_system_context, | |
| 15 const FileSystemURL& url, | |
| 16 const StatusCallback& callback) | |
| 17 : RecursiveOperationDelegate(file_system_context), | |
| 18 url_(url), | |
| 19 callback_(callback), | |
| 20 weak_factory_(this) { | |
| 21 } | |
| 22 | |
| 23 RemoveOperationDelegate::~RemoveOperationDelegate() {} | |
| 24 | |
| 25 void RemoveOperationDelegate::Run() { | |
| 26 operation_runner()->RemoveFile(url_, base::Bind( | |
| 27 &RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr())); | |
| 28 } | |
| 29 | |
| 30 void RemoveOperationDelegate::RunRecursively() { | |
| 31 StartRecursiveOperation(url_, callback_); | |
| 32 } | |
| 33 | |
| 34 void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url, | |
| 35 const StatusCallback& callback) { | |
| 36 operation_runner()->RemoveFile( | |
| 37 url, | |
| 38 base::Bind(&RemoveOperationDelegate::DidRemoveFile, | |
| 39 weak_factory_.GetWeakPtr(), callback)); | |
| 40 } | |
| 41 | |
| 42 void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url, | |
| 43 const StatusCallback& callback) { | |
| 44 callback.Run(base::File::FILE_OK); | |
| 45 } | |
| 46 | |
| 47 void RemoveOperationDelegate::PostProcessDirectory( | |
| 48 const FileSystemURL& url, const StatusCallback& callback) { | |
| 49 operation_runner()->RemoveDirectory(url, callback); | |
| 50 } | |
| 51 | |
| 52 void RemoveOperationDelegate::DidTryRemoveFile(base::File::Error error) { | |
| 53 if (error != base::File::FILE_ERROR_NOT_A_FILE && | |
| 54 error != base::File::FILE_ERROR_SECURITY) { | |
| 55 callback_.Run(error); | |
| 56 return; | |
| 57 } | |
| 58 operation_runner()->RemoveDirectory( | |
| 59 url_, | |
| 60 base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory, | |
| 61 weak_factory_.GetWeakPtr(), error)); | |
| 62 } | |
| 63 | |
| 64 void RemoveOperationDelegate::DidTryRemoveDirectory( | |
| 65 base::File::Error remove_file_error, | |
| 66 base::File::Error remove_directory_error) { | |
| 67 callback_.Run( | |
| 68 remove_directory_error == base::File::FILE_ERROR_NOT_A_DIRECTORY ? | |
| 69 remove_file_error : | |
| 70 remove_directory_error); | |
| 71 } | |
| 72 | |
| 73 void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback, | |
| 74 base::File::Error error) { | |
| 75 if (error == base::File::FILE_ERROR_NOT_FOUND) { | |
| 76 callback.Run(base::File::FILE_OK); | |
| 77 return; | |
| 78 } | |
| 79 callback.Run(error); | |
| 80 } | |
| 81 | |
| 82 } // namespace storage | |
| OLD | NEW |