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

Side by Side Diff: webkit/fileapi/local_file_system_operation.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/fileapi/local_file_system_operation.h" 5 #include "webkit/fileapi/local_file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
13 #include "webkit/blob/shareable_file_reference.h" 13 #include "webkit/blob/shareable_file_reference.h"
14 #include "webkit/fileapi/cross_operation_delegate.h"
14 #include "webkit/fileapi/file_observers.h" 15 #include "webkit/fileapi/file_observers.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_file_util_proxy.h" 17 #include "webkit/fileapi/file_system_file_util_proxy.h"
17 #include "webkit/fileapi/file_system_mount_point_provider.h" 18 #include "webkit/fileapi/file_system_mount_point_provider.h"
18 #include "webkit/fileapi/file_system_task_runners.h" 19 #include "webkit/fileapi/file_system_task_runners.h"
19 #include "webkit/fileapi/file_system_types.h" 20 #include "webkit/fileapi/file_system_types.h"
20 #include "webkit/fileapi/file_system_url.h" 21 #include "webkit/fileapi/file_system_url.h"
21 #include "webkit/fileapi/file_system_util.h" 22 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/fileapi/file_writer_delegate.h" 23 #include "webkit/fileapi/file_writer_delegate.h"
24 #include "webkit/fileapi/remove_operation_delegate.h"
23 #include "webkit/fileapi/sandbox_file_stream_writer.h" 25 #include "webkit/fileapi/sandbox_file_stream_writer.h"
24 #include "webkit/quota/quota_manager.h" 26 #include "webkit/quota/quota_manager.h"
25 #include "webkit/quota/quota_types.h" 27 #include "webkit/quota/quota_types.h"
26 28
27 using webkit_blob::ShareableFileReference; 29 using webkit_blob::ShareableFileReference;
28 30
29 namespace fileapi { 31 namespace fileapi {
30 32
31 namespace { 33 namespace {
32 34
33 bool IsMediaFileSystemType(FileSystemType type) { 35 bool IsMediaFileSystemType(FileSystemType type) {
34 return type == kFileSystemTypeNativeMedia || 36 return type == kFileSystemTypeNativeMedia ||
35 type == kFileSystemTypeDeviceMedia; 37 type == kFileSystemTypeDeviceMedia;
36 } 38 }
37 39
38 bool IsCrossOperationAllowed(FileSystemType src_type,
39 FileSystemType dest_type) {
40 // If two types are supposed to run on different task runners we should not
41 // allow cross FileUtil operations at this layer.
42 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type);
43 }
44
45 } // namespace 40 } // namespace
46 41
42 // LocalFileSystemOperation::ScopedUpdateNotifier -----------------------------
43
47 class LocalFileSystemOperation::ScopedUpdateNotifier { 44 class LocalFileSystemOperation::ScopedUpdateNotifier {
48 public: 45 public:
49 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, 46 ScopedUpdateNotifier(FileSystemOperationContext* operation_context,
50 const FileSystemURL& url); 47 const FileSystemURL& url);
51 ~ScopedUpdateNotifier(); 48 ~ScopedUpdateNotifier();
52 49
53 private: 50 private:
54 // Not owned; owned by the owner of this instance 51 // Not owned; owned by the owner of this instance
55 // (i.e. LocalFileSystemOperation). 52 // (i.e. LocalFileSystemOperation).
56 FileSystemOperationContext* operation_context_; 53 FileSystemOperationContext* operation_context_;
57 FileSystemURL url_; 54 FileSystemURL url_;
58 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier); 55 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier);
59 }; 56 };
60 57
61 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier( 58 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier(
62 FileSystemOperationContext* operation_context, 59 FileSystemOperationContext* operation_context,
63 const FileSystemURL& url) 60 const FileSystemURL& url)
64 : operation_context_(operation_context), url_(url) { 61 : operation_context_(operation_context), url_(url) {
65 operation_context_->update_observers()->Notify( 62 operation_context_->update_observers()->Notify(
66 &FileUpdateObserver::OnStartUpdate, MakeTuple(url_)); 63 &FileUpdateObserver::OnStartUpdate, MakeTuple(url_));
67 } 64 }
68 65
69 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() { 66 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() {
70 operation_context_->update_observers()->Notify( 67 operation_context_->update_observers()->Notify(
71 &FileUpdateObserver::OnEndUpdate, MakeTuple(url_)); 68 &FileUpdateObserver::OnEndUpdate, MakeTuple(url_));
72 } 69 }
73 70
71 // LocalFileSystemOperation ---------------------------------------------------
72
74 LocalFileSystemOperation::~LocalFileSystemOperation() { 73 LocalFileSystemOperation::~LocalFileSystemOperation() {
75 } 74 }
76 75
77 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, 76 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url,
78 bool exclusive, 77 bool exclusive,
79 const StatusCallback& callback) { 78 const StatusCallback& callback) {
80 DCHECK(SetPendingOperationType(kOperationCreateFile)); 79 DCHECK(SetPendingOperationType(kOperationCreateFile));
81 80
82 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); 81 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
83 if (result != base::PLATFORM_FILE_OK) { 82 if (result != base::PLATFORM_FILE_OK) {
84 callback.Run(result); 83 callback.Run(result);
85 delete this; 84 delete this;
86 return; 85 return;
87 } 86 }
88 87
89 GetUsageAndQuotaThenRunTask( 88 GetUsageAndQuotaThenRunTask(
90 url, 89 url,
91 base::Bind(&LocalFileSystemOperation::DoCreateFile, 90 base::Bind(&LocalFileSystemOperation::DoCreateFile,
92 base::Unretained(this), url, callback, exclusive), 91 base::Unretained(this), url, callback, exclusive),
93 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 92 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
94 } 93 }
95 94
96 void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url, 95 void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url,
97 bool exclusive, 96 bool exclusive,
98 bool recursive, 97 bool recursive,
99 const StatusCallback& callback) { 98 const StatusCallback& callback) {
100 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); 99 DCHECK(SetPendingOperationType(kOperationCreateDirectory));
101 100
102 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); 101 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
103 if (result != base::PLATFORM_FILE_OK) { 102 if (result != base::PLATFORM_FILE_OK) {
104 callback.Run(result); 103 callback.Run(result);
105 delete this; 104 delete this;
106 return; 105 return;
107 } 106 }
108 GetUsageAndQuotaThenRunTask( 107 GetUsageAndQuotaThenRunTask(
109 url, 108 url,
110 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, 109 base::Bind(&LocalFileSystemOperation::DoCreateDirectory,
111 base::Unretained(this), url, callback, exclusive, recursive), 110 base::Unretained(this), url, callback, exclusive, recursive),
112 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 111 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
113 } 112 }
114 113
115 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, 114 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
116 const FileSystemURL& dest_url, 115 const FileSystemURL& dest_url,
117 const StatusCallback& callback) { 116 const StatusCallback& callback) {
118 DCHECK(SetPendingOperationType(kOperationCopy)); 117 DCHECK(SetPendingOperationType(kOperationCopy));
119 is_cross_operation_ = (src_url.type() != dest_url.type());
120 118
121 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); 119 base::PlatformFileError result = SetUp(
122 if (result == base::PLATFORM_FILE_OK) 120 dest_url, &file_util_, SETUP_FOR_WRITE);
123 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE);
124 if (result == base::PLATFORM_FILE_OK) {
125 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type()))
126 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
127 }
128 if (result != base::PLATFORM_FILE_OK) { 121 if (result != base::PLATFORM_FILE_OK) {
129 callback.Run(result); 122 callback.Run(result);
130 delete this; 123 delete this;
131 return; 124 return;
132 } 125 }
133 126
134 GetUsageAndQuotaThenRunTask( 127 DCHECK(!recursive_operation_delegate_);
135 dest_url, 128 recursive_operation_delegate_.reset(
136 base::Bind(&LocalFileSystemOperation::DoCopy, 129 new CrossOperationDelegate(this, src_url, dest_url,
137 base::Unretained(this), src_url, dest_url, callback), 130 CrossOperationDelegate::OPERATION_COPY,
138 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 131 callback));
132 recursive_operation_delegate_->RunRecursively();
139 } 133 }
140 134
141 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, 135 void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
142 const FileSystemURL& dest_url, 136 const FileSystemURL& dest_url,
143 const StatusCallback& callback) { 137 const StatusCallback& callback) {
144 DCHECK(SetPendingOperationType(kOperationMove)); 138 DCHECK(SetPendingOperationType(kOperationMove));
145 is_cross_operation_ = (src_url.type() != dest_url.type());
146 139
147 scoped_ptr<LocalFileSystemOperation> deleter(this); 140 base::PlatformFileError result = SetUp(
148 141 src_url, &file_util_, SETUP_FOR_WRITE);
149 // Temporarily disables cross-filesystem move. 142 if (result != base::PLATFORM_FILE_OK) {
150 // TODO(kinuko,tzik,kinaba): This special handling must be removed once 143 callback.Run(result);
151 // we support saner cross-filesystem operation. 144 delete this;
152 // (See http://crbug.com/130055)
153 if (is_cross_operation_) {
154 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
155 return; 145 return;
156 } 146 }
157 147
158 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); 148 DCHECK(!recursive_operation_delegate_);
159 if (result == base::PLATFORM_FILE_OK) 149 recursive_operation_delegate_.reset(
160 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); 150 new CrossOperationDelegate(this, src_url, dest_url,
161 if (result == base::PLATFORM_FILE_OK) { 151 CrossOperationDelegate::OPERATION_MOVE,
162 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) 152 callback));
163 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 153 recursive_operation_delegate_->RunRecursively();
164 }
165 if (result != base::PLATFORM_FILE_OK) {
166 callback.Run(result);
167 return;
168 }
169
170 GetUsageAndQuotaThenRunTask(
171 dest_url,
172 base::Bind(&LocalFileSystemOperation::DoMove,
173 base::Unretained(deleter.release()),
174 src_url, dest_url, callback),
175 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
176 } 154 }
177 155
178 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, 156 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url,
179 const StatusCallback& callback) { 157 const StatusCallback& callback) {
180 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); 158 DCHECK(SetPendingOperationType(kOperationDirectoryExists));
181 159
182 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 160 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
183 if (result != base::PLATFORM_FILE_OK) { 161 if (result != base::PLATFORM_FILE_OK) {
184 callback.Run(result); 162 callback.Run(result);
185 delete this; 163 delete this;
186 return; 164 return;
187 } 165 }
188 166
189 FileSystemFileUtilProxy::GetFileInfo( 167 FileSystemFileUtilProxy::GetFileInfo(
190 operation_context_.get(), src_util_, url, 168 operation_context(), file_util_, url,
191 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, 169 base::Bind(&LocalFileSystemOperation::DidDirectoryExists,
192 base::Owned(this), callback)); 170 base::Owned(this), callback));
193 } 171 }
194 172
195 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, 173 void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
196 const StatusCallback& callback) { 174 const StatusCallback& callback) {
197 DCHECK(SetPendingOperationType(kOperationFileExists)); 175 DCHECK(SetPendingOperationType(kOperationFileExists));
198 176
199 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 177 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
200 if (result != base::PLATFORM_FILE_OK) { 178 if (result != base::PLATFORM_FILE_OK) {
201 callback.Run(result); 179 callback.Run(result);
202 delete this; 180 delete this;
203 return; 181 return;
204 } 182 }
205 183
206 FileSystemFileUtilProxy::GetFileInfo( 184 FileSystemFileUtilProxy::GetFileInfo(
207 operation_context_.get(), src_util_, url, 185 operation_context(), file_util_, url,
208 base::Bind(&LocalFileSystemOperation::DidFileExists, 186 base::Bind(&LocalFileSystemOperation::DidFileExists,
209 base::Owned(this), callback)); 187 base::Owned(this), callback));
210 } 188 }
211 189
212 void LocalFileSystemOperation::GetMetadata( 190 void LocalFileSystemOperation::GetMetadata(
213 const FileSystemURL& url, const GetMetadataCallback& callback) { 191 const FileSystemURL& url, const GetMetadataCallback& callback) {
214 DCHECK(SetPendingOperationType(kOperationGetMetadata)); 192 DCHECK(SetPendingOperationType(kOperationGetMetadata));
215 193
216 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 194 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
217 if (result != base::PLATFORM_FILE_OK) { 195 if (result != base::PLATFORM_FILE_OK) {
218 callback.Run(result, base::PlatformFileInfo(), FilePath()); 196 callback.Run(result, base::PlatformFileInfo(), FilePath());
219 delete this; 197 delete this;
220 return; 198 return;
221 } 199 }
222 200
223 FileSystemFileUtilProxy::GetFileInfo( 201 FileSystemFileUtilProxy::GetFileInfo(
224 operation_context_.get(), src_util_, url, 202 operation_context(), file_util_, url,
225 base::Bind(&LocalFileSystemOperation::DidGetMetadata, 203 base::Bind(&LocalFileSystemOperation::DidGetMetadata,
226 base::Owned(this), callback)); 204 base::Owned(this), callback));
227 } 205 }
228 206
229 void LocalFileSystemOperation::ReadDirectory( 207 void LocalFileSystemOperation::ReadDirectory(
230 const FileSystemURL& url, const ReadDirectoryCallback& callback) { 208 const FileSystemURL& url, const ReadDirectoryCallback& callback) {
231 DCHECK(SetPendingOperationType(kOperationReadDirectory)); 209 DCHECK(SetPendingOperationType(kOperationReadDirectory));
232 210
233 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 211 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
234 if (result != base::PLATFORM_FILE_OK) { 212 if (result != base::PLATFORM_FILE_OK) {
235 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); 213 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
236 delete this; 214 delete this;
237 return; 215 return;
238 } 216 }
239 217
240 FileSystemFileUtilProxy::ReadDirectory( 218 FileSystemFileUtilProxy::ReadDirectory(
241 operation_context_.get(), src_util_, url, 219 operation_context(), file_util_, url,
242 base::Bind(&LocalFileSystemOperation::DidReadDirectory, 220 base::Bind(&LocalFileSystemOperation::DidReadDirectory,
243 base::Owned(this), callback)); 221 base::Owned(this), callback));
244 } 222 }
245 223
246 void LocalFileSystemOperation::Remove(const FileSystemURL& url, 224 void LocalFileSystemOperation::Remove(const FileSystemURL& url,
247 bool recursive, 225 bool recursive,
248 const StatusCallback& callback) { 226 const StatusCallback& callback) {
249 DCHECK(SetPendingOperationType(kOperationRemove)); 227 DCHECK(SetPendingOperationType(kOperationRemove));
250 228 DCHECK(!recursive_operation_delegate_);
251 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 229 recursive_operation_delegate_.reset(
252 if (result != base::PLATFORM_FILE_OK) { 230 new RemoveOperationDelegate(this, url, callback));
253 callback.Run(result); 231 if (recursive)
254 delete this; 232 recursive_operation_delegate_->RunRecursively();
255 return; 233 else
256 } 234 recursive_operation_delegate_->Run();
257
258 FileSystemFileUtilProxy::Delete(
259 operation_context_.get(), src_util_, url, recursive,
260 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
261 base::Owned(this), callback));
262 } 235 }
263 236
264 void LocalFileSystemOperation::Write( 237 void LocalFileSystemOperation::Write(
265 const net::URLRequestContext* url_request_context, 238 const net::URLRequestContext* url_request_context,
266 const FileSystemURL& url, 239 const FileSystemURL& url,
267 const GURL& blob_url, 240 const GURL& blob_url,
268 int64 offset, 241 int64 offset,
269 const WriteCallback& callback) { 242 const WriteCallback& callback) {
270 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); 243 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run();
271 } 244 }
272 245
273 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, 246 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
274 const StatusCallback& callback) { 247 const StatusCallback& callback) {
275 DCHECK(SetPendingOperationType(kOperationTruncate)); 248 DCHECK(SetPendingOperationType(kOperationTruncate));
276 249
277 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 250 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
278 if (result != base::PLATFORM_FILE_OK) { 251 if (result != base::PLATFORM_FILE_OK) {
279 callback.Run(result); 252 callback.Run(result);
280 delete this; 253 delete this;
281 return; 254 return;
282 } 255 }
283 GetUsageAndQuotaThenRunTask( 256 GetUsageAndQuotaThenRunTask(
284 url, 257 url,
285 base::Bind(&LocalFileSystemOperation::DoTruncate, 258 base::Bind(&LocalFileSystemOperation::DoTruncate,
286 base::Unretained(this), url, callback, length), 259 base::Unretained(this), url, callback, length),
287 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 260 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
288 } 261 }
289 262
290 void LocalFileSystemOperation::TouchFile(const FileSystemURL& url, 263 void LocalFileSystemOperation::TouchFile(const FileSystemURL& url,
291 const base::Time& last_access_time, 264 const base::Time& last_access_time,
292 const base::Time& last_modified_time, 265 const base::Time& last_modified_time,
293 const StatusCallback& callback) { 266 const StatusCallback& callback) {
294 DCHECK(SetPendingOperationType(kOperationTouchFile)); 267 DCHECK(SetPendingOperationType(kOperationTouchFile));
295 268
296 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 269 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
297 if (result != base::PLATFORM_FILE_OK) { 270 if (result != base::PLATFORM_FILE_OK) {
298 callback.Run(result); 271 callback.Run(result);
299 delete this; 272 delete this;
300 return; 273 return;
301 } 274 }
302 275
303 FileSystemFileUtilProxy::Touch( 276 FileSystemFileUtilProxy::Touch(
304 operation_context_.get(), src_util_, url, 277 operation_context(), file_util_, url,
305 last_access_time, last_modified_time, 278 last_access_time, last_modified_time,
306 base::Bind(&LocalFileSystemOperation::DidTouchFile, 279 base::Bind(&LocalFileSystemOperation::DidTouchFile,
307 base::Owned(this), callback)); 280 base::Owned(this), callback));
308 } 281 }
309 282
310 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, 283 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url,
311 int file_flags, 284 int file_flags,
312 base::ProcessHandle peer_handle, 285 base::ProcessHandle peer_handle,
313 const OpenFileCallback& callback) { 286 const OpenFileCallback& callback) {
314 DCHECK(SetPendingOperationType(kOperationOpenFile)); 287 DCHECK(SetPendingOperationType(kOperationOpenFile));
315 scoped_ptr<LocalFileSystemOperation> deleter(this); 288 scoped_ptr<LocalFileSystemOperation> deleter(this);
316 289
317 peer_handle_ = peer_handle; 290 peer_handle_ = peer_handle;
318 291
319 if (file_flags & ( 292 if (file_flags & (
320 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | 293 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
321 base::PLATFORM_FILE_HIDDEN))) { 294 base::PLATFORM_FILE_HIDDEN))) {
322 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, 295 callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
323 base::PlatformFile(), base::ProcessHandle()); 296 base::PlatformFile(), base::ProcessHandle());
324 return; 297 return;
325 } 298 }
326 if (file_flags & 299 if (file_flags &
327 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | 300 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS |
328 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | 301 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED |
329 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | 302 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
330 base::PLATFORM_FILE_DELETE_ON_CLOSE | 303 base::PLATFORM_FILE_DELETE_ON_CLOSE |
331 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { 304 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
332 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); 305 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
333 if (result != base::PLATFORM_FILE_OK) { 306 if (result != base::PLATFORM_FILE_OK) {
334 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); 307 callback.Run(result, base::PlatformFile(), base::ProcessHandle());
335 return; 308 return;
336 } 309 }
337 } else { 310 } else {
338 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 311 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
339 if (result != base::PLATFORM_FILE_OK) { 312 if (result != base::PLATFORM_FILE_OK) {
340 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); 313 callback.Run(result, base::PlatformFile(), base::ProcessHandle());
341 return; 314 return;
342 } 315 }
343 } 316 }
344 GetUsageAndQuotaThenRunTask( 317 GetUsageAndQuotaThenRunTask(
345 url, 318 url,
346 base::Bind(&LocalFileSystemOperation::DoOpenFile, 319 base::Bind(&LocalFileSystemOperation::DoOpenFile,
347 base::Unretained(deleter.release()), 320 base::Unretained(deleter.release()),
348 url, callback, file_flags), 321 url, callback, file_flags),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 365
393 LocalFileSystemOperation* 366 LocalFileSystemOperation*
394 LocalFileSystemOperation::AsLocalFileSystemOperation() { 367 LocalFileSystemOperation::AsLocalFileSystemOperation() {
395 return this; 368 return this;
396 } 369 }
397 370
398 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, 371 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url,
399 FilePath* platform_path) { 372 FilePath* platform_path) {
400 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); 373 DCHECK(SetPendingOperationType(kOperationGetLocalPath));
401 374
402 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 375 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
403 if (result != base::PLATFORM_FILE_OK) { 376 if (result != base::PLATFORM_FILE_OK) {
404 delete this; 377 delete this;
405 return; 378 return;
406 } 379 }
407 380
408 src_util_->GetLocalFilePath(operation_context_.get(), url, platform_path); 381 file_util_->GetLocalFilePath(operation_context(), url, platform_path);
409 382
410 delete this; 383 delete this;
411 } 384 }
412 385
413 void LocalFileSystemOperation::CreateSnapshotFile( 386 void LocalFileSystemOperation::CreateSnapshotFile(
414 const FileSystemURL& url, 387 const FileSystemURL& url,
415 const SnapshotFileCallback& callback) { 388 const SnapshotFileCallback& callback) {
416 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); 389 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
417 390
418 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); 391 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
419 if (result != base::PLATFORM_FILE_OK) { 392 if (result != base::PLATFORM_FILE_OK) {
420 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); 393 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL);
421 delete this; 394 delete this;
422 return; 395 return;
423 } 396 }
424 397
425 FileSystemFileUtilProxy::CreateSnapshotFile( 398 FileSystemFileUtilProxy::CreateSnapshotFile(
426 operation_context_.get(), src_util_, url, 399 operation_context(), file_util_, url,
427 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, 400 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile,
428 base::Owned(this), callback)); 401 base::Owned(this), callback));
429 } 402 }
430 403
431 void LocalFileSystemOperation::CopyInForeignFile( 404 void LocalFileSystemOperation::CopyInForeignFile(
432 const FilePath& src_local_disk_file_path, 405 const FilePath& src_local_disk_file_path,
433 const FileSystemURL& dest_url, 406 const FileSystemURL& dest_url,
434 const StatusCallback& callback) { 407 const StatusCallback& callback) {
435 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); 408 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
436 409
437 base::PlatformFileError result = SetUp( 410 base::PlatformFileError result = SetUp(
438 dest_url, &dest_util_, SETUP_FOR_CREATE); 411 dest_url, &file_util_, SETUP_FOR_CREATE);
439 if (result != base::PLATFORM_FILE_OK) { 412 if (result != base::PLATFORM_FILE_OK) {
440 callback.Run(result); 413 callback.Run(result);
441 delete this; 414 delete this;
442 return; 415 return;
443 } 416 }
444 417
445 GetUsageAndQuotaThenRunTask( 418 GetUsageAndQuotaThenRunTask(
446 dest_url, 419 dest_url,
447 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, 420 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile,
448 base::Unretained(this), src_local_disk_file_path, dest_url, 421 base::Unretained(this), src_local_disk_file_path, dest_url,
449 callback), 422 callback),
450 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 423 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
451 } 424 }
452 425
426 void LocalFileSystemOperation::RemoveFile(
427 const FileSystemURL& url,
428 const StatusCallback& callback) {
429 DCHECK(SetPendingOperationType(kOperationRemove));
430 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
431 if (result != base::PLATFORM_FILE_OK) {
432 callback.Run(result);
433 delete this;
434 return;
435 }
436
437 FileSystemFileUtilProxy::DeleteFile(
438 operation_context(), file_util_, url,
439 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
440 base::Owned(this), callback));
441 }
442
443 void LocalFileSystemOperation::RemoveDirectory(
444 const FileSystemURL& url,
445 const StatusCallback& callback) {
446 DCHECK(SetPendingOperationType(kOperationRemove));
447 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
448 if (result != base::PLATFORM_FILE_OK) {
449 callback.Run(result);
450 delete this;
451 return;
452 }
453
454 FileSystemFileUtilProxy::DeleteDirectory(
455 operation_context(), file_util_, url,
456 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
457 base::Owned(this), callback));
458 }
459
460 void LocalFileSystemOperation::CopyLocalFile(
461 const FileSystemURL& src_url,
462 const FileSystemURL& dest_url,
463 const StatusCallback& callback) {
464 DCHECK(SetPendingOperationType(kOperationCopy));
465 DCHECK_EQ(src_url.origin(), dest_url.origin());
466 DCHECK_EQ(src_url.type(), dest_url.type());
467
468 base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_READ);
469 if (result == base::PLATFORM_FILE_OK)
470 result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
471 if (result != base::PLATFORM_FILE_OK) {
472 callback.Run(result);
473 delete this;
474 return;
475 }
476
477 // Record read access for src_url.
478 operation_context()->access_observers()->Notify(
479 &FileAccessObserver::OnAccess, MakeTuple(src_url));
480 // Record update access for dest_url.
481 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
482 operation_context(), dest_url));
483
484 GetUsageAndQuotaThenRunTask(
485 dest_url,
486 base::Bind(&LocalFileSystemOperation::DoCopyLocalFile,
487 base::Unretained(this), src_url, dest_url, callback),
488 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
489 }
490
491 void LocalFileSystemOperation::MoveLocalFile(
492 const FileSystemURL& src_url,
493 const FileSystemURL& dest_url,
494 const StatusCallback& callback) {
495 DCHECK(SetPendingOperationType(kOperationMove));
496 DCHECK_EQ(src_url.origin(), dest_url.origin());
497 DCHECK_EQ(src_url.type(), dest_url.type());
498
499 base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_WRITE);
500 if (result == base::PLATFORM_FILE_OK)
501 result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
502 if (result != base::PLATFORM_FILE_OK) {
503 callback.Run(result);
504 delete this;
505 return;
506 }
507
508 // Record update access for dest_url.
509 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
510 operation_context(), dest_url));
511
512 GetUsageAndQuotaThenRunTask(
513 dest_url,
514 base::Bind(&LocalFileSystemOperation::DoMoveLocalFile,
515 base::Unretained(this), src_url, dest_url, callback),
516 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
517 }
518
453 LocalFileSystemOperation::LocalFileSystemOperation( 519 LocalFileSystemOperation::LocalFileSystemOperation(
454 FileSystemContext* file_system_context, 520 FileSystemContext* file_system_context,
455 scoped_ptr<FileSystemOperationContext> operation_context) 521 scoped_ptr<FileSystemOperationContext> operation_context)
456 : operation_context_(operation_context.Pass()), 522 : operation_context_(operation_context.Pass()),
457 src_util_(NULL), 523 file_util_(NULL),
458 dest_util_(NULL), 524 overriding_operation_context_(NULL),
459 is_cross_operation_(false),
460 peer_handle_(base::kNullProcessHandle), 525 peer_handle_(base::kNullProcessHandle),
461 pending_operation_(kOperationNone), 526 pending_operation_(kOperationNone),
462 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 527 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
463 DCHECK(operation_context_.get()); 528 DCHECK(operation_context_.get());
464 } 529 }
465 530
466 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( 531 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask(
467 const FileSystemURL& url, 532 const FileSystemURL& url,
468 const base::Closure& task, 533 const base::Closure& task,
469 const base::Closure& error_callback) { 534 const base::Closure& error_callback) {
470 quota::QuotaManagerProxy* quota_manager_proxy = 535 quota::QuotaManagerProxy* quota_manager_proxy =
471 file_system_context()->quota_manager_proxy(); 536 file_system_context()->quota_manager_proxy();
472 if (!quota_manager_proxy || 537 if (!quota_manager_proxy ||
473 !file_system_context()->GetQuotaUtil(url.type())) { 538 !file_system_context()->GetQuotaUtil(url.type())) {
474 // If we don't have the quota manager or the requested filesystem type 539 // If we don't have the quota manager or the requested filesystem type
475 // does not support quota, we should be able to let it go. 540 // does not support quota, we should be able to let it go.
476 operation_context_->set_allowed_bytes_growth(kint64max); 541 operation_context()->set_allowed_bytes_growth(kint64max);
477 task.Run(); 542 task.Run();
478 return; 543 return;
479 } 544 }
480 545
481 DCHECK(quota_manager_proxy); 546 DCHECK(quota_manager_proxy);
482 DCHECK(quota_manager_proxy->quota_manager()); 547 DCHECK(quota_manager_proxy->quota_manager());
483 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 548 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
484 url.origin(), 549 url.origin(),
485 FileSystemTypeToQuotaStorageType(url.type()), 550 FileSystemTypeToQuotaStorageType(url.type()),
486 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask, 551 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask,
487 weak_factory_.GetWeakPtr(), task, error_callback)); 552 weak_factory_.GetWeakPtr(), task, error_callback));
488 } 553 }
489 554
490 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask( 555 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask(
491 const base::Closure& task, 556 const base::Closure& task,
492 const base::Closure& error_callback, 557 const base::Closure& error_callback,
493 quota::QuotaStatusCode status, 558 quota::QuotaStatusCode status,
494 int64 usage, int64 quota) { 559 int64 usage, int64 quota) {
495 if (status != quota::kQuotaStatusOk) { 560 if (status != quota::kQuotaStatusOk) {
496 LOG(WARNING) << "Got unexpected quota error : " << status; 561 LOG(WARNING) << "Got unexpected quota error : " << status;
497 error_callback.Run(); 562 error_callback.Run();
498 return; 563 return;
499 } 564 }
500 565
501 operation_context_->set_allowed_bytes_growth(quota - usage); 566 operation_context()->set_allowed_bytes_growth(quota - usage);
502 task.Run(); 567 task.Run();
503 } 568 }
504 569
505 base::Closure LocalFileSystemOperation::GetWriteClosure( 570 base::Closure LocalFileSystemOperation::GetWriteClosure(
506 const net::URLRequestContext* url_request_context, 571 const net::URLRequestContext* url_request_context,
507 const FileSystemURL& url, 572 const FileSystemURL& url,
508 const GURL& blob_url, 573 const GURL& blob_url,
509 int64 offset, 574 int64 offset,
510 const WriteCallback& callback) { 575 const WriteCallback& callback) {
511 DCHECK(SetPendingOperationType(kOperationWrite)); 576 DCHECK(SetPendingOperationType(kOperationWrite));
512 577
513 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); 578 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
514 if (result != base::PLATFORM_FILE_OK) { 579 if (result != base::PLATFORM_FILE_OK) {
515 return base::Bind(&LocalFileSystemOperation::DidFailWrite, 580 return base::Bind(&LocalFileSystemOperation::DidFailWrite,
516 base::Owned(this), callback, result); 581 base::Owned(this), callback, result);
517 } 582 }
518 583
519 FileSystemMountPointProvider* provider = file_system_context()-> 584 FileSystemMountPointProvider* provider = file_system_context()->
520 GetMountPointProvider(url.type()); 585 GetMountPointProvider(url.type());
521 DCHECK(provider); 586 DCHECK(provider);
522 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( 587 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter(
523 url, offset, file_system_context())); 588 url, offset, file_system_context()));
(...skipping 24 matching lines...) Expand all
548 const WriteCallback& callback, 613 const WriteCallback& callback,
549 base::PlatformFileError result) { 614 base::PlatformFileError result) {
550 callback.Run(result, 0, false); 615 callback.Run(result, 0, false);
551 } 616 }
552 617
553 void LocalFileSystemOperation::DoCreateFile( 618 void LocalFileSystemOperation::DoCreateFile(
554 const FileSystemURL& url, 619 const FileSystemURL& url,
555 const StatusCallback& callback, 620 const StatusCallback& callback,
556 bool exclusive) { 621 bool exclusive) {
557 FileSystemFileUtilProxy::EnsureFileExists( 622 FileSystemFileUtilProxy::EnsureFileExists(
558 operation_context_.get(), 623 operation_context(),
559 src_util_, url, 624 file_util_, url,
560 base::Bind( 625 base::Bind(
561 exclusive ? 626 exclusive ?
562 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : 627 &LocalFileSystemOperation::DidEnsureFileExistsExclusive :
563 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, 628 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive,
564 base::Owned(this), callback)); 629 base::Owned(this), callback));
565 } 630 }
566 631
567 void LocalFileSystemOperation::DoCreateDirectory( 632 void LocalFileSystemOperation::DoCreateDirectory(
568 const FileSystemURL& url, 633 const FileSystemURL& url,
569 const StatusCallback& callback, 634 const StatusCallback& callback,
570 bool exclusive, bool recursive) { 635 bool exclusive, bool recursive) {
571 FileSystemFileUtilProxy::CreateDirectory( 636 FileSystemFileUtilProxy::CreateDirectory(
572 operation_context_.get(), 637 operation_context(),
573 src_util_, url, exclusive, recursive, 638 file_util_, url, exclusive, recursive,
574 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 639 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
575 base::Owned(this), callback)); 640 base::Owned(this), callback));
576 } 641 }
577 642
578 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url, 643 void LocalFileSystemOperation::DoCopyLocalFile(
579 const FileSystemURL& dest_url, 644 const FileSystemURL& src_url,
580 const StatusCallback& callback) { 645 const FileSystemURL& dest_url,
581 FileSystemFileUtilProxy::Copy( 646 const StatusCallback& callback) {
582 operation_context_.get(), 647 FileSystemFileUtilProxy::CopyLocalFile(
583 src_util_, dest_util_, 648 operation_context(),
584 src_url, dest_url, 649 file_util_, src_url, dest_url,
650 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
651 base::Owned(this), callback));
652 }
653
654 void LocalFileSystemOperation::DoMoveLocalFile(
655 const FileSystemURL& src_url,
656 const FileSystemURL& dest_url,
657 const StatusCallback& callback) {
658 FileSystemFileUtilProxy::MoveLocalFile(
659 operation_context(),
660 file_util_, src_url, dest_url,
585 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 661 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
586 base::Owned(this), callback)); 662 base::Owned(this), callback));
587 } 663 }
588 664
589 void LocalFileSystemOperation::DoCopyInForeignFile( 665 void LocalFileSystemOperation::DoCopyInForeignFile(
590 const FilePath& src_local_disk_file_path, 666 const FilePath& src_local_disk_file_path,
591 const FileSystemURL& dest_url, 667 const FileSystemURL& dest_url,
592 const StatusCallback& callback) { 668 const StatusCallback& callback) {
593 FileSystemFileUtilProxy::CopyInForeignFile( 669 FileSystemFileUtilProxy::CopyInForeignFile(
594 operation_context_.get(), 670 operation_context(),
595 dest_util_, 671 file_util_, src_local_disk_file_path, dest_url,
596 src_local_disk_file_path, dest_url,
597 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 672 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
598 base::Owned(this), callback)); 673 base::Owned(this), callback));
599 } 674 }
600
601 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url,
602 const FileSystemURL& dest_url,
603 const StatusCallback& callback) {
604 FileSystemFileUtilProxy::Move(
605 operation_context_.get(),
606 src_util_, dest_util_,
607 src_url, dest_url,
608 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
609 base::Owned(this), callback));
610 }
611 675
612 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, 676 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url,
613 const StatusCallback& callback, 677 const StatusCallback& callback,
614 int64 length) { 678 int64 length) {
615 FileSystemFileUtilProxy::Truncate( 679 FileSystemFileUtilProxy::Truncate(
616 operation_context_.get(), src_util_, url, length, 680 operation_context(), file_util_, url, length,
617 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, 681 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
618 base::Owned(this), callback)); 682 base::Owned(this), callback));
619 } 683 }
620 684
621 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, 685 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url,
622 const OpenFileCallback& callback, 686 const OpenFileCallback& callback,
623 int file_flags) { 687 int file_flags) {
624 FileSystemFileUtilProxy::CreateOrOpen( 688 FileSystemFileUtilProxy::CreateOrOpen(
625 operation_context_.get(), src_util_, url, file_flags, 689 operation_context(), file_util_, url, file_flags,
626 base::Bind(&LocalFileSystemOperation::DidOpenFile, 690 base::Bind(&LocalFileSystemOperation::DidOpenFile,
627 base::Owned(this), callback)); 691 base::Owned(this), callback));
628 } 692 }
629 693
630 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( 694 void LocalFileSystemOperation::DidEnsureFileExistsExclusive(
631 const StatusCallback& callback, 695 const StatusCallback& callback,
632 base::PlatformFileError rv, bool created) { 696 base::PlatformFileError rv, bool created) {
633 if (rv == base::PLATFORM_FILE_OK && !created) { 697 if (rv == base::PLATFORM_FILE_OK && !created) {
634 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); 698 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
635 } else { 699 } else {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if (write_callback_.is_null()) { 765 if (write_callback_.is_null()) {
702 // If cancelled, callback is already invoked and set to null in Cancel(). 766 // If cancelled, callback is already invoked and set to null in Cancel().
703 // We must not call it twice. Just shut down this operation object. 767 // We must not call it twice. Just shut down this operation object.
704 delete this; 768 delete this;
705 return; 769 return;
706 } 770 }
707 771
708 const bool complete = ( 772 const bool complete = (
709 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); 773 write_status != FileWriterDelegate::SUCCESS_IO_PENDING);
710 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { 774 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) {
711 operation_context_->change_observers()->Notify( 775 operation_context()->change_observers()->Notify(
712 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 776 &FileChangeObserver::OnModifyFile, MakeTuple(url));
713 } 777 }
714 778
715 write_callback_.Run(rv, bytes, complete); 779 write_callback_.Run(rv, bytes, complete);
716 if (complete || rv != base::PLATFORM_FILE_OK) 780 if (complete || rv != base::PLATFORM_FILE_OK)
717 delete this; 781 delete this;
718 } 782 }
719 783
720 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback, 784 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback,
721 base::PlatformFileError rv) { 785 base::PlatformFileError rv) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 FileSystemFileUtil** file_util, 817 FileSystemFileUtil** file_util,
754 SetUpMode mode) { 818 SetUpMode mode) {
755 if (!url.is_valid()) 819 if (!url.is_valid())
756 return base::PLATFORM_FILE_ERROR_INVALID_URL; 820 return base::PLATFORM_FILE_ERROR_INVALID_URL;
757 821
758 // Restricted file system is read-only. 822 // Restricted file system is read-only.
759 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal && 823 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal &&
760 mode != SETUP_FOR_READ) 824 mode != SETUP_FOR_READ)
761 return base::PLATFORM_FILE_ERROR_SECURITY; 825 return base::PLATFORM_FILE_ERROR_SECURITY;
762 826
763 if (!file_system_context()->GetMountPointProvider(
764 url.type())->IsAccessAllowed(url))
765 return base::PLATFORM_FILE_ERROR_SECURITY;
766
767 DCHECK(file_util); 827 DCHECK(file_util);
768 if (!*file_util) 828 if (!*file_util)
769 *file_util = file_system_context()->GetFileUtil(url.type()); 829 *file_util = file_system_context()->GetFileUtil(url.type());
770 if (!*file_util) 830 if (!*file_util)
771 return base::PLATFORM_FILE_ERROR_SECURITY; 831 return base::PLATFORM_FILE_ERROR_SECURITY;
772 832
833 // If this operation is created for recursive sub-operations (i.e.
834 // operation context is overridden from another operation) we skip
835 // some duplicated security checks.
836 if (overriding_operation_context_)
837 return base::PLATFORM_FILE_OK;
838
839 if (!file_system_context()->GetMountPointProvider(
840 url.type())->IsAccessAllowed(url))
841 return base::PLATFORM_FILE_ERROR_SECURITY;
842
773 if (mode == SETUP_FOR_READ) { 843 if (mode == SETUP_FOR_READ) {
774 // TODO(kinuko): This doesn't work well for cross-filesystem operation 844 operation_context()->access_observers()->Notify(
775 // in the current architecture since the operation context (thus the 845 &FileAccessObserver::OnAccess, MakeTuple(url));
776 // observers) is configured for the destination URL while this method
777 // could be called for both src and dest URL.
778 if (!is_cross_operation_) {
779 operation_context_->access_observers()->Notify(
780 &FileAccessObserver::OnAccess, MakeTuple(url));
781 }
782 return base::PLATFORM_FILE_OK; 846 return base::PLATFORM_FILE_OK;
783 } 847 }
784 848
785 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); 849 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE);
786 850
787 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( 851 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
788 operation_context_.get(), url)); 852 operation_context(), url));
789 853
790 // Any write access is disallowed on the root path. 854 // Any write access is disallowed on the root path.
791 if (url.path().value().length() == 0 || 855 if (url.path().value().length() == 0 ||
792 url.path().DirName().value() == url.path().value()) 856 url.path().DirName().value() == url.path().value())
793 return base::PLATFORM_FILE_ERROR_SECURITY; 857 return base::PLATFORM_FILE_ERROR_SECURITY;
794 858
795 if (mode == SETUP_FOR_CREATE) { 859 if (mode == SETUP_FOR_CREATE) {
796 FileSystemMountPointProvider* provider = file_system_context()-> 860 FileSystemMountPointProvider* provider = file_system_context()->
797 GetMountPointProvider(url.type()); 861 GetMountPointProvider(url.type());
798 862
799 // Check if the cracked file name looks good to create. 863 // Check if the cracked file name looks good to create.
800 if (provider->IsRestrictedFileName(VirtualPath::BaseName(url.path()))) 864 if (provider->IsRestrictedFileName(VirtualPath::BaseName(url.path())))
801 return base::PLATFORM_FILE_ERROR_SECURITY; 865 return base::PLATFORM_FILE_ERROR_SECURITY;
802 } 866 }
803 867
804 return base::PLATFORM_FILE_OK; 868 return base::PLATFORM_FILE_OK;
805 } 869 }
806 870
807 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { 871 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) {
808 if (pending_operation_ != kOperationNone) 872 if (pending_operation_ != kOperationNone)
809 return false; 873 return false;
810 pending_operation_ = type; 874 pending_operation_ = type;
811 return true; 875 return true;
812 } 876 }
813 877
814 } // namespace fileapi 878 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698