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

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

Issue 9372044: Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
11 #include "net/url_request/url_request_context.h" 11 #include "net/url_request/url_request_context.h"
12 #include "webkit/fileapi/file_system_callback_dispatcher.h"
13 #include "webkit/fileapi/file_system_context.h" 12 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_file_util_proxy.h" 13 #include "webkit/fileapi/file_system_file_util_proxy.h"
15 #include "webkit/fileapi/file_system_mount_point_provider.h" 14 #include "webkit/fileapi/file_system_mount_point_provider.h"
16 #include "webkit/fileapi/file_system_operation_context.h" 15 #include "webkit/fileapi/file_system_operation_context.h"
17 #include "webkit/fileapi/file_system_quota_util.h" 16 #include "webkit/fileapi/file_system_quota_util.h"
18 #include "webkit/fileapi/file_system_types.h" 17 #include "webkit/fileapi/file_system_types.h"
19 #include "webkit/fileapi/file_system_util.h" 18 #include "webkit/fileapi/file_system_util.h"
20 #include "webkit/fileapi/file_writer_delegate.h" 19 #include "webkit/fileapi/file_writer_delegate.h"
21 #include "webkit/fileapi/local_file_util.h" 20 #include "webkit/fileapi/local_file_util.h"
22 #include "webkit/fileapi/quota_file_util.h" 21 #include "webkit/fileapi/quota_file_util.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 proxy_, 64 proxy_,
66 base::Bind(&FileSystemFileUtil::Close, 65 base::Bind(&FileSystemFileUtil::Close,
67 base::Unretained(c->src_file_util()), 66 base::Unretained(c->src_file_util()),
68 base::Owned(c)), 67 base::Owned(c)),
69 file_writer_delegate_->file(), 68 file_writer_delegate_->file(),
70 base::FileUtilProxy::StatusCallback()); 69 base::FileUtilProxy::StatusCallback());
71 } 70 }
72 } 71 }
73 72
74 void FileSystemOperation::CreateFile(const GURL& path, 73 void FileSystemOperation::CreateFile(const GURL& path,
75 bool exclusive) { 74 bool exclusive,
75 const StatusCallback& callback) {
76 #ifndef NDEBUG 76 #ifndef NDEBUG
77 DCHECK(kOperationNone == pending_operation_); 77 DCHECK(kOperationNone == pending_operation_);
78 pending_operation_ = kOperationCreateFile; 78 pending_operation_ = kOperationCreateFile;
79 #endif 79 #endif
80 if (!SetupSrcContextForWrite(path, true)) { 80 base::PlatformFileError result = SetupSrcContextForWrite(path, true);
81 if (result != base::PLATFORM_FILE_OK) {
82 callback.Run(result);
81 delete this; 83 delete this;
82 return; 84 return;
83 } 85 }
84 GetUsageAndQuotaThenCallback( 86 GetUsageAndQuotaThenCallback(
85 operation_context_.src_origin_url(), 87 operation_context_.src_origin_url(),
86 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, 88 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
87 base::Unretained(this), exclusive)); 89 base::Unretained(this), callback, exclusive));
88 } 90 }
89 91
90 void FileSystemOperation::DelayedCreateFileForQuota( 92 void FileSystemOperation::DelayedCreateFileForQuota(
93 const StatusCallback& callback,
91 bool exclusive, 94 bool exclusive,
92 quota::QuotaStatusCode status, int64 usage, int64 quota) { 95 quota::QuotaStatusCode status, int64 usage, int64 quota) {
93 operation_context_.set_allowed_bytes_growth(quota - usage); 96 operation_context_.set_allowed_bytes_growth(quota - usage);
94 97
95 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 98 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
96 file_system_context(), 99 file_system_context(),
97 operation_context_.src_origin_url(), 100 operation_context_.src_origin_url(),
98 operation_context_.src_type())); 101 operation_context_.src_type()));
99 102
100 FileSystemFileUtilProxy::RelayEnsureFileExists( 103 FileSystemFileUtilProxy::RelayEnsureFileExists(
101 proxy_, 104 proxy_,
102 base::Bind(&FileSystemFileUtil::EnsureFileExists, 105 base::Bind(&FileSystemFileUtil::EnsureFileExists,
103 base::Unretained(operation_context_.src_file_util()), 106 base::Unretained(operation_context_.src_file_util()),
104 &operation_context_, src_virtual_path_), 107 &operation_context_, src_virtual_path_),
105 base::Bind( 108 base::Bind(
106 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive 109 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
107 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, 110 : &FileSystemOperation::DidEnsureFileExistsNonExclusive,
108 base::Owned(this))); 111 base::Owned(this), callback));
109 } 112 }
110 113
111 void FileSystemOperation::CreateDirectory(const GURL& path, 114 void FileSystemOperation::CreateDirectory(const GURL& path,
112 bool exclusive, 115 bool exclusive,
113 bool recursive) { 116 bool recursive,
117 const StatusCallback& callback) {
114 #ifndef NDEBUG 118 #ifndef NDEBUG
115 DCHECK(kOperationNone == pending_operation_); 119 DCHECK(kOperationNone == pending_operation_);
116 pending_operation_ = kOperationCreateDirectory; 120 pending_operation_ = kOperationCreateDirectory;
117 #endif 121 #endif
118 if (!SetupSrcContextForWrite(path, true)) { 122 base::PlatformFileError result = SetupSrcContextForWrite(path, true);
123 if (result != base::PLATFORM_FILE_OK) {
124 callback.Run(result);
119 delete this; 125 delete this;
120 return; 126 return;
121 } 127 }
122 GetUsageAndQuotaThenCallback( 128 GetUsageAndQuotaThenCallback(
123 operation_context_.src_origin_url(), 129 operation_context_.src_origin_url(),
124 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, 130 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
125 base::Unretained(this), exclusive, recursive)); 131 base::Unretained(this), callback, exclusive, recursive));
126 } 132 }
127 133
128 void FileSystemOperation::DelayedCreateDirectoryForQuota( 134 void FileSystemOperation::DelayedCreateDirectoryForQuota(
135 const StatusCallback& callback,
129 bool exclusive, bool recursive, 136 bool exclusive, bool recursive,
130 quota::QuotaStatusCode status, int64 usage, int64 quota) { 137 quota::QuotaStatusCode status, int64 usage, int64 quota) {
131 operation_context_.set_allowed_bytes_growth(quota - usage); 138 operation_context_.set_allowed_bytes_growth(quota - usage);
132 139
133 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 140 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
134 file_system_context(), 141 file_system_context(),
135 operation_context_.src_origin_url(), 142 operation_context_.src_origin_url(),
136 operation_context_.src_type())); 143 operation_context_.src_type()));
137 144
138 base::FileUtilProxy::RelayFileTask( 145 base::FileUtilProxy::RelayFileTask(
139 proxy_, FROM_HERE, 146 proxy_, FROM_HERE,
140 base::Bind(&FileSystemFileUtil::CreateDirectory, 147 base::Bind(&FileSystemFileUtil::CreateDirectory,
141 base::Unretained(operation_context_.src_file_util()), 148 base::Unretained(operation_context_.src_file_util()),
142 &operation_context_, 149 &operation_context_,
143 src_virtual_path_, exclusive, recursive), 150 src_virtual_path_, exclusive, recursive),
144 base::Bind(&FileSystemOperation::DidFinishFileOperation, 151 base::Bind(&FileSystemOperation::DidFinishFileOperation,
145 base::Owned(this))); 152 base::Owned(this), callback));
146 } 153 }
147 154
148 void FileSystemOperation::Copy(const GURL& src_path, 155 void FileSystemOperation::Copy(const GURL& src_path,
149 const GURL& dest_path) { 156 const GURL& dest_path,
157 const StatusCallback& callback) {
150 #ifndef NDEBUG 158 #ifndef NDEBUG
151 DCHECK(kOperationNone == pending_operation_); 159 DCHECK(kOperationNone == pending_operation_);
152 pending_operation_ = kOperationCopy; 160 pending_operation_ = kOperationCopy;
153 #endif 161 #endif
154 if (!SetupSrcContextForRead(src_path) || 162 base::PlatformFileError result = SetupSrcContextForRead(src_path);
155 !SetupDestContextForWrite(dest_path, true)) { 163 if (result == base::PLATFORM_FILE_OK)
164 result = SetupDestContextForWrite(dest_path, true);
165 if (result != base::PLATFORM_FILE_OK) {
166 callback.Run(result);
156 delete this; 167 delete this;
157 return; 168 return;
158 } 169 }
159 170
160 GetUsageAndQuotaThenCallback( 171 GetUsageAndQuotaThenCallback(
161 operation_context_.dest_origin_url(), 172 operation_context_.dest_origin_url(),
162 base::Bind(&FileSystemOperation::DelayedCopyForQuota, 173 base::Bind(&FileSystemOperation::DelayedCopyForQuota,
163 base::Unretained(this))); 174 base::Unretained(this), callback));
164 } 175 }
165 176
166 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, 177 void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback,
178 quota::QuotaStatusCode status,
167 int64 usage, int64 quota) { 179 int64 usage, int64 quota) {
168 operation_context_.set_allowed_bytes_growth(quota - usage); 180 operation_context_.set_allowed_bytes_growth(quota - usage);
169 181
170 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 182 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
171 file_system_context(), 183 file_system_context(),
172 operation_context_.dest_origin_url(), 184 operation_context_.dest_origin_url(),
173 operation_context_.dest_type())); 185 operation_context_.dest_type()));
174 186
175 base::FileUtilProxy::RelayFileTask( 187 base::FileUtilProxy::RelayFileTask(
176 proxy_, FROM_HERE, 188 proxy_, FROM_HERE,
177 base::Bind(&FileSystemFileUtil::Copy, 189 base::Bind(&FileSystemFileUtil::Copy,
178 base::Unretained(operation_context_.src_file_util()), 190 base::Unretained(operation_context_.src_file_util()),
179 &operation_context_, 191 &operation_context_,
180 src_virtual_path_, dest_virtual_path_), 192 src_virtual_path_, dest_virtual_path_),
181 base::Bind(&FileSystemOperation::DidFinishFileOperation, 193 base::Bind(&FileSystemOperation::DidFinishFileOperation,
182 base::Owned(this))); 194 base::Owned(this), callback));
183 } 195 }
184 196
185 void FileSystemOperation::Move(const GURL& src_path, 197 void FileSystemOperation::Move(const GURL& src_path,
186 const GURL& dest_path) { 198 const GURL& dest_path,
199 const StatusCallback& callback) {
187 #ifndef NDEBUG 200 #ifndef NDEBUG
188 DCHECK(kOperationNone == pending_operation_); 201 DCHECK(kOperationNone == pending_operation_);
189 pending_operation_ = kOperationMove; 202 pending_operation_ = kOperationMove;
190 #endif 203 #endif
191 if (!SetupSrcContextForWrite(src_path, false) || 204 base::PlatformFileError result = SetupSrcContextForWrite(src_path, false);
192 !SetupDestContextForWrite(dest_path, true)) { 205 if (result == base::PLATFORM_FILE_OK)
206 result = SetupDestContextForWrite(dest_path, true);
207 if (result != base::PLATFORM_FILE_OK) {
208 callback.Run(result);
193 delete this; 209 delete this;
194 return; 210 return;
195 } 211 }
196 212
197 GetUsageAndQuotaThenCallback( 213 GetUsageAndQuotaThenCallback(
198 operation_context_.dest_origin_url(), 214 operation_context_.dest_origin_url(),
199 base::Bind(&FileSystemOperation::DelayedMoveForQuota, 215 base::Bind(&FileSystemOperation::DelayedMoveForQuota,
200 base::Unretained(this))); 216 base::Unretained(this), callback));
201 } 217 }
202 218
203 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, 219 void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback,
220 quota::QuotaStatusCode status,
204 int64 usage, int64 quota) { 221 int64 usage, int64 quota) {
205 operation_context_.set_allowed_bytes_growth(quota - usage); 222 operation_context_.set_allowed_bytes_growth(quota - usage);
206 223
207 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 224 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
208 file_system_context(), 225 file_system_context(),
209 operation_context_.dest_origin_url(), 226 operation_context_.dest_origin_url(),
210 operation_context_.dest_type())); 227 operation_context_.dest_type()));
211 228
212 base::FileUtilProxy::RelayFileTask( 229 base::FileUtilProxy::RelayFileTask(
213 proxy_, FROM_HERE, 230 proxy_, FROM_HERE,
214 base::Bind(&FileSystemFileUtil::Move, 231 base::Bind(&FileSystemFileUtil::Move,
215 base::Unretained(operation_context_.src_file_util()), 232 base::Unretained(operation_context_.src_file_util()),
216 &operation_context_, 233 &operation_context_,
217 src_virtual_path_, dest_virtual_path_), 234 src_virtual_path_, dest_virtual_path_),
218 base::Bind(&FileSystemOperation::DidFinishFileOperation, 235 base::Bind(&FileSystemOperation::DidFinishFileOperation,
219 base::Owned(this))); 236 base::Owned(this), callback));
220 } 237 }
221 238
222 void FileSystemOperation::DirectoryExists(const GURL& path) { 239 void FileSystemOperation::DirectoryExists(const GURL& path,
240 const StatusCallback& callback) {
223 #ifndef NDEBUG 241 #ifndef NDEBUG
224 DCHECK(kOperationNone == pending_operation_); 242 DCHECK(kOperationNone == pending_operation_);
225 pending_operation_ = kOperationDirectoryExists; 243 pending_operation_ = kOperationDirectoryExists;
226 #endif 244 #endif
227 if (!SetupSrcContextForRead(path)) { 245 base::PlatformFileError result = SetupSrcContextForRead(path);
246 if (result != base::PLATFORM_FILE_OK) {
247 callback.Run(result);
228 delete this; 248 delete this;
229 return; 249 return;
230 } 250 }
231 251
232 FileSystemFileUtilProxy::RelayGetFileInfo( 252 FileSystemFileUtilProxy::RelayGetFileInfo(
233 proxy_, 253 proxy_,
234 base::Bind(&FileSystemFileUtil::GetFileInfo, 254 base::Bind(&FileSystemFileUtil::GetFileInfo,
235 base::Unretained(operation_context_.src_file_util()), 255 base::Unretained(operation_context_.src_file_util()),
236 &operation_context_, src_virtual_path_), 256 &operation_context_, src_virtual_path_),
237 base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this))); 257 base::Bind(&FileSystemOperation::DidDirectoryExists,
258 base::Owned(this), callback));
238 } 259 }
239 260
240 void FileSystemOperation::FileExists(const GURL& path) { 261 void FileSystemOperation::FileExists(const GURL& path,
262 const StatusCallback& callback) {
241 #ifndef NDEBUG 263 #ifndef NDEBUG
242 DCHECK(kOperationNone == pending_operation_); 264 DCHECK(kOperationNone == pending_operation_);
243 pending_operation_ = kOperationFileExists; 265 pending_operation_ = kOperationFileExists;
244 #endif 266 #endif
245 if (!SetupSrcContextForRead(path)) { 267 base::PlatformFileError result = SetupSrcContextForRead(path);
268 if (result != base::PLATFORM_FILE_OK) {
269 callback.Run(result);
246 delete this; 270 delete this;
247 return; 271 return;
248 } 272 }
249 273
250 FileSystemFileUtilProxy::RelayGetFileInfo( 274 FileSystemFileUtilProxy::RelayGetFileInfo(
251 proxy_, 275 proxy_,
252 base::Bind(&FileSystemFileUtil::GetFileInfo, 276 base::Bind(&FileSystemFileUtil::GetFileInfo,
253 base::Unretained(operation_context_.src_file_util()), 277 base::Unretained(operation_context_.src_file_util()),
254 &operation_context_, src_virtual_path_), 278 &operation_context_, src_virtual_path_),
255 base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this))); 279 base::Bind(&FileSystemOperation::DidFileExists,
280 base::Owned(this), callback));
256 } 281 }
257 282
258 void FileSystemOperation::GetMetadata(const GURL& path) { 283 void FileSystemOperation::GetMetadata(const GURL& path,
284 const GetMetadataCallback& callback) {
259 #ifndef NDEBUG 285 #ifndef NDEBUG
260 DCHECK(kOperationNone == pending_operation_); 286 DCHECK(kOperationNone == pending_operation_);
261 pending_operation_ = kOperationGetMetadata; 287 pending_operation_ = kOperationGetMetadata;
262 #endif 288 #endif
263 if (!SetupSrcContextForRead(path)) { 289 base::PlatformFileError result = SetupSrcContextForRead(path);
290 if (result != base::PLATFORM_FILE_OK) {
291 callback.Run(result, base::PlatformFileInfo(), FilePath());
264 delete this; 292 delete this;
265 return; 293 return;
266 } 294 }
267 295
268 FileSystemFileUtilProxy::RelayGetFileInfo( 296 FileSystemFileUtilProxy::RelayGetFileInfo(
269 proxy_, 297 proxy_,
270 base::Bind(&FileSystemFileUtil::GetFileInfo, 298 base::Bind(&FileSystemFileUtil::GetFileInfo,
271 base::Unretained(operation_context_.src_file_util()), 299 base::Unretained(operation_context_.src_file_util()),
272 &operation_context_, src_virtual_path_), 300 &operation_context_, src_virtual_path_),
273 base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this))); 301 base::Bind(&FileSystemOperation::DidGetMetadata,
302 base::Owned(this), callback));
274 } 303 }
275 304
276 void FileSystemOperation::ReadDirectory(const GURL& path) { 305 void FileSystemOperation::ReadDirectory(const GURL& path,
306 const ReadDirectoryCallback& callback) {
277 #ifndef NDEBUG 307 #ifndef NDEBUG
278 DCHECK(kOperationNone == pending_operation_); 308 DCHECK(kOperationNone == pending_operation_);
279 pending_operation_ = kOperationReadDirectory; 309 pending_operation_ = kOperationReadDirectory;
280 #endif 310 #endif
281 if (!SetupSrcContextForRead(path)) { 311 base::PlatformFileError result = SetupSrcContextForRead(path);
312 if (result != base::PLATFORM_FILE_OK) {
313 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
282 delete this; 314 delete this;
283 return; 315 return;
284 } 316 }
285 317
286 FileSystemFileUtilProxy::RelayReadDirectory( 318 FileSystemFileUtilProxy::RelayReadDirectory(
287 proxy_, 319 proxy_,
288 base::Bind(&FileSystemFileUtil::ReadDirectory, 320 base::Bind(&FileSystemFileUtil::ReadDirectory,
289 base::Unretained(operation_context_.src_file_util()), 321 base::Unretained(operation_context_.src_file_util()),
290 &operation_context_, src_virtual_path_), 322 &operation_context_, src_virtual_path_),
291 base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this))); 323 base::Bind(&FileSystemOperation::DidReadDirectory,
324 base::Owned(this), callback));
292 } 325 }
293 326
294 void FileSystemOperation::Remove(const GURL& path, bool recursive) { 327 void FileSystemOperation::Remove(const GURL& path, bool recursive,
328 const StatusCallback& callback) {
295 #ifndef NDEBUG 329 #ifndef NDEBUG
296 DCHECK(kOperationNone == pending_operation_); 330 DCHECK(kOperationNone == pending_operation_);
297 pending_operation_ = kOperationRemove; 331 pending_operation_ = kOperationRemove;
298 #endif 332 #endif
299 if (!SetupSrcContextForWrite(path, false)) { 333 base::PlatformFileError result = SetupSrcContextForWrite(path, false);
334 if (result != base::PLATFORM_FILE_OK) {
335 callback.Run(result);
300 delete this; 336 delete this;
301 return; 337 return;
302 } 338 }
303 339
304 base::FileUtilProxy::RelayFileTask( 340 base::FileUtilProxy::RelayFileTask(
305 proxy_, FROM_HERE, 341 proxy_, FROM_HERE,
306 base::Bind(&FileSystemFileUtil::Delete, 342 base::Bind(&FileSystemFileUtil::Delete,
307 base::Unretained(operation_context_.src_file_util()), 343 base::Unretained(operation_context_.src_file_util()),
308 &operation_context_, src_virtual_path_, recursive), 344 &operation_context_, src_virtual_path_, recursive),
309 base::Bind(&FileSystemOperation::DidFinishFileOperation, 345 base::Bind(&FileSystemOperation::DidFinishFileOperation,
310 base::Owned(this))); 346 base::Owned(this), callback));
311 } 347 }
312 348
313 void FileSystemOperation::Write( 349 void FileSystemOperation::Write(
314 const net::URLRequestContext* url_request_context, 350 const net::URLRequestContext* url_request_context,
315 const GURL& path, 351 const GURL& path,
316 const GURL& blob_url, 352 const GURL& blob_url,
317 int64 offset) { 353 int64 offset,
354 const WriteCallback& callback) {
318 #ifndef NDEBUG 355 #ifndef NDEBUG
319 DCHECK(kOperationNone == pending_operation_); 356 DCHECK(kOperationNone == pending_operation_);
320 pending_operation_ = kOperationWrite; 357 pending_operation_ = kOperationWrite;
321 #endif 358 #endif
322 if (!SetupSrcContextForWrite(path, true)) { 359 base::PlatformFileError result = SetupSrcContextForWrite(path, true);
360 if (result != base::PLATFORM_FILE_OK) {
361 callback.Run(result, 0, false);
323 delete this; 362 delete this;
324 return; 363 return;
325 } 364 }
326 DCHECK(blob_url.is_valid()); 365 DCHECK(blob_url.is_valid());
327 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); 366 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
367 set_write_callback(callback);
328 blob_request_.reset( 368 blob_request_.reset(
329 new net::URLRequest(blob_url, file_writer_delegate_.get())); 369 new net::URLRequest(blob_url, file_writer_delegate_.get()));
330 blob_request_->set_context(url_request_context); 370 blob_request_->set_context(url_request_context);
331 371
332 GetUsageAndQuotaThenCallback( 372 GetUsageAndQuotaThenCallback(
333 operation_context_.src_origin_url(), 373 operation_context_.src_origin_url(),
334 base::Bind(&FileSystemOperation::DelayedWriteForQuota, 374 base::Bind(&FileSystemOperation::DelayedWriteForQuota,
335 base::Unretained(this))); 375 base::Unretained(this)));
336 } 376 }
337 377
(...skipping 15 matching lines...) Expand all
353 base::Bind(&FileSystemFileUtil::CreateOrOpen, 393 base::Bind(&FileSystemFileUtil::CreateOrOpen,
354 base::Unretained(operation_context_.src_file_util()), 394 base::Unretained(operation_context_.src_file_util()),
355 &operation_context_, src_virtual_path_, file_flags), 395 &operation_context_, src_virtual_path_, file_flags),
356 base::Bind(&FileSystemFileUtil::Close, 396 base::Bind(&FileSystemFileUtil::Close,
357 base::Unretained(operation_context_.src_file_util()), 397 base::Unretained(operation_context_.src_file_util()),
358 &operation_context_), 398 &operation_context_),
359 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, 399 base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
360 base::Unretained(this))); 400 base::Unretained(this)));
361 } 401 }
362 402
363 void FileSystemOperation::Truncate(const GURL& path, int64 length) { 403 void FileSystemOperation::Truncate(const GURL& path, int64 length,
404 const StatusCallback& callback) {
364 #ifndef NDEBUG 405 #ifndef NDEBUG
365 DCHECK(kOperationNone == pending_operation_); 406 DCHECK(kOperationNone == pending_operation_);
366 pending_operation_ = kOperationTruncate; 407 pending_operation_ = kOperationTruncate;
367 #endif 408 #endif
368 if (!SetupSrcContextForWrite(path, false)) { 409 base::PlatformFileError result = SetupSrcContextForWrite(path, false);
410 if (result != base::PLATFORM_FILE_OK) {
411 callback.Run(result);
369 delete this; 412 delete this;
370 return; 413 return;
371 } 414 }
372 GetUsageAndQuotaThenCallback( 415 GetUsageAndQuotaThenCallback(
373 operation_context_.src_origin_url(), 416 operation_context_.src_origin_url(),
374 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, 417 base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
375 base::Unretained(this), length)); 418 base::Unretained(this), callback, length));
376 } 419 }
377 420
378 void FileSystemOperation::DelayedTruncateForQuota(int64 length, 421 void FileSystemOperation::DelayedTruncateForQuota(
379 quota::QuotaStatusCode status, 422 const StatusCallback& callback,
380 int64 usage, int64 quota) { 423 int64 length, quota::QuotaStatusCode status, int64 usage, int64 quota) {
381 operation_context_.set_allowed_bytes_growth(quota - usage); 424 operation_context_.set_allowed_bytes_growth(quota - usage);
382 425
383 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 426 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
384 file_system_context(), 427 file_system_context(),
385 operation_context_.src_origin_url(), 428 operation_context_.src_origin_url(),
386 operation_context_.src_type())); 429 operation_context_.src_type()));
387 430
388 base::FileUtilProxy::RelayFileTask( 431 base::FileUtilProxy::RelayFileTask(
389 proxy_, FROM_HERE, 432 proxy_, FROM_HERE,
390 base::Bind(&FileSystemFileUtil::Truncate, 433 base::Bind(&FileSystemFileUtil::Truncate,
391 base::Unretained(operation_context_.src_file_util()), 434 base::Unretained(operation_context_.src_file_util()),
392 &operation_context_, src_virtual_path_, length), 435 &operation_context_, src_virtual_path_, length),
393 base::Bind(&FileSystemOperation::DidFinishFileOperation, 436 base::Bind(&FileSystemOperation::DidFinishFileOperation,
394 base::Owned(this))); 437 base::Owned(this), callback));
395 } 438 }
396 439
397 void FileSystemOperation::TouchFile(const GURL& path, 440 void FileSystemOperation::TouchFile(const GURL& path,
398 const base::Time& last_access_time, 441 const base::Time& last_access_time,
399 const base::Time& last_modified_time) { 442 const base::Time& last_modified_time,
443 const StatusCallback& callback) {
400 #ifndef NDEBUG 444 #ifndef NDEBUG
401 DCHECK(kOperationNone == pending_operation_); 445 DCHECK(kOperationNone == pending_operation_);
402 pending_operation_ = kOperationTouchFile; 446 pending_operation_ = kOperationTouchFile;
403 #endif 447 #endif
404 if (!SetupSrcContextForWrite(path, true)) { 448 base::PlatformFileError result = SetupSrcContextForWrite(path, true);
449 if (result != base::PLATFORM_FILE_OK) {
450 callback.Run(result);
405 delete this; 451 delete this;
406 return; 452 return;
407 } 453 }
408 454
409 base::FileUtilProxy::RelayFileTask( 455 base::FileUtilProxy::RelayFileTask(
410 proxy_, FROM_HERE, 456 proxy_, FROM_HERE,
411 base::Bind(&FileSystemFileUtil::Touch, 457 base::Bind(&FileSystemFileUtil::Touch,
412 base::Unretained(operation_context_.src_file_util()), 458 base::Unretained(operation_context_.src_file_util()),
413 &operation_context_, 459 &operation_context_,
414 src_virtual_path_, last_access_time, last_modified_time), 460 src_virtual_path_, last_access_time, last_modified_time),
415 base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this))); 461 base::Bind(&FileSystemOperation::DidTouchFile,
462 base::Owned(this), callback));
416 } 463 }
417 464
418 void FileSystemOperation::OpenFile(const GURL& path, 465 void FileSystemOperation::OpenFile(const GURL& path,
419 int file_flags, 466 int file_flags,
420 base::ProcessHandle peer_handle) { 467 base::ProcessHandle peer_handle,
468 const OpenFileCallback& callback) {
421 #ifndef NDEBUG 469 #ifndef NDEBUG
422 DCHECK(kOperationNone == pending_operation_); 470 DCHECK(kOperationNone == pending_operation_);
423 pending_operation_ = kOperationOpenFile; 471 pending_operation_ = kOperationOpenFile;
424 #endif 472 #endif
425 peer_handle_ = peer_handle; 473 peer_handle_ = peer_handle;
426 474
427 if (file_flags & ( 475 if (file_flags & (
428 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | 476 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
429 base::PLATFORM_FILE_HIDDEN))) { 477 base::PLATFORM_FILE_HIDDEN))) {
478 callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
479 base::PlatformFile(), base::ProcessHandle());
430 delete this; 480 delete this;
431 return; 481 return;
432 } 482 }
433 if (file_flags & 483 if (file_flags &
434 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | 484 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS |
435 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | 485 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED |
436 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | 486 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
437 base::PLATFORM_FILE_DELETE_ON_CLOSE | 487 base::PLATFORM_FILE_DELETE_ON_CLOSE |
438 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { 488 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
439 if (!SetupSrcContextForWrite(path, true)) { 489 base::PlatformFileError result = SetupSrcContextForWrite(path, true);
490 if (result != base::PLATFORM_FILE_OK) {
491 callback.Run(result, base::PlatformFile(), base::ProcessHandle());
440 delete this; 492 delete this;
441 return; 493 return;
442 } 494 }
443 } else { 495 } else {
444 if (!SetupSrcContextForRead(path)) { 496 base::PlatformFileError result = SetupSrcContextForRead(path);
497 if (result != base::PLATFORM_FILE_OK) {
498 callback.Run(result, base::PlatformFile(), base::ProcessHandle());
445 delete this; 499 delete this;
446 return; 500 return;
447 } 501 }
448 } 502 }
449 GetUsageAndQuotaThenCallback( 503 GetUsageAndQuotaThenCallback(
450 operation_context_.src_origin_url(), 504 operation_context_.src_origin_url(),
451 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, 505 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
452 base::Unretained(this), file_flags)); 506 base::Unretained(this), callback, file_flags));
453 } 507 }
454 508
455 void FileSystemOperation::DelayedOpenFileForQuota(int file_flags, 509 void FileSystemOperation::DelayedOpenFileForQuota(
456 quota::QuotaStatusCode status, 510 const OpenFileCallback& callback,
457 int64 usage, int64 quota) { 511 int file_flags, quota::QuotaStatusCode status, int64 usage, int64 quota) {
458 operation_context_.set_allowed_bytes_growth(quota - usage); 512 operation_context_.set_allowed_bytes_growth(quota - usage);
459 513
460 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 514 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
461 file_system_context(), 515 file_system_context(),
462 operation_context_.src_origin_url(), 516 operation_context_.src_origin_url(),
463 operation_context_.src_type())); 517 operation_context_.src_type()));
464 518
519 LOG(ERROR) << "DelayedOpenFileforQuota";
kinuko 2012/02/10 05:34:09 This should be removed?
kinaba 2012/02/10 08:22:58 Oops!!111 Right.
465 base::FileUtilProxy::RelayCreateOrOpen( 520 base::FileUtilProxy::RelayCreateOrOpen(
466 proxy_, 521 proxy_,
467 base::Bind(&FileSystemFileUtil::CreateOrOpen, 522 base::Bind(&FileSystemFileUtil::CreateOrOpen,
468 base::Unretained(operation_context_.src_file_util()), 523 base::Unretained(operation_context_.src_file_util()),
469 &operation_context_, 524 &operation_context_,
470 src_virtual_path_, file_flags), 525 src_virtual_path_, file_flags),
471 base::Bind(&FileSystemFileUtil::Close, 526 base::Bind(&FileSystemFileUtil::Close,
472 base::Unretained(operation_context_.src_file_util()), 527 base::Unretained(operation_context_.src_file_util()),
473 &operation_context_), 528 &operation_context_),
474 base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this))); 529 base::Bind(&FileSystemOperation::DidOpenFile,
530 base::Owned(this), callback));
475 } 531 }
476 532
477 // We can only get here on a write or truncate that's not yet completed. 533 // We can only get here on a write or truncate that's not yet completed.
478 // We don't support cancelling any other operation at this time. 534 // We don't support cancelling any other operation at this time.
479 void FileSystemOperation::Cancel( 535 void FileSystemOperation::Cancel(const StatusCallback& cancel_callback) {
480 scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) {
481 if (file_writer_delegate_.get()) { 536 if (file_writer_delegate_.get()) {
482 #ifndef NDEBUG 537 #ifndef NDEBUG
483 DCHECK(kOperationWrite == pending_operation_); 538 DCHECK(kOperationWrite == pending_operation_);
484 #endif 539 #endif
485 // Writes are done without proxying through FileUtilProxy after the initial 540 // Writes are done without proxying through FileUtilProxy after the initial
486 // opening of the PlatformFile. All state changes are done on this thread, 541 // opening of the PlatformFile. All state changes are done on this thread,
487 // so we're guaranteed to be able to shut down atomically. We do need to 542 // so we're guaranteed to be able to shut down atomically. We do need to
488 // check that the file has been opened [which means the blob_request_ has 543 // check that the file has been opened [which means the blob_request_ has
489 // been created], so we know how much we need to do. 544 // been created], so we know how much we need to do.
490 if (blob_request_.get()) 545 if (blob_request_.get())
491 // This halts any calls to file_writer_delegate_ from blob_request_. 546 // This halts any calls to file_writer_delegate_ from blob_request_.
492 blob_request_->Cancel(); 547 blob_request_->Cancel();
493 548
494 if (dispatcher_.get()) 549 // DidWrite deletes this object.
495 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 550 DidWrite(base::PLATFORM_FILE_ERROR_ABORT, 0, false);
496 cancel_dispatcher->DidSucceed(); 551 cancel_callback.Run(base::PLATFORM_FILE_OK);
497 dispatcher_.reset();
498 } else { 552 } else {
499 #ifndef NDEBUG 553 #ifndef NDEBUG
500 DCHECK(kOperationTruncate == pending_operation_); 554 DCHECK(kOperationTruncate == pending_operation_);
501 #endif 555 #endif
502 // We're cancelling a truncate operation, but we can't actually stop it 556 // We're cancelling a truncate operation, but we can't actually stop it
503 // since it's been proxied to another thread. We need to save the 557 // since it's been proxied to another thread. We need to save the
504 // cancel_dispatcher so that when the truncate returns, it can see that it's 558 // cancel_callback so that when the truncate returns, it can see that it's
505 // been cancelled, report it, and report that the cancel has succeeded. 559 // been cancelled, report it, and report that the cancel has succeeded.
506 DCHECK(!cancel_dispatcher_.get()); 560 DCHECK(cancel_callback_.is_null());
507 cancel_dispatcher_ = cancel_dispatcher.Pass(); 561 cancel_callback_ = cancel_callback;
508 } 562 }
509 } 563 }
510 564
511 FileSystemOperation* FileSystemOperation::AsFileSystemOperation() { 565 FileSystemOperation* FileSystemOperation::AsFileSystemOperation() {
512 return this; 566 return this;
513 } 567 }
514 568
515 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, 569 void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
516 FilePath* platform_path) { 570 FilePath* platform_path) {
517 #ifndef NDEBUG 571 #ifndef NDEBUG
518 DCHECK(kOperationNone == pending_operation_); 572 DCHECK(kOperationNone == pending_operation_);
519 pending_operation_ = kOperationGetLocalPath; 573 pending_operation_ = kOperationGetLocalPath;
520 #endif 574 #endif
521 if (!SetupSrcContextForRead(path)) { 575 base::PlatformFileError result = SetupSrcContextForRead(path);
576 if (result != base::PLATFORM_FILE_OK) {
522 delete this; 577 delete this;
523 return; 578 return;
524 } 579 }
525 580
526 operation_context_.src_file_util()->GetLocalFilePath( 581 operation_context_.src_file_util()->GetLocalFilePath(
527 &operation_context_, src_virtual_path_, platform_path); 582 &operation_context_, src_virtual_path_, platform_path);
528 583
529 delete this; 584 delete this;
530 } 585 }
531 586
532 FileSystemOperation::FileSystemOperation( 587 FileSystemOperation::FileSystemOperation(
533 scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
534 scoped_refptr<base::MessageLoopProxy> proxy, 588 scoped_refptr<base::MessageLoopProxy> proxy,
535 FileSystemContext* file_system_context) 589 FileSystemContext* file_system_context)
536 : proxy_(proxy), 590 : proxy_(proxy),
537 dispatcher_(dispatcher.Pass()),
538 operation_context_(file_system_context, NULL), 591 operation_context_(file_system_context, NULL),
539 peer_handle_(base::kNullProcessHandle) { 592 peer_handle_(base::kNullProcessHandle) {
540 #ifndef NDEBUG 593 #ifndef NDEBUG
541 pending_operation_ = kOperationNone; 594 pending_operation_ = kOperationNone;
542 #endif 595 #endif
543 } 596 }
544 597
545 void FileSystemOperation::GetUsageAndQuotaThenCallback( 598 void FileSystemOperation::GetUsageAndQuotaThenCallback(
546 const GURL& origin_url, 599 const GURL& origin_url,
547 const quota::QuotaManager::GetUsageAndQuotaCallback& callback) { 600 const quota::QuotaManager::GetUsageAndQuotaCallback& callback) {
(...skipping 10 matching lines...) Expand all
558 DCHECK(quota_manager_proxy); 611 DCHECK(quota_manager_proxy);
559 DCHECK(quota_manager_proxy->quota_manager()); 612 DCHECK(quota_manager_proxy->quota_manager());
560 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 613 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
561 operation_context_.src_origin_url(), 614 operation_context_.src_origin_url(),
562 FileSystemTypeToQuotaStorageType( 615 FileSystemTypeToQuotaStorageType(
563 operation_context_.src_type()), 616 operation_context_.src_type()),
564 callback); 617 callback);
565 } 618 }
566 619
567 void FileSystemOperation::DidEnsureFileExistsExclusive( 620 void FileSystemOperation::DidEnsureFileExistsExclusive(
621 const StatusCallback& callback,
568 base::PlatformFileError rv, bool created) { 622 base::PlatformFileError rv, bool created) {
569 if (rv == base::PLATFORM_FILE_OK && !created) { 623 if (rv == base::PLATFORM_FILE_OK && !created) {
570 if (dispatcher_.get()) 624 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
571 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS);
572 } else { 625 } else {
573 DidFinishFileOperation(rv); 626 DidFinishFileOperation(callback, rv);
574 } 627 }
575 } 628 }
576 629
577 void FileSystemOperation::DidEnsureFileExistsNonExclusive( 630 void FileSystemOperation::DidEnsureFileExistsNonExclusive(
631 const StatusCallback& callback,
578 base::PlatformFileError rv, bool /* created */) { 632 base::PlatformFileError rv, bool /* created */) {
579 DidFinishFileOperation(rv); 633 DidFinishFileOperation(callback, rv);
580 } 634 }
581 635
582 void FileSystemOperation::DidFinishFileOperation( 636 void FileSystemOperation::DidFinishFileOperation(
637 const StatusCallback& callback,
583 base::PlatformFileError rv) { 638 base::PlatformFileError rv) {
584 if (cancel_dispatcher_.get()) { 639 if (!cancel_callback_.is_null()) {
585 #ifndef NDEBUG 640 #ifndef NDEBUG
586 DCHECK(kOperationTruncate == pending_operation_); 641 DCHECK(kOperationTruncate == pending_operation_);
587 #endif 642 #endif
588 643 callback.Run(base::PLATFORM_FILE_ERROR_ABORT);
589 if (dispatcher_.get()) 644 cancel_callback_.Run(base::PLATFORM_FILE_OK);
590 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 645 cancel_callback_.Reset();
591 cancel_dispatcher_->DidSucceed(); 646 } else {
592 } else if (dispatcher_.get()) { 647 callback.Run(rv);
593 if (rv == base::PLATFORM_FILE_OK)
594 dispatcher_->DidSucceed();
595 else
596 dispatcher_->DidFail(rv);
597 } 648 }
598 } 649 }
599 650
600 void FileSystemOperation::DidDirectoryExists( 651 void FileSystemOperation::DidDirectoryExists(
652 const StatusCallback& callback,
601 base::PlatformFileError rv, 653 base::PlatformFileError rv,
602 const base::PlatformFileInfo& file_info, 654 const base::PlatformFileInfo& file_info,
603 const FilePath& unused) { 655 const FilePath& unused) {
604 if (!dispatcher_.get()) 656 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory)
605 return; 657 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
606 if (rv == base::PLATFORM_FILE_OK) { 658 callback.Run(rv);
607 if (file_info.is_directory)
608 dispatcher_->DidSucceed();
609 else
610 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY);
611 } else {
612 dispatcher_->DidFail(rv);
613 }
614 } 659 }
615 660
616 void FileSystemOperation::DidFileExists( 661 void FileSystemOperation::DidFileExists(
662 const StatusCallback& callback,
617 base::PlatformFileError rv, 663 base::PlatformFileError rv,
618 const base::PlatformFileInfo& file_info, 664 const base::PlatformFileInfo& file_info,
619 const FilePath& unused) { 665 const FilePath& unused) {
620 if (!dispatcher_.get()) 666 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory)
621 return; 667 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE;
622 if (rv == base::PLATFORM_FILE_OK) { 668 callback.Run(rv);
623 if (file_info.is_directory)
624 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE);
625 else
626 dispatcher_->DidSucceed();
627 } else {
628 dispatcher_->DidFail(rv);
629 }
630 } 669 }
631 670
632 void FileSystemOperation::DidGetMetadata( 671 void FileSystemOperation::DidGetMetadata(
672 const GetMetadataCallback& callback,
633 base::PlatformFileError rv, 673 base::PlatformFileError rv,
634 const base::PlatformFileInfo& file_info, 674 const base::PlatformFileInfo& file_info,
635 const FilePath& platform_path) { 675 const FilePath& platform_path) {
636 if (!dispatcher_.get()) 676 callback.Run(rv, file_info, platform_path);
637 return;
638 if (rv == base::PLATFORM_FILE_OK)
639 dispatcher_->DidReadMetadata(file_info, platform_path);
640 else
641 dispatcher_->DidFail(rv);
642 } 677 }
643 678
644 void FileSystemOperation::DidReadDirectory( 679 void FileSystemOperation::DidReadDirectory(
680 const ReadDirectoryCallback& callback,
645 base::PlatformFileError rv, 681 base::PlatformFileError rv,
646 const std::vector<base::FileUtilProxy::Entry>& entries) { 682 const std::vector<base::FileUtilProxy::Entry>& entries) {
647 if (!dispatcher_.get()) 683 callback.Run(rv, entries, false /* has_more */);
648 return;
649
650 if (rv == base::PLATFORM_FILE_OK)
651 dispatcher_->DidReadDirectory(entries, false /* has_more */);
652 else
653 dispatcher_->DidFail(rv);
654 } 684 }
655 685
656 void FileSystemOperation::DidWrite( 686 void FileSystemOperation::DidWrite(
657 base::PlatformFileError rv, 687 base::PlatformFileError rv,
658 int64 bytes, 688 int64 bytes,
659 bool complete) { 689 bool complete) {
660 if (!dispatcher_.get()) { 690 write_callback_.Run(rv, bytes, complete);
661 delete this;
662 return;
663 }
664 if (rv == base::PLATFORM_FILE_OK)
665 dispatcher_->DidWrite(bytes, complete);
666 else
667 dispatcher_->DidFail(rv);
668 if (complete || rv != base::PLATFORM_FILE_OK) 691 if (complete || rv != base::PLATFORM_FILE_OK)
669 delete this; 692 delete this;
670 } 693 }
671 694
672 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { 695 void FileSystemOperation::DidTouchFile(const StatusCallback& callback,
673 if (!dispatcher_.get()) 696 base::PlatformFileError rv) {
674 return; 697 callback.Run(rv);
675 if (rv == base::PLATFORM_FILE_OK)
676 dispatcher_->DidSucceed();
677 else
678 dispatcher_->DidFail(rv);
679 } 698 }
680 699
681 void FileSystemOperation::DidOpenFile( 700 void FileSystemOperation::DidOpenFile(
701 const OpenFileCallback& callback,
682 base::PlatformFileError rv, 702 base::PlatformFileError rv,
683 base::PassPlatformFile file, 703 base::PassPlatformFile file,
684 bool unused) { 704 bool unused) {
685 if (!dispatcher_.get()) 705 if (rv == base::PLATFORM_FILE_OK)
686 return;
687 if (rv == base::PLATFORM_FILE_OK) {
688 CHECK_NE(base::kNullProcessHandle, peer_handle_); 706 CHECK_NE(base::kNullProcessHandle, peer_handle_);
689 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); 707 callback.Run(rv, file.ReleaseValue(), peer_handle_);
690 } else {
691 dispatcher_->DidFail(rv);
692 }
693 } 708 }
694 709
695 void FileSystemOperation::OnFileOpenedForWrite( 710 void FileSystemOperation::OnFileOpenedForWrite(
696 base::PlatformFileError rv, 711 base::PlatformFileError rv,
697 base::PassPlatformFile file, 712 base::PassPlatformFile file,
698 bool created) { 713 bool created) {
699 if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) { 714 if (rv != base::PLATFORM_FILE_OK) {
700 if (dispatcher_.get()) 715 write_callback_.Run(rv, 0, false);
701 dispatcher_->DidFail(rv);
702 delete this; 716 delete this;
703 return; 717 return;
704 } 718 }
705 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); 719 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
706 } 720 }
707 721
708 bool FileSystemOperation::VerifyFileSystemPathForRead( 722 base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead(
709 const GURL& path, GURL* origin_url, FileSystemType* type, 723 const GURL& path, GURL* origin_url, FileSystemType* type,
710 FilePath* virtual_path, FileSystemFileUtil** file_util) { 724 FilePath* virtual_path, FileSystemFileUtil** file_util) {
711 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) 725 base::PlatformFileError rv =
712 return false; 726 VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
727 if (rv != base::PLATFORM_FILE_OK)
728 return rv;
713 729
714 // We notify this read access whether the read access succeeds or not. 730 // We notify this read access whether the read access succeeds or not.
715 // This must be ok since this is used to let the QM's eviction logic know 731 // This must be ok since this is used to let the QM's eviction logic know
716 // someone is interested in reading the origin data and therefore to indicate 732 // someone is interested in reading the origin data and therefore to indicate
717 // that evicting this origin may not be a good idea. 733 // that evicting this origin may not be a good idea.
718 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); 734 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type);
719 if (quota_util) { 735 if (quota_util) {
720 quota_util->NotifyOriginWasAccessedOnIOThread( 736 quota_util->NotifyOriginWasAccessedOnIOThread(
721 file_system_context()->quota_manager_proxy(), 737 file_system_context()->quota_manager_proxy(),
722 *origin_url, 738 *origin_url,
723 *type); 739 *type);
724 } 740 }
725 741
726 return true; 742 return base::PLATFORM_FILE_OK;
727 } 743 }
728 744
729 bool FileSystemOperation::VerifyFileSystemPathForWrite( 745 base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForWrite(
730 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, 746 const GURL& path, bool create, GURL* origin_url, FileSystemType* type,
731 FilePath* virtual_path, FileSystemFileUtil** file_util) { 747 FilePath* virtual_path, FileSystemFileUtil** file_util) {
732 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) 748 base::PlatformFileError rv =
733 return false; 749 VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
750 if (rv != base::PLATFORM_FILE_OK)
751 return rv;
734 752
735 // Any write access is disallowed on the root path. 753 // Any write access is disallowed on the root path.
736 if (virtual_path->value().length() == 0 || 754 if (virtual_path->value().length() == 0 ||
737 virtual_path->DirName().value() == virtual_path->value()) { 755 virtual_path->DirName().value() == virtual_path->value()) {
738 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 756 return base::PLATFORM_FILE_ERROR_SECURITY;
739 return false;
740 } 757 }
741 if (create && 758 if (create &&
742 file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName( 759 file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName(
743 virtual_path->BaseName())) { 760 virtual_path->BaseName())) {
744 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 761 return base::PLATFORM_FILE_ERROR_SECURITY;
745 return false;
746 } 762 }
747 763
748 return true; 764 return base::PLATFORM_FILE_OK;
749 } 765 }
750 766
751 bool FileSystemOperation::VerifyFileSystemPath( 767 base::PlatformFileError FileSystemOperation::VerifyFileSystemPath(
752 const GURL& path, GURL* origin_url, FileSystemType* type, 768 const GURL& path, GURL* origin_url, FileSystemType* type,
753 FilePath* virtual_path, FileSystemFileUtil** file_util) { 769 FilePath* virtual_path, FileSystemFileUtil** file_util) {
754 DCHECK(file_system_context()); 770 DCHECK(file_system_context());
755 771
756 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { 772 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
757 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); 773 return base::PLATFORM_FILE_ERROR_INVALID_URL;
758 return false;
759 } 774 }
760 if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed( 775 if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed(
761 *origin_url, *type, *virtual_path)) { 776 *origin_url, *type, *virtual_path)) {
762 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 777 return base::PLATFORM_FILE_ERROR_SECURITY;
763 return false;
764 } 778 }
765 DCHECK(file_util); 779 DCHECK(file_util);
766 *file_util = file_system_context()->GetFileUtil(*type); 780 *file_util = file_system_context()->GetFileUtil(*type);
767 DCHECK(*file_util); 781 DCHECK(*file_util);
768 782
769 return true; 783 return base::PLATFORM_FILE_OK;
770 } 784 }
771 785
772 bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) { 786 base::PlatformFileError FileSystemOperation::SetupSrcContextForRead(
787 const GURL& path) {
773 GURL origin_url; 788 GURL origin_url;
774 FileSystemType type; 789 FileSystemType type;
775 FileSystemFileUtil* file_util; 790 FileSystemFileUtil* file_util;
776 bool result = VerifyFileSystemPathForRead( 791 base::PlatformFileError result = VerifyFileSystemPathForRead(
777 path, &origin_url, &type, &src_virtual_path_, &file_util); 792 path, &origin_url, &type, &src_virtual_path_, &file_util);
778 operation_context_.set_src_origin_url(origin_url); 793 operation_context_.set_src_origin_url(origin_url);
779 operation_context_.set_src_type(type); 794 operation_context_.set_src_type(type);
780 if (!operation_context_.src_file_util()) 795 if (!operation_context_.src_file_util())
781 operation_context_.set_src_file_util(file_util); 796 operation_context_.set_src_file_util(file_util);
782 return result; 797 return result;
783 } 798 }
784 799
785 bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path, 800 base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite(
786 bool create) { 801 const GURL& path,
802 bool create) {
787 GURL origin_url; 803 GURL origin_url;
788 FileSystemType type; 804 FileSystemType type;
789 FileSystemFileUtil* file_util = NULL; 805 FileSystemFileUtil* file_util = NULL;
790 bool result = VerifyFileSystemPathForWrite( 806 base::PlatformFileError result = VerifyFileSystemPathForWrite(
791 path, create, &origin_url, &type, &src_virtual_path_, &file_util); 807 path, create, &origin_url, &type, &src_virtual_path_, &file_util);
792 operation_context_.set_src_origin_url(origin_url); 808 operation_context_.set_src_origin_url(origin_url);
793 operation_context_.set_src_type(type); 809 operation_context_.set_src_type(type);
794 if (!operation_context_.src_file_util()) 810 if (!operation_context_.src_file_util())
795 operation_context_.set_src_file_util(file_util); 811 operation_context_.set_src_file_util(file_util);
796 return result; 812 return result;
797 } 813 }
798 814
799 bool FileSystemOperation::SetupDestContextForWrite(const GURL& path, 815 base::PlatformFileError FileSystemOperation::SetupDestContextForWrite(
800 bool create) { 816 const GURL& path,
817 bool create) {
801 GURL origin_url; 818 GURL origin_url;
802 FileSystemType type; 819 FileSystemType type;
803 FileSystemFileUtil* file_util = NULL; 820 FileSystemFileUtil* file_util = NULL;
804 bool result = VerifyFileSystemPathForWrite( 821 base::PlatformFileError result = VerifyFileSystemPathForWrite(
805 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); 822 path, create, &origin_url, &type, &dest_virtual_path_, &file_util);
806 operation_context_.set_dest_origin_url(origin_url); 823 operation_context_.set_dest_origin_url(origin_url);
807 operation_context_.set_dest_type(type); 824 operation_context_.set_dest_type(type);
808 if (!operation_context_.dest_file_util()) 825 if (!operation_context_.dest_file_util())
809 operation_context_.set_dest_file_util(file_util); 826 operation_context_.set_dest_file_util(file_util);
810 return result; 827 return result;
811 } 828 }
812 829
813 } // namespace fileapi 830 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698