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