| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h" | 5 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "webkit/browser/fileapi/quota/open_file_handle.h" | 8 #include "webkit/browser/fileapi/quota/open_file_handle.h" |
| 9 #include "webkit/browser/fileapi/quota/open_file_handle_context.h" | 9 #include "webkit/browser/fileapi/quota/open_file_handle_context.h" |
| 10 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 10 #include "webkit/browser/fileapi/quota/quota_reservation.h" |
| 11 | 11 |
| 12 namespace fileapi { | 12 namespace fileapi { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void IgnoreResult(base::PlatformFileError error) {} | 16 void IgnoreResult(base::PlatformFileError error) {} |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 QuotaReservationBuffer::QuotaReservationBuffer( | 20 QuotaReservationBuffer::QuotaReservationBuffer( |
| 21 base::WeakPtr<QuotaReservationManager> reservation_manager, | 21 base::WeakPtr<QuotaReservationManager> reservation_manager, |
| 22 const GURL& origin, | 22 const GURL& origin, |
| 23 FileSystemType type) | 23 FileSystemType type) |
| 24 : reservation_manager_(reservation_manager), | 24 : reservation_manager_(reservation_manager), |
| 25 origin_(origin), | 25 origin_(origin), |
| 26 type_(type), | 26 type_(type), |
| 27 reserved_quota_(0) { | 27 reserved_quota_(0) { |
| 28 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 28 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 29 reservation_manager_->IncrementDirtyCount(origin, type); | 29 reservation_manager_->IncreaseDirtyCount(origin, type); |
| 30 } | 30 } |
| 31 | 31 |
| 32 scoped_refptr<QuotaReservation> QuotaReservationBuffer::CreateReservation() { | 32 scoped_refptr<QuotaReservation> QuotaReservationBuffer::CreateReservation() { |
| 33 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 33 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 34 return make_scoped_refptr(new QuotaReservation(this)); | 34 return make_scoped_refptr(new QuotaReservation(this)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 scoped_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( | 37 scoped_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( |
| 38 QuotaReservation* reservation, | 38 QuotaReservation* reservation, |
| 39 const base::FilePath& platform_path) { | 39 const base::FilePath& platform_path) { |
| 40 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 40 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 41 OpenFileHandleContext** open_file = &open_files_[platform_path]; | 41 OpenFileHandleContext** open_file = &open_files_[platform_path]; |
| 42 if (!*open_file) | 42 if (!*open_file) |
| 43 *open_file = new OpenFileHandleContext(platform_path, this); | 43 *open_file = new OpenFileHandleContext(platform_path, this); |
| 44 return make_scoped_ptr(new OpenFileHandle(reservation, *open_file)); | 44 return make_scoped_ptr(new OpenFileHandle(reservation, *open_file)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption, | 47 void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption, |
| 48 int64 usage_delta) { | 48 int64 usage_delta) { |
| 49 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 49 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 50 if (!reservation_manager_) | 50 if (!reservation_manager_) |
| 51 return; | 51 return; |
| 52 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta); | 52 |
| 53 reservation_manager_->CommitQuotaUsage( |
| 54 origin_, type_, usage_delta, |
| 55 base::Bind(&IgnoreResult)); |
| 53 | 56 |
| 54 DCHECK_LE(quota_consumption, reserved_quota_); | 57 DCHECK_LE(quota_consumption, reserved_quota_); |
| 55 if (quota_consumption > 0) { | 58 if (quota_consumption > 0) { |
| 56 reserved_quota_ -= quota_consumption; | 59 reserved_quota_ -= quota_consumption; |
| 57 reservation_manager_->ReleaseReservedQuota( | 60 reservation_manager_->ReleaseReservedQuota( |
| 58 origin_, type_, quota_consumption); | 61 origin_, type_, quota_consumption); |
| 59 } | 62 } |
| 60 } | 63 } |
| 61 | 64 |
| 62 void QuotaReservationBuffer::DetachOpenFileHandleContext( | 65 void QuotaReservationBuffer::DetachOpenFileHandleContext( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 | 77 |
| 75 QuotaReservationBuffer::~QuotaReservationBuffer() { | 78 QuotaReservationBuffer::~QuotaReservationBuffer() { |
| 76 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 79 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 77 if (!reservation_manager_) | 80 if (!reservation_manager_) |
| 78 return; | 81 return; |
| 79 | 82 |
| 80 DCHECK_LE(0, reserved_quota_); | 83 DCHECK_LE(0, reserved_quota_); |
| 81 if (reserved_quota_ && reservation_manager_) { | 84 if (reserved_quota_ && reservation_manager_) { |
| 82 reservation_manager_->ReserveQuota( | 85 reservation_manager_->ReserveQuota( |
| 83 origin_, type_, -reserved_quota_, | 86 origin_, type_, -reserved_quota_, |
| 84 base::Bind(&QuotaReservationBuffer::DecrementDirtyCount, | 87 base::Bind(&QuotaReservationBuffer::DecreaseDirtyCount, |
| 85 reservation_manager_, origin_, type_)); | 88 reservation_manager_, origin_, type_)); |
| 86 } | 89 } |
| 87 reservation_manager_->ReleaseReservationBuffer(this); | 90 reservation_manager_->ReleaseReservationBuffer(this); |
| 88 } | 91 } |
| 89 | 92 |
| 90 // static | 93 // static |
| 91 bool QuotaReservationBuffer::DecrementDirtyCount( | 94 bool QuotaReservationBuffer::DecreaseDirtyCount( |
| 92 base::WeakPtr<QuotaReservationManager> reservation_manager, | 95 base::WeakPtr<QuotaReservationManager> reservation_manager, |
| 93 const GURL& origin, | 96 const GURL& origin, |
| 94 FileSystemType type, | 97 FileSystemType type, |
| 95 base::PlatformFileError error) { | 98 base::PlatformFileError error) { |
| 96 if (error == base::PLATFORM_FILE_OK && reservation_manager) { | 99 if (error == base::PLATFORM_FILE_OK && reservation_manager) { |
| 97 reservation_manager->DecrementDirtyCount(origin, type); | 100 reservation_manager->DecreaseDirtyCount(origin, type); |
| 98 return true; | 101 return true; |
| 99 } | 102 } |
| 100 return false; | 103 return false; |
| 101 } | 104 } |
| 102 | 105 |
| 103 | 106 |
| 104 } // namespace fileapi | 107 } // namespace fileapi |
| OLD | NEW |