blob: 4819f0164e5a995d9b23ac4c61454fb9677fee38 [file] [log] [blame]
[email protected]92b808802013-01-28 05:10:511// 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]c6f9203a2013-05-28 02:08:075#include "webkit/browser/fileapi/remove_operation_delegate.h"
[email protected]92b808802013-01-28 05:10:516
7#include "base/bind.h"
[email protected]c6f9203a2013-05-28 02:08:078#include "webkit/browser/fileapi/file_system_context.h"
[email protected]3c631b22013-06-05 16:13:349#include "webkit/browser/fileapi/file_system_operation_runner.h"
[email protected]92b808802013-01-28 05:10:5110
11namespace fileapi {
12
13RemoveOperationDelegate::RemoveOperationDelegate(
[email protected]a85efc32013-03-04 10:45:5114 FileSystemContext* file_system_context,
[email protected]aeba9c12013-01-28 10:44:4215 const FileSystemURL& url,
[email protected]92b808802013-01-28 05:10:5116 const StatusCallback& callback)
[email protected]3c631b22013-06-05 16:13:3417 : RecursiveOperationDelegate(file_system_context),
[email protected]aeba9c12013-01-28 10:44:4218 url_(url),
[email protected]53a97412013-08-09 03:57:1419 callback_(callback),
20 weak_factory_(this) {
[email protected]92b808802013-01-28 05:10:5121}
22
23RemoveOperationDelegate::~RemoveOperationDelegate() {}
24
[email protected]aeba9c12013-01-28 10:44:4225void RemoveOperationDelegate::Run() {
[email protected]3c631b22013-06-05 16:13:3426 operation_runner()->RemoveFile(url_, base::Bind(
[email protected]53a97412013-08-09 03:57:1427 &RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr()));
[email protected]92b808802013-01-28 05:10:5128}
29
[email protected]aeba9c12013-01-28 10:44:4230void RemoveOperationDelegate::RunRecursively() {
[email protected]dc231f62013-09-19 18:14:0131 StartRecursiveOperation(url_, callback_);
[email protected]aeba9c12013-01-28 10:44:4232}
33
34void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,
35 const StatusCallback& callback) {
[email protected]dc231f62013-09-19 18:14:0136 operation_runner()->RemoveFile(
37 url,
38 base::Bind(&RemoveOperationDelegate::DidRemoveFile,
39 weak_factory_.GetWeakPtr(), callback));
[email protected]aeba9c12013-01-28 10:44:4240}
41
42void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url,
43 const StatusCallback& callback) {
[email protected]aeba9c12013-01-28 10:44:4244 callback.Run(base::PLATFORM_FILE_OK);
[email protected]92b808802013-01-28 05:10:5145}
46
[email protected]bf1599c42013-09-18 23:32:1847void RemoveOperationDelegate::PostProcessDirectory(
48 const FileSystemURL& url, const StatusCallback& callback) {
[email protected]dc231f62013-09-19 18:14:0149 operation_runner()->RemoveDirectory(url, callback);
[email protected]bf1599c42013-09-18 23:32:1850}
51
[email protected]92b808802013-01-28 05:10:5152void RemoveOperationDelegate::DidTryRemoveFile(
[email protected]92b808802013-01-28 05:10:5153 base::PlatformFileError error) {
[email protected]9e61b262013-09-19 18:40:1954 if (error != base::PLATFORM_FILE_ERROR_NOT_A_FILE &&
55 error != base::PLATFORM_FILE_ERROR_SECURITY) {
[email protected]92b808802013-01-28 05:10:5156 callback_.Run(error);
57 return;
58 }
[email protected]9e61b262013-09-19 18:40:1959 operation_runner()->RemoveDirectory(
60 url_,
61 base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory,
62 weak_factory_.GetWeakPtr(), error));
63}
64
65void 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]92b808802013-01-28 05:10:5172}
73
[email protected]aeba9c12013-01-28 10:44:4274void 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]92b808802013-01-28 05:10:5178 return;
79 }
[email protected]aeba9c12013-01-28 10:44:4280 callback.Run(error);
[email protected]92b808802013-01-28 05:10:5181}
82
[email protected]92b808802013-01-28 05:10:5183} // namespace fileapi