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
3 // found in the LICENSE file.
5 #include "storage/browser/fileapi/quota/quota_reservation_manager.h"
7 #include "storage/browser/fileapi/quota/quota_reservation.h"
8 #include "storage/browser/fileapi/quota/quota_reservation_buffer.h"
12 QuotaReservationManager::QuotaReservationManager(
13 scoped_ptr
<QuotaBackend
> backend
)
14 : backend_(backend
.Pass()),
15 weak_ptr_factory_(this) {
16 sequence_checker_
.DetachFromSequence();
19 QuotaReservationManager::~QuotaReservationManager() {
20 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
23 void QuotaReservationManager::ReserveQuota(
27 const ReserveQuotaCallback
& callback
) {
28 DCHECK(origin
.is_valid());
29 backend_
->ReserveQuota(origin
, type
, size
, callback
);
32 void QuotaReservationManager::ReleaseReservedQuota(
36 DCHECK(origin
.is_valid());
37 backend_
->ReleaseReservedQuota(origin
, type
, size
);
40 void QuotaReservationManager::CommitQuotaUsage(
44 DCHECK(origin
.is_valid());
45 backend_
->CommitQuotaUsage(origin
, type
, delta
);
48 void QuotaReservationManager::IncrementDirtyCount(const GURL
& origin
,
49 FileSystemType type
) {
50 DCHECK(origin
.is_valid());
51 backend_
->IncrementDirtyCount(origin
, type
);
54 void QuotaReservationManager::DecrementDirtyCount(const GURL
& origin
,
55 FileSystemType type
) {
56 DCHECK(origin
.is_valid());
57 backend_
->DecrementDirtyCount(origin
, type
);
60 scoped_refptr
<QuotaReservationBuffer
>
61 QuotaReservationManager::GetReservationBuffer(
63 FileSystemType type
) {
64 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
65 DCHECK(origin
.is_valid());
66 QuotaReservationBuffer
** buffer
=
67 &reservation_buffers_
[std::make_pair(origin
, type
)];
69 *buffer
= new QuotaReservationBuffer(
70 weak_ptr_factory_
.GetWeakPtr(), origin
, type
);
72 return make_scoped_refptr(*buffer
);
75 void QuotaReservationManager::ReleaseReservationBuffer(
76 QuotaReservationBuffer
* reservation_buffer
) {
77 DCHECK(sequence_checker_
.CalledOnValidSequencedThread());
78 std::pair
<GURL
, FileSystemType
> key(reservation_buffer
->origin(),
79 reservation_buffer
->type());
80 DCHECK_EQ(reservation_buffers_
[key
], reservation_buffer
);
81 reservation_buffers_
.erase(key
);
84 scoped_refptr
<QuotaReservation
> QuotaReservationManager::CreateReservation(
86 FileSystemType type
) {
87 DCHECK(origin
.is_valid());
88 return GetReservationBuffer(origin
, type
)->CreateReservation();;
91 } // namespace storage