Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / fileapi / remove_operation_delegate.cc
blob9786cf443b59b0aaabeb705632794633995058db
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.
5 #include "webkit/fileapi/remove_operation_delegate.h"
7 #include "base/bind.h"
8 #include "webkit/browser/fileapi/local_file_system_operation.h"
9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_operation_context.h"
12 namespace fileapi {
14 RemoveOperationDelegate::RemoveOperationDelegate(
15 FileSystemContext* file_system_context,
16 LocalFileSystemOperation* operation,
17 const FileSystemURL& url,
18 const StatusCallback& callback)
19 : RecursiveOperationDelegate(file_system_context, operation),
20 url_(url),
21 callback_(callback) {
24 RemoveOperationDelegate::~RemoveOperationDelegate() {}
26 void RemoveOperationDelegate::Run() {
27 NewNestedOperation()->RemoveFile(url_, base::Bind(
28 &RemoveOperationDelegate::DidTryRemoveFile, AsWeakPtr()));
31 void RemoveOperationDelegate::RunRecursively() {
32 StartRecursiveOperation(
33 url_,
34 base::Bind(&RemoveOperationDelegate::RemoveNextDirectory, AsWeakPtr()));
37 void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,
38 const StatusCallback& callback) {
39 if (to_remove_directories_.size() == 1u &&
40 to_remove_directories_.top() == url) {
41 // We seem to have been re-directed from ProcessDirectory.
42 to_remove_directories_.pop();
44 NewNestedOperation()->RemoveFile(url, base::Bind(
45 &RemoveOperationDelegate::DidRemoveFile, AsWeakPtr(), callback));
48 void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url,
49 const StatusCallback& callback) {
50 to_remove_directories_.push(url);
51 callback.Run(base::PLATFORM_FILE_OK);
54 void RemoveOperationDelegate::DidTryRemoveFile(
55 base::PlatformFileError error) {
56 if (error == base::PLATFORM_FILE_OK ||
57 error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) {
58 callback_.Run(error);
59 return;
61 NewNestedOperation()->RemoveDirectory(url_, callback_);
64 void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback,
65 base::PlatformFileError error) {
66 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
67 callback.Run(base::PLATFORM_FILE_OK);
68 return;
70 callback.Run(error);
73 void RemoveOperationDelegate::RemoveNextDirectory(
74 base::PlatformFileError error) {
75 if (error != base::PLATFORM_FILE_OK ||
76 to_remove_directories_.empty()) {
77 callback_.Run(error);
78 return;
80 FileSystemURL url = to_remove_directories_.top();
81 to_remove_directories_.pop();
82 NewNestedOperation()->RemoveDirectory(url, base::Bind(
83 &RemoveOperationDelegate::RemoveNextDirectory,
84 AsWeakPtr()));
87 } // namespace fileapi