[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 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 | |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 5 | #include "webkit/browser/fileapi/remove_operation_delegate.h" |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 6 | |
| 7 | #include "base/bind.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 8 | #include "webkit/browser/fileapi/file_system_context.h" |
[email protected] | 3c631b2 | 2013-06-05 16:13:34 | [diff] [blame] | 9 | #include "webkit/browser/fileapi/file_system_operation_runner.h" |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 10 | |
| 11 | namespace fileapi { |
| 12 | |
| 13 | RemoveOperationDelegate::RemoveOperationDelegate( |
[email protected] | a85efc3 | 2013-03-04 10:45:51 | [diff] [blame] | 14 | FileSystemContext* file_system_context, |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 15 | const FileSystemURL& url, |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 16 | const StatusCallback& callback) |
[email protected] | 3c631b2 | 2013-06-05 16:13:34 | [diff] [blame] | 17 | : RecursiveOperationDelegate(file_system_context), |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 18 | url_(url), |
[email protected] | 53a9741 | 2013-08-09 03:57:14 | [diff] [blame] | 19 | callback_(callback), |
| 20 | weak_factory_(this) { |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | RemoveOperationDelegate::~RemoveOperationDelegate() {} |
| 24 | |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 25 | void RemoveOperationDelegate::Run() { |
[email protected] | 3c631b2 | 2013-06-05 16:13:34 | [diff] [blame] | 26 | operation_runner()->RemoveFile(url_, base::Bind( |
[email protected] | 53a9741 | 2013-08-09 03:57:14 | [diff] [blame] | 27 | &RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr())); |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 30 | void RemoveOperationDelegate::RunRecursively() { |
[email protected] | dc231f6 | 2013-09-19 18:14:01 | [diff] [blame] | 31 | StartRecursiveOperation(url_, callback_); |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url, |
| 35 | const StatusCallback& callback) { |
[email protected] | dc231f6 | 2013-09-19 18:14:01 | [diff] [blame] | 36 | operation_runner()->RemoveFile( |
| 37 | url, |
| 38 | base::Bind(&RemoveOperationDelegate::DidRemoveFile, |
| 39 | weak_factory_.GetWeakPtr(), callback)); |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url, |
| 43 | const StatusCallback& callback) { |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 44 | callback.Run(base::PLATFORM_FILE_OK); |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | bf1599c4 | 2013-09-18 23:32:18 | [diff] [blame] | 47 | void RemoveOperationDelegate::PostProcessDirectory( |
| 48 | const FileSystemURL& url, const StatusCallback& callback) { |
[email protected] | dc231f6 | 2013-09-19 18:14:01 | [diff] [blame] | 49 | operation_runner()->RemoveDirectory(url, callback); |
[email protected] | bf1599c4 | 2013-09-18 23:32:18 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 52 | void RemoveOperationDelegate::DidTryRemoveFile( |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 53 | base::PlatformFileError error) { |
[email protected] | 9e61b26 | 2013-09-19 18:40:19 | [diff] [blame] | 54 | if (error != base::PLATFORM_FILE_ERROR_NOT_A_FILE && |
| 55 | error != base::PLATFORM_FILE_ERROR_SECURITY) { |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 56 | callback_.Run(error); |
| 57 | return; |
| 58 | } |
[email protected] | 9e61b26 | 2013-09-19 18:40:19 | [diff] [blame] | 59 | operation_runner()->RemoveDirectory( |
| 60 | url_, |
| 61 | base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory, |
| 62 | weak_factory_.GetWeakPtr(), error)); |
| 63 | } |
| 64 | |
| 65 | void RemoveOperationDelegate::DidTryRemoveDirectory( |
| 66 | base::PlatformFileError remove_file_error, |
| 67 | base::PlatformFileError remove_directory_error) { |
| 68 | callback_.Run( |
| 69 | remove_directory_error == base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY ? |
| 70 | remove_file_error : |
| 71 | remove_directory_error); |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 74 | void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback, |
| 75 | base::PlatformFileError error) { |
| 76 | if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
| 77 | callback.Run(base::PLATFORM_FILE_OK); |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 78 | return; |
| 79 | } |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 80 | callback.Run(error); |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | 92b80880 | 2013-01-28 05:10:51 | [diff] [blame] | 83 | } // namespace fileapi |