| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 scoped_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( | 32 scoped_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( |
| 33 QuotaReservation* reservation, | 33 QuotaReservation* reservation, |
| 34 const base::FilePath& platform_path) { | 34 const base::FilePath& platform_path) { |
| 35 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 35 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 36 OpenFileHandleContext** open_file = &open_files_[platform_path]; | 36 OpenFileHandleContext** open_file = &open_files_[platform_path]; |
| 37 if (!*open_file) | 37 if (!*open_file) |
| 38 *open_file = new OpenFileHandleContext(platform_path, this); | 38 *open_file = new OpenFileHandleContext(platform_path, this); |
| 39 return make_scoped_ptr(new OpenFileHandle(reservation, *open_file)); | 39 return make_scoped_ptr(new OpenFileHandle(reservation, *open_file)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption, | 42 void QuotaReservationBuffer::CommitFileGrowth(int64 reserved_quota_consumption, |
| 43 int64 usage_delta) { | 43 int64 usage_delta) { |
| 44 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 44 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 45 if (!reservation_manager_) | 45 if (!reservation_manager_) |
| 46 return; | 46 return; |
| 47 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta); | 47 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta); |
| 48 | 48 |
| 49 if (quota_consumption > 0) { | 49 if (reserved_quota_consumption > 0) { |
| 50 if (quota_consumption > reserved_quota_) { | 50 if (reserved_quota_consumption > reserved_quota_) { |
| 51 LOG(ERROR) << "Detected over consumption of the storage quota beyond its" | 51 LOG(ERROR) << "Detected over consumption of the storage quota beyond its" |
| 52 << " reservation"; | 52 << " reservation"; |
| 53 quota_consumption = reserved_quota_; | 53 reserved_quota_consumption = reserved_quota_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 reserved_quota_ -= quota_consumption; | 56 reserved_quota_ -= reserved_quota_consumption; |
| 57 reservation_manager_->ReleaseReservedQuota( | 57 reservation_manager_->ReleaseReservedQuota( |
| 58 origin_, type_, quota_consumption); | 58 origin_, type_, reserved_quota_consumption); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 void QuotaReservationBuffer::DetachOpenFileHandleContext( | 62 void QuotaReservationBuffer::DetachOpenFileHandleContext( |
| 63 OpenFileHandleContext* open_file) { | 63 OpenFileHandleContext* open_file) { |
| 64 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 64 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 65 DCHECK_EQ(open_file, open_files_[open_file->platform_path()]); | 65 DCHECK_EQ(open_file, open_files_[open_file->platform_path()]); |
| 66 open_files_.erase(open_file->platform_path()); | 66 open_files_.erase(open_file->platform_path()); |
| 67 } | 67 } |
| 68 | 68 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 DCHECK(origin.is_valid()); | 96 DCHECK(origin.is_valid()); |
| 97 if (error == base::PLATFORM_FILE_OK && reservation_manager) { | 97 if (error == base::PLATFORM_FILE_OK && reservation_manager) { |
| 98 reservation_manager->DecrementDirtyCount(origin, type); | 98 reservation_manager->DecrementDirtyCount(origin, type); |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 } // namespace fileapi | 105 } // namespace fileapi |
| OLD | NEW |