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