OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
11 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
12 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
13 #include "webkit/fileapi/file_system_file_util_proxy.h" | 13 #include "webkit/fileapi/file_system_file_util_proxy.h" |
14 #include "webkit/fileapi/file_system_operation_context.h" | 14 #include "webkit/fileapi/file_system_operation_context.h" |
15 #include "webkit/fileapi/file_system_path_manager.h" | 15 #include "webkit/fileapi/file_system_path_manager.h" |
16 #include "webkit/fileapi/file_system_quota_util.h" | 16 #include "webkit/fileapi/file_system_quota_util.h" |
17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
18 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
19 #include "webkit/fileapi/file_writer_delegate.h" | 19 #include "webkit/fileapi/file_writer_delegate.h" |
20 #include "webkit/fileapi/local_file_system_file_util.h" | 20 #include "webkit/fileapi/local_file_system_file_util.h" |
21 #include "webkit/fileapi/quota_file_util.h" | 21 #include "webkit/fileapi/quota_file_util.h" |
22 #include "webkit/quota/quota_types.h" | 22 #include "webkit/quota/quota_types.h" |
23 | 23 |
24 namespace fileapi { | 24 namespace fileapi { |
25 | 25 |
26 FileSystemOperation::ScopedQuotaUtilHelper::ScopedQuotaUtilHelper( | |
27 FileSystemContext* context, const GURL& origin_url, FileSystemType type) | |
28 : origin_url_(origin_url), type_(type) { | |
29 DCHECK(context); | |
30 DCHECK(type != kFileSystemTypeUnknown); | |
31 quota_util_ = context->GetQuotaUtil(type_); | |
32 if (quota_util_) { | |
33 DCHECK(quota_util_->proxy()); | |
34 quota_util_->proxy()->StartUpdateOrigin(origin_url_, type_); | |
35 } | |
36 } | |
37 | |
38 FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() { | |
39 if (quota_util_) { | |
40 DCHECK(quota_util_->proxy()); | |
41 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); | |
42 } | |
43 } | |
44 | |
26 FileSystemOperation::FileSystemOperation( | 45 FileSystemOperation::FileSystemOperation( |
27 FileSystemCallbackDispatcher* dispatcher, | 46 FileSystemCallbackDispatcher* dispatcher, |
28 scoped_refptr<base::MessageLoopProxy> proxy, | 47 scoped_refptr<base::MessageLoopProxy> proxy, |
29 FileSystemContext* file_system_context, | 48 FileSystemContext* file_system_context, |
30 FileSystemFileUtil* file_system_file_util) | 49 FileSystemFileUtil* file_system_file_util) |
31 : proxy_(proxy), | 50 : proxy_(proxy), |
32 dispatcher_(dispatcher), | 51 dispatcher_(dispatcher), |
33 file_system_operation_context_( | 52 file_system_operation_context_( |
34 file_system_context, file_system_file_util), | 53 file_system_context, file_system_file_util), |
35 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 54 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 void FileSystemOperation::DelayedCreateFileForQuota( | 118 void FileSystemOperation::DelayedCreateFileForQuota( |
100 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 119 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
101 if (file_system_context()->IsStorageUnlimited( | 120 if (file_system_context()->IsStorageUnlimited( |
102 file_system_operation_context()->src_origin_url()) || | 121 file_system_operation_context()->src_origin_url()) || |
103 quota == QuotaFileUtil::kNoLimit) { | 122 quota == QuotaFileUtil::kNoLimit) { |
104 file_system_operation_context_.set_allowed_bytes_growth( | 123 file_system_operation_context_.set_allowed_bytes_growth( |
105 QuotaFileUtil::kNoLimit); | 124 QuotaFileUtil::kNoLimit); |
106 } else { | 125 } else { |
107 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 126 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
108 } | 127 } |
128 | |
129 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
130 file_system_context(), | |
131 file_system_operation_context_.src_origin_url(), | |
132 file_system_operation_context_.src_type())); | |
133 | |
109 FileSystemFileUtilProxy::EnsureFileExists( | 134 FileSystemFileUtilProxy::EnsureFileExists( |
110 file_system_operation_context_, | 135 file_system_operation_context_, |
111 proxy_, | 136 proxy_, |
112 file_system_operation_context_.src_virtual_path(), | 137 file_system_operation_context_.src_virtual_path(), |
113 callback_factory_.NewCallback( | 138 callback_factory_.NewCallback( |
114 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive | 139 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive |
115 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); | 140 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); |
116 } | 141 } |
117 | 142 |
118 void FileSystemOperation::CreateDirectory(const GURL& path, | 143 void FileSystemOperation::CreateDirectory(const GURL& path, |
(...skipping 30 matching lines...) Expand all Loading... | |
149 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 174 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
150 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 175 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
151 if (file_system_context()->IsStorageUnlimited( | 176 if (file_system_context()->IsStorageUnlimited( |
152 file_system_operation_context()->src_origin_url()) || | 177 file_system_operation_context()->src_origin_url()) || |
153 quota == QuotaFileUtil::kNoLimit) { | 178 quota == QuotaFileUtil::kNoLimit) { |
154 file_system_operation_context_.set_allowed_bytes_growth( | 179 file_system_operation_context_.set_allowed_bytes_growth( |
155 QuotaFileUtil::kNoLimit); | 180 QuotaFileUtil::kNoLimit); |
156 } else { | 181 } else { |
157 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 182 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
158 } | 183 } |
184 | |
185 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
ericu
2011/08/19 04:12:59
This feels a bit odd here, given that many filesys
Dai Mikurube (NOT FULLTIME)
2011/08/19 10:21:10
I basically agree with that, but I guess it has a
kinuko
2011/08/19 11:13:08
I'm ok with eric's proposal iff we can make sure t
| |
186 file_system_context(), | |
187 file_system_operation_context_.src_origin_url(), | |
188 file_system_operation_context_.src_type())); | |
189 | |
159 FileSystemFileUtilProxy::CreateDirectory( | 190 FileSystemFileUtilProxy::CreateDirectory( |
160 file_system_operation_context_, | 191 file_system_operation_context_, |
161 proxy_, | 192 proxy_, |
162 file_system_operation_context_.src_virtual_path(), | 193 file_system_operation_context_.src_virtual_path(), |
163 exclusive_, | 194 exclusive_, |
164 recursive_, | 195 recursive_, |
165 callback_factory_.NewCallback( | 196 callback_factory_.NewCallback( |
166 &FileSystemOperation::DidFinishFileOperation)); | 197 &FileSystemOperation::DidFinishFileOperation)); |
167 } | 198 } |
168 | 199 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 240 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
210 int64 usage, int64 quota) { | 241 int64 usage, int64 quota) { |
211 if (file_system_context()->IsStorageUnlimited( | 242 if (file_system_context()->IsStorageUnlimited( |
212 file_system_operation_context()->dest_origin_url()) || | 243 file_system_operation_context()->dest_origin_url()) || |
213 quota == QuotaFileUtil::kNoLimit) { | 244 quota == QuotaFileUtil::kNoLimit) { |
214 file_system_operation_context_.set_allowed_bytes_growth( | 245 file_system_operation_context_.set_allowed_bytes_growth( |
215 QuotaFileUtil::kNoLimit); | 246 QuotaFileUtil::kNoLimit); |
216 } else { | 247 } else { |
217 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 248 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
218 } | 249 } |
250 | |
251 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
252 file_system_context(), | |
253 file_system_operation_context_.dest_origin_url(), | |
254 file_system_operation_context_.dest_type())); | |
255 | |
219 FileSystemFileUtilProxy::Copy( | 256 FileSystemFileUtilProxy::Copy( |
220 file_system_operation_context_, | 257 file_system_operation_context_, |
221 proxy_, | 258 proxy_, |
222 file_system_operation_context_.src_virtual_path(), | 259 file_system_operation_context_.src_virtual_path(), |
223 file_system_operation_context_.dest_virtual_path(), | 260 file_system_operation_context_.dest_virtual_path(), |
224 callback_factory_.NewCallback( | 261 callback_factory_.NewCallback( |
225 &FileSystemOperation::DidFinishFileOperation)); | 262 &FileSystemOperation::DidFinishFileOperation)); |
226 } | 263 } |
227 | 264 |
228 void FileSystemOperation::Move(const GURL& src_path, | 265 void FileSystemOperation::Move(const GURL& src_path, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 305 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
269 int64 usage, int64 quota) { | 306 int64 usage, int64 quota) { |
270 if (file_system_context()->IsStorageUnlimited( | 307 if (file_system_context()->IsStorageUnlimited( |
271 file_system_operation_context()->dest_origin_url()) || | 308 file_system_operation_context()->dest_origin_url()) || |
272 quota == QuotaFileUtil::kNoLimit) { | 309 quota == QuotaFileUtil::kNoLimit) { |
273 file_system_operation_context_.set_allowed_bytes_growth( | 310 file_system_operation_context_.set_allowed_bytes_growth( |
274 QuotaFileUtil::kNoLimit); | 311 QuotaFileUtil::kNoLimit); |
275 } else { | 312 } else { |
276 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 313 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
277 } | 314 } |
315 | |
316 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
317 file_system_context(), | |
318 file_system_operation_context_.dest_origin_url(), | |
319 file_system_operation_context_.dest_type())); | |
320 | |
278 FileSystemFileUtilProxy::Move( | 321 FileSystemFileUtilProxy::Move( |
279 file_system_operation_context_, | 322 file_system_operation_context_, |
280 proxy_, | 323 proxy_, |
281 file_system_operation_context_.src_virtual_path(), | 324 file_system_operation_context_.src_virtual_path(), |
282 file_system_operation_context_.dest_virtual_path(), | 325 file_system_operation_context_.dest_virtual_path(), |
283 callback_factory_.NewCallback( | 326 callback_factory_.NewCallback( |
284 &FileSystemOperation::DidFinishFileOperation)); | 327 &FileSystemOperation::DidFinishFileOperation)); |
285 } | 328 } |
286 | 329 |
287 void FileSystemOperation::DirectoryExists(const GURL& path) { | 330 void FileSystemOperation::DirectoryExists(const GURL& path) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 494 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
452 int64 usage, int64 quota) { | 495 int64 usage, int64 quota) { |
453 if (file_system_context()->IsStorageUnlimited( | 496 if (file_system_context()->IsStorageUnlimited( |
454 file_system_operation_context()->src_origin_url()) || | 497 file_system_operation_context()->src_origin_url()) || |
455 quota == QuotaFileUtil::kNoLimit) { | 498 quota == QuotaFileUtil::kNoLimit) { |
456 file_system_operation_context_.set_allowed_bytes_growth( | 499 file_system_operation_context_.set_allowed_bytes_growth( |
457 QuotaFileUtil::kNoLimit); | 500 QuotaFileUtil::kNoLimit); |
458 } else { | 501 } else { |
459 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 502 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
460 } | 503 } |
504 | |
505 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
506 file_system_context(), | |
507 file_system_operation_context_.src_origin_url(), | |
508 file_system_operation_context_.src_type())); | |
509 | |
461 FileSystemFileUtilProxy::CreateOrOpen( | 510 FileSystemFileUtilProxy::CreateOrOpen( |
462 file_system_operation_context_, | 511 file_system_operation_context_, |
463 proxy_, | 512 proxy_, |
464 file_system_operation_context_.src_virtual_path(), | 513 file_system_operation_context_.src_virtual_path(), |
465 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 514 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
466 base::PLATFORM_FILE_ASYNC, | 515 base::PLATFORM_FILE_ASYNC, |
467 callback_factory_.NewCallback( | 516 callback_factory_.NewCallback( |
468 &FileSystemOperation::OnFileOpenedForWrite)); | 517 &FileSystemOperation::OnFileOpenedForWrite)); |
469 } | 518 } |
470 | 519 |
(...skipping 26 matching lines...) Expand all Loading... | |
497 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 546 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
498 int64 usage, int64 quota) { | 547 int64 usage, int64 quota) { |
499 if (file_system_context()->IsStorageUnlimited( | 548 if (file_system_context()->IsStorageUnlimited( |
500 file_system_operation_context()->src_origin_url()) || | 549 file_system_operation_context()->src_origin_url()) || |
501 quota == QuotaFileUtil::kNoLimit) { | 550 quota == QuotaFileUtil::kNoLimit) { |
502 file_system_operation_context_.set_allowed_bytes_growth( | 551 file_system_operation_context_.set_allowed_bytes_growth( |
503 QuotaFileUtil::kNoLimit); | 552 QuotaFileUtil::kNoLimit); |
504 } else { | 553 } else { |
505 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 554 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
506 } | 555 } |
556 | |
557 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
558 file_system_context(), | |
559 file_system_operation_context_.src_origin_url(), | |
560 file_system_operation_context_.src_type())); | |
561 | |
507 FileSystemFileUtilProxy::Truncate( | 562 FileSystemFileUtilProxy::Truncate( |
508 file_system_operation_context_, | 563 file_system_operation_context_, |
509 proxy_, | 564 proxy_, |
510 file_system_operation_context_.src_virtual_path(), | 565 file_system_operation_context_.src_virtual_path(), |
511 length_, callback_factory_.NewCallback( | 566 length_, callback_factory_.NewCallback( |
512 &FileSystemOperation::DidFinishFileOperation)); | 567 &FileSystemOperation::DidFinishFileOperation)); |
513 } | 568 } |
514 | 569 |
515 void FileSystemOperation::TouchFile(const GURL& path, | 570 void FileSystemOperation::TouchFile(const GURL& path, |
516 const base::Time& last_access_time, | 571 const base::Time& last_access_time, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 int64 usage, int64 quota) { | 648 int64 usage, int64 quota) { |
594 if (file_system_context()->IsStorageUnlimited( | 649 if (file_system_context()->IsStorageUnlimited( |
595 file_system_operation_context()->dest_origin_url()) || | 650 file_system_operation_context()->dest_origin_url()) || |
596 quota == QuotaFileUtil::kNoLimit) { | 651 quota == QuotaFileUtil::kNoLimit) { |
597 file_system_operation_context_.set_allowed_bytes_growth( | 652 file_system_operation_context_.set_allowed_bytes_growth( |
598 QuotaFileUtil::kNoLimit); | 653 QuotaFileUtil::kNoLimit); |
599 } else { | 654 } else { |
600 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 655 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
601 } | 656 } |
602 | 657 |
658 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
659 file_system_context(), | |
660 file_system_operation_context_.src_origin_url(), | |
661 file_system_operation_context_.src_type())); | |
662 | |
603 FileSystemFileUtilProxy::CreateOrOpen( | 663 FileSystemFileUtilProxy::CreateOrOpen( |
604 file_system_operation_context_, | 664 file_system_operation_context_, |
605 proxy_, | 665 proxy_, |
606 file_system_operation_context_.src_virtual_path(), | 666 file_system_operation_context_.src_virtual_path(), |
607 file_flags_, | 667 file_flags_, |
608 callback_factory_.NewCallback( | 668 callback_factory_.NewCallback( |
609 &FileSystemOperation::DidOpenFile)); | 669 &FileSystemOperation::DidOpenFile)); |
610 } | 670 } |
611 | 671 |
612 // We can only get here on a write or truncate that's not yet completed. | 672 // We can only get here on a write or truncate that's not yet completed. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 } | 974 } |
915 DCHECK(file_system_file_util); | 975 DCHECK(file_system_file_util); |
916 *file_system_file_util = | 976 *file_system_file_util = |
917 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 977 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); |
918 DCHECK(*file_system_file_util); | 978 DCHECK(*file_system_file_util); |
919 | 979 |
920 return true; | 980 return true; |
921 } | 981 } |
922 | 982 |
923 } // namespace fileapi | 983 } // namespace fileapi |
OLD | NEW |