Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: webkit/fileapi/remove_operation_delegate.cc

Issue 12051010: (For-try) Divide recursive Copy/Move into multiple async tasks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/fileapi/remove_operation_delegate.h"
6
7 #include "base/bind.h"
8 #include "webkit/fileapi/file_system_context.h"
9 #include "webkit/fileapi/file_system_operation_context.h"
10 #include "webkit/fileapi/local_file_system_operation.h"
11
12 namespace fileapi {
13
14 RemoveOperationDelegate::RemoveOperationDelegate(
15 LocalFileSystemOperation* original_operation,
16 const FileSystemURL& url,
17 const StatusCallback& callback)
18 : RecursiveOperationDelegate(original_operation),
19 url_(url),
20 callback_(callback) {
21 }
22
23 RemoveOperationDelegate::~RemoveOperationDelegate() {}
24
25 void RemoveOperationDelegate::Run() {
26 base::PlatformFileError error;
27 LocalFileSystemOperation* operation = NewOperation(url_, &error);
28 if (!operation) {
29 callback_.Run(error);
30 return;
31 }
32 operation->RemoveFile(url_, base::Bind(
33 &RemoveOperationDelegate::DidTryRemoveFile, AsWeakPtr()));
34 }
35
36 void RemoveOperationDelegate::RunRecursively() {
37 StartRecursiveOperation(
38 url_,
39 base::Bind(&RemoveOperationDelegate::RemoveNextDirectory, AsWeakPtr()));
40 }
41
42 void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,
43 const StatusCallback& callback) {
44 base::PlatformFileError error;
45 LocalFileSystemOperation* operation = NewOperation(url, &error);
46 if (!operation) {
47 callback.Run(error);
48 return;
49 }
50 if (to_remove_directories_.size() == 1u &&
51 to_remove_directories_.top() == url) {
52 // We seem to have been re-directed from ProcessDirectory.
53 to_remove_directories_.pop();
54 }
55 operation->RemoveFile(url, base::Bind(
56 &RemoveOperationDelegate::DidRemoveFile, AsWeakPtr(), callback));
57 }
58
59 void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url,
60 const StatusCallback& callback) {
61 to_remove_directories_.push(url);
62 callback.Run(base::PLATFORM_FILE_OK);
63 }
64
65 void RemoveOperationDelegate::DidTryRemoveFile(
66 base::PlatformFileError error) {
67 if (error == base::PLATFORM_FILE_OK ||
68 error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) {
69 callback_.Run(error);
70 return;
71 }
72 LocalFileSystemOperation* operation = NewOperation(url_, &error);
73 if (!operation) {
74 callback_.Run(error);
75 return;
76 }
77 operation->RemoveDirectory(url_, callback_);
78 }
79
80 void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback,
81 base::PlatformFileError error) {
82 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
83 callback.Run(base::PLATFORM_FILE_OK);
84 return;
85 }
86 callback.Run(error);
87 }
88
89 void RemoveOperationDelegate::RemoveNextDirectory(
90 base::PlatformFileError error) {
91 if (error != base::PLATFORM_FILE_OK ||
92 to_remove_directories_.empty()) {
93 callback_.Run(error);
94 return;
95 }
96 FileSystemURL url = to_remove_directories_.top();
97 to_remove_directories_.pop();
98 LocalFileSystemOperation* operation = NewOperation(url, &error);
99 if (!operation) {
100 callback_.Run(error);
101 return;
102 }
103 operation->RemoveDirectory(url, base::Bind(
104 &RemoveOperationDelegate::RemoveNextDirectory,
105 AsWeakPtr()));
106 }
107
108 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698