| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <set> | 11 #include <set> |
| 10 #include <utility> | 12 #include <utility> |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 15 #include "storage/browser/blob/shareable_file_reference.h" | 17 #include "storage/browser/blob/shareable_file_reference.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 class IndexedDBBackingStore; | 21 class IndexedDBBackingStore; |
| 20 | 22 |
| 21 class CONTENT_EXPORT IndexedDBActiveBlobRegistry { | 23 class CONTENT_EXPORT IndexedDBActiveBlobRegistry { |
| 22 public: | 24 public: |
| 23 explicit IndexedDBActiveBlobRegistry(IndexedDBBackingStore* backing_store); | 25 explicit IndexedDBActiveBlobRegistry(IndexedDBBackingStore* backing_store); |
| 24 ~IndexedDBActiveBlobRegistry(); | 26 ~IndexedDBActiveBlobRegistry(); |
| 25 | 27 |
| 26 // Most methods of this class, and the closure returned by | 28 // Most methods of this class, and the closure returned by |
| 27 // GetAddBlobRefCallback, should only be called on the backing_store's task | 29 // GetAddBlobRefCallback, should only be called on the backing_store's task |
| 28 // runner. The exception is the closure returned by GetFinalReleaseCallback, | 30 // runner. The exception is the closure returned by GetFinalReleaseCallback, |
| 29 // which just calls ReleaseBlobRefThreadSafe. | 31 // which just calls ReleaseBlobRefThreadSafe. |
| 30 | 32 |
| 31 // Use DatabaseMetaDataKey::AllBlobsKey for "the whole database". | 33 // Use DatabaseMetaDataKey::AllBlobsKey for "the whole database". |
| 32 bool MarkDeletedCheckIfUsed(int64 database_id, int64 blob_key); | 34 bool MarkDeletedCheckIfUsed(int64_t database_id, int64_t blob_key); |
| 33 | 35 |
| 34 storage::ShareableFileReference::FinalReleaseCallback GetFinalReleaseCallback( | 36 storage::ShareableFileReference::FinalReleaseCallback GetFinalReleaseCallback( |
| 35 int64 database_id, | 37 int64_t database_id, |
| 36 int64 blob_key); | 38 int64_t blob_key); |
| 37 // This closure holds a raw pointer to the IndexedDBActiveBlobRegistry, | 39 // This closure holds a raw pointer to the IndexedDBActiveBlobRegistry, |
| 38 // and may not be called after it is deleted. | 40 // and may not be called after it is deleted. |
| 39 base::Closure GetAddBlobRefCallback(int64 database_id, int64 blob_key); | 41 base::Closure GetAddBlobRefCallback(int64_t database_id, int64_t blob_key); |
| 40 // Call this to force the registry to drop its use counts, permitting the | 42 // Call this to force the registry to drop its use counts, permitting the |
| 41 // factory to drop any blob-related refcount for the backing store. | 43 // factory to drop any blob-related refcount for the backing store. |
| 42 // This will also turn any outstanding callbacks into no-ops. | 44 // This will also turn any outstanding callbacks into no-ops. |
| 43 void ForceShutdown(); | 45 void ForceShutdown(); |
| 44 | 46 |
| 45 private: | 47 private: |
| 46 // Maps blob_key -> IsDeleted; if the record's absent, it's not in active use | 48 // Maps blob_key -> IsDeleted; if the record's absent, it's not in active use |
| 47 // and we don't care if it's deleted. | 49 // and we don't care if it's deleted. |
| 48 typedef std::map<int64, bool> SingleDBMap; | 50 typedef std::map<int64_t, bool> SingleDBMap; |
| 49 // Maps DB ID -> SingleDBMap | 51 // Maps DB ID -> SingleDBMap |
| 50 typedef std::map<int64, SingleDBMap> AllDBsMap; | 52 typedef std::map<int64_t, SingleDBMap> AllDBsMap; |
| 51 typedef std::set<int64> DeletedDBSet; | 53 typedef std::set<int64_t> DeletedDBSet; |
| 52 | 54 |
| 53 void AddBlobRef(int64 database_id, int64 blob_key); | 55 void AddBlobRef(int64_t database_id, int64_t blob_key); |
| 54 void ReleaseBlobRef(int64 database_id, int64 blob_key); | 56 void ReleaseBlobRef(int64_t database_id, int64_t blob_key); |
| 55 static void ReleaseBlobRefThreadSafe( | 57 static void ReleaseBlobRefThreadSafe( |
| 56 scoped_refptr<base::TaskRunner> task_runner, | 58 scoped_refptr<base::TaskRunner> task_runner, |
| 57 base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, | 59 base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, |
| 58 int64 database_id, | 60 int64_t database_id, |
| 59 int64 blob_key, | 61 int64_t blob_key, |
| 60 const base::FilePath& unused); | 62 const base::FilePath& unused); |
| 61 | 63 |
| 62 AllDBsMap use_tracker_; | 64 AllDBsMap use_tracker_; |
| 63 DeletedDBSet deleted_dbs_; | 65 DeletedDBSet deleted_dbs_; |
| 64 // As long as we've got blobs registered in use_tracker_, | 66 // As long as we've got blobs registered in use_tracker_, |
| 65 // backing_store_->factory() will keep backing_store_ alive for us. And | 67 // backing_store_->factory() will keep backing_store_ alive for us. And |
| 66 // backing_store_ owns us, so we'll stay alive as long as we're needed. | 68 // backing_store_ owns us, so we'll stay alive as long as we're needed. |
| 67 IndexedDBBackingStore* backing_store_; | 69 IndexedDBBackingStore* backing_store_; |
| 68 base::WeakPtrFactory<IndexedDBActiveBlobRegistry> weak_factory_; | 70 base::WeakPtrFactory<IndexedDBActiveBlobRegistry> weak_factory_; |
| 69 | 71 |
| 70 DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistry); | 72 DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistry); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 } // namespace content | 75 } // namespace content |
| 74 | 76 |
| 75 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ | 77 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| OLD | NEW |