OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "storage/browser/fileapi/remove_operation_delegate.h" | 5 #include "storage/browser/fileapi/remove_operation_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "storage/browser/fileapi/file_observers.h" | |
8 #include "storage/browser/fileapi/file_system_context.h" | 9 #include "storage/browser/fileapi/file_system_context.h" |
9 #include "storage/browser/fileapi/file_system_operation_runner.h" | 10 #include "storage/browser/fileapi/file_system_operation_runner.h" |
10 | 11 |
11 namespace storage { | 12 namespace storage { |
12 | 13 |
13 RemoveOperationDelegate::RemoveOperationDelegate( | 14 RemoveOperationDelegate::RemoveOperationDelegate( |
14 FileSystemContext* file_system_context, | 15 FileSystemContext* file_system_context, |
15 const FileSystemURL& url, | 16 const FileSystemURL& url, |
16 const StatusCallback& callback) | 17 const StatusCallback& callback) |
17 : RecursiveOperationDelegate(file_system_context), | 18 : RecursiveOperationDelegate(file_system_context), |
18 url_(url), | 19 url_(url), |
19 callback_(callback), | 20 callback_(callback), |
20 weak_factory_(this) { | 21 weak_factory_(this) { |
21 } | 22 } |
22 | 23 |
23 RemoveOperationDelegate::~RemoveOperationDelegate() {} | 24 RemoveOperationDelegate::~RemoveOperationDelegate() {} |
24 | 25 |
25 void RemoveOperationDelegate::Run() { | 26 void RemoveOperationDelegate::Run() { |
27 NotifyOnStartUpdate(url_); | |
tzik
2014/09/17 04:10:19
ditto
iseki
2014/09/17 06:21:45
Done.
| |
26 operation_runner()->RemoveFile(url_, base::Bind( | 28 operation_runner()->RemoveFile(url_, base::Bind( |
27 &RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr())); | 29 &RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr())); |
28 } | 30 } |
29 | 31 |
30 void RemoveOperationDelegate::RunRecursively() { | 32 void RemoveOperationDelegate::RunRecursively() { |
31 StartRecursiveOperation(url_, callback_); | 33 StartRecursiveOperation(url_, callback_); |
32 } | 34 } |
33 | 35 |
34 void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url, | 36 void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url, |
35 const StatusCallback& callback) { | 37 const StatusCallback& callback) { |
38 NotifyOnStartUpdate(url); | |
36 operation_runner()->RemoveFile( | 39 operation_runner()->RemoveFile( |
37 url, | 40 url, |
38 base::Bind(&RemoveOperationDelegate::DidRemoveFile, | 41 base::Bind(&RemoveOperationDelegate::DidRemoveFile, |
39 weak_factory_.GetWeakPtr(), callback)); | 42 weak_factory_.GetWeakPtr(), |
43 url, | |
44 callback)); | |
40 } | 45 } |
41 | 46 |
42 void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url, | 47 void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url, |
43 const StatusCallback& callback) { | 48 const StatusCallback& callback) { |
44 callback.Run(base::File::FILE_OK); | 49 callback.Run(base::File::FILE_OK); |
45 } | 50 } |
46 | 51 |
47 void RemoveOperationDelegate::PostProcessDirectory( | 52 void RemoveOperationDelegate::PostProcessDirectory( |
48 const FileSystemURL& url, const StatusCallback& callback) { | 53 const FileSystemURL& url, const StatusCallback& callback) { |
54 NotifyOnStartUpdate(url); | |
tzik
2014/09/17 05:03:06
ditto
iseki
2014/09/17 06:21:45
Done.
| |
49 operation_runner()->RemoveDirectory(url, callback); | 55 operation_runner()->RemoveDirectory(url, callback); |
50 } | 56 } |
51 | 57 |
52 void RemoveOperationDelegate::DidTryRemoveFile(base::File::Error error) { | 58 void RemoveOperationDelegate::DidTryRemoveFile(base::File::Error error) { |
53 if (error != base::File::FILE_ERROR_NOT_A_FILE && | 59 if (error != base::File::FILE_ERROR_NOT_A_FILE && |
54 error != base::File::FILE_ERROR_SECURITY) { | 60 error != base::File::FILE_ERROR_SECURITY) { |
61 NotifyOnEndUpdate(url_); | |
tzik
2014/09/17 05:03:06
ditto
iseki
2014/09/17 06:21:45
Done.
| |
55 callback_.Run(error); | 62 callback_.Run(error); |
56 return; | 63 return; |
57 } | 64 } |
58 operation_runner()->RemoveDirectory( | 65 operation_runner()->RemoveDirectory( |
59 url_, | 66 url_, |
60 base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory, | 67 base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory, |
61 weak_factory_.GetWeakPtr(), error)); | 68 weak_factory_.GetWeakPtr(), error)); |
62 } | 69 } |
63 | 70 |
64 void RemoveOperationDelegate::DidTryRemoveDirectory( | 71 void RemoveOperationDelegate::DidTryRemoveDirectory( |
65 base::File::Error remove_file_error, | 72 base::File::Error remove_file_error, |
66 base::File::Error remove_directory_error) { | 73 base::File::Error remove_directory_error) { |
74 NotifyOnEndUpdate(url_); | |
tzik
2014/09/17 05:03:06
ditto
iseki
2014/09/17 06:21:45
Done.
| |
67 callback_.Run( | 75 callback_.Run( |
68 remove_directory_error == base::File::FILE_ERROR_NOT_A_DIRECTORY ? | 76 remove_directory_error == base::File::FILE_ERROR_NOT_A_DIRECTORY ? |
69 remove_file_error : | 77 remove_file_error : |
70 remove_directory_error); | 78 remove_directory_error); |
71 } | 79 } |
72 | 80 |
73 void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback, | 81 void RemoveOperationDelegate::DidRemoveFile(const FileSystemURL& url, |
82 const StatusCallback& callback, | |
74 base::File::Error error) { | 83 base::File::Error error) { |
84 NotifyOnEndUpdate(url); | |
75 if (error == base::File::FILE_ERROR_NOT_FOUND) { | 85 if (error == base::File::FILE_ERROR_NOT_FOUND) { |
76 callback.Run(base::File::FILE_OK); | 86 callback.Run(base::File::FILE_OK); |
77 return; | 87 return; |
78 } | 88 } |
79 callback.Run(error); | 89 callback.Run(error); |
80 } | 90 } |
81 | 91 |
92 void RemoveOperationDelegate::NotifyOnStartUpdate(const FileSystemURL& url) { | |
93 if (file_system_context()->GetUpdateObservers(url.type())) { | |
94 file_system_context()->GetUpdateObservers(url.type())->Notify( | |
95 &FileUpdateObserver::OnStartUpdate, MakeTuple(url)); | |
96 } | |
97 } | |
98 | |
99 void RemoveOperationDelegate::NotifyOnEndUpdate(const FileSystemURL& url) { | |
100 if (file_system_context()->GetUpdateObservers(url.type())) { | |
101 file_system_context()->GetUpdateObservers(url.type())->Notify( | |
102 &FileUpdateObserver::OnEndUpdate, MakeTuple(url)); | |
103 } | |
104 } | |
105 | |
82 } // namespace storage | 106 } // namespace storage |
OLD | NEW |