net cleanup: Remove unnecessary namespace prefixes.
[chromium-blink-merge.git] / storage / browser / fileapi / quota / quota_reservation_manager.h
blobec042452e0272a11fda1c3eb5cdef5e156e089ef
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 #ifndef STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_MANAGER_H_
6 #define STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_MANAGER_H_
8 #include <map>
9 #include <utility>
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/files/file.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "storage/browser/storage_browser_export.h"
17 #include "storage/common/fileapi/file_system_types.h"
18 #include "url/gurl.h"
20 namespace content {
21 class QuotaReservationManagerTest;
24 namespace storage {
26 class QuotaReservation;
27 class QuotaReservationBuffer;
28 class OpenFileHandle;
29 class OpenFileHandleContext;
31 class STORAGE_EXPORT QuotaReservationManager {
32 public:
33 // Callback for ReserveQuota. When this callback returns false, ReserveQuota
34 // operation should be reverted.
35 typedef base::Callback<bool(base::File::Error error, int64 delta)>
36 ReserveQuotaCallback;
38 // An abstraction of backing quota system.
39 class STORAGE_EXPORT QuotaBackend {
40 public:
41 QuotaBackend() {}
42 virtual ~QuotaBackend() {}
44 // Reserves or reclaims |delta| of quota for |origin| and |type| pair.
45 // Reserved quota should be counted as usage, but it should be on-memory
46 // and be cleared by a browser restart.
47 // Invokes |callback| upon completion with an error code.
48 // |callback| should return false if it can't accept the reservation, in
49 // that case, the backend should roll back the reservation.
50 virtual void ReserveQuota(const GURL& origin,
51 FileSystemType type,
52 int64 delta,
53 const ReserveQuotaCallback& callback) = 0;
55 // Reclaims |size| of quota for |origin| and |type|.
56 virtual void ReleaseReservedQuota(const GURL& origin,
57 FileSystemType type,
58 int64 size) = 0;
60 // Updates disk usage of |origin| and |type|.
61 // Invokes |callback| upon completion with an error code.
62 virtual void CommitQuotaUsage(const GURL& origin,
63 FileSystemType type,
64 int64 delta) = 0;
66 virtual void IncrementDirtyCount(const GURL& origin,
67 FileSystemType type) = 0;
68 virtual void DecrementDirtyCount(const GURL& origin,
69 FileSystemType type) = 0;
71 private:
72 DISALLOW_COPY_AND_ASSIGN(QuotaBackend);
75 explicit QuotaReservationManager(scoped_ptr<QuotaBackend> backend);
76 ~QuotaReservationManager();
78 // The entry point of the quota reservation. Creates new reservation object
79 // for |origin| and |type|.
80 scoped_refptr<QuotaReservation> CreateReservation(
81 const GURL& origin,
82 FileSystemType type);
84 private:
85 typedef std::map<std::pair<GURL, FileSystemType>, QuotaReservationBuffer*>
86 ReservationBufferByOriginAndType;
88 friend class QuotaReservation;
89 friend class QuotaReservationBuffer;
90 friend class content::QuotaReservationManagerTest;
92 void ReserveQuota(const GURL& origin,
93 FileSystemType type,
94 int64 delta,
95 const ReserveQuotaCallback& callback);
97 void ReleaseReservedQuota(const GURL& origin,
98 FileSystemType type,
99 int64 size);
101 void CommitQuotaUsage(const GURL& origin,
102 FileSystemType type,
103 int64 delta);
105 void IncrementDirtyCount(const GURL& origin, FileSystemType type);
106 void DecrementDirtyCount(const GURL& origin, FileSystemType type);
108 scoped_refptr<QuotaReservationBuffer> GetReservationBuffer(
109 const GURL& origin,
110 FileSystemType type);
111 void ReleaseReservationBuffer(QuotaReservationBuffer* reservation_pool);
113 scoped_ptr<QuotaBackend> backend_;
115 // Not owned. The destructor of ReservationBuffer should erase itself from
116 // |reservation_buffers_| by calling ReleaseReservationBuffer.
117 ReservationBufferByOriginAndType reservation_buffers_;
119 base::SequenceChecker sequence_checker_;
120 base::WeakPtrFactory<QuotaReservationManager> weak_ptr_factory_;
122 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManager);
125 } // namespace storage
127 #endif // STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_MANAGER_H_