Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / storage / browser / fileapi / quota / quota_reservation_manager.cc
blobb5ee5d8705569d8d5072426a89ca5ca82abf1956
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"
10 namespace storage {
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(
24 const GURL& origin,
25 FileSystemType type,
26 int64 size,
27 const ReserveQuotaCallback& callback) {
28 DCHECK(origin.is_valid());
29 backend_->ReserveQuota(origin, type, size, callback);
32 void QuotaReservationManager::ReleaseReservedQuota(
33 const GURL& origin,
34 FileSystemType type,
35 int64 size) {
36 DCHECK(origin.is_valid());
37 backend_->ReleaseReservedQuota(origin, type, size);
40 void QuotaReservationManager::CommitQuotaUsage(
41 const GURL& origin,
42 FileSystemType type,
43 int64 delta) {
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(
62 const GURL& origin,
63 FileSystemType type) {
64 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
65 DCHECK(origin.is_valid());
66 QuotaReservationBuffer** buffer =
67 &reservation_buffers_[std::make_pair(origin, type)];
68 if (!*buffer) {
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(
85 const GURL& origin,
86 FileSystemType type) {
87 DCHECK(origin.is_valid());
88 return GetReservationBuffer(origin, type)->CreateReservation();;
91 } // namespace storage