OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <utility> |
| 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "webkit/common/blob/shareable_file_reference.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class IndexedDBBackingStore; |
| 19 |
| 20 class IndexedDBActiveBlobRegistry { |
| 21 public: |
| 22 IndexedDBActiveBlobRegistry(IndexedDBBackingStore* backing_store); |
| 23 ~IndexedDBActiveBlobRegistry(); |
| 24 |
| 25 // Most methods of this class, and the closure returned by |
| 26 // GetAddBlobRefCallback, should only be called on the backing_store's task |
| 27 // runner. The exception is the closure returned by GetFinalReleaseCallback, |
| 28 // which just calls ReleaseBlobRefThreadSafe. |
| 29 |
| 30 // Use DatabaseMetaDataKey::AllBlobsKey for "the whole database". |
| 31 bool MarkDeletedCheckIfUsed(int64 database_id, int64 blob_key); |
| 32 |
| 33 webkit_blob::ShareableFileReference::FinalReleaseCallback |
| 34 GetFinalReleaseCallback(int64 database_id, int64 blob_key); |
| 35 // This closure holds a raw pointer to the IndexedDBActiveBlobRegistry, |
| 36 // and may not be called after it is deleted. |
| 37 base::Closure GetAddBlobRefCallback(int64 database_id, int64 blob_key); |
| 38 // Call this to force the registry to drop its reference to the backing store. |
| 39 // This will also turn any outstanding callbacks into no-ops. |
| 40 void ForceShutdown(); |
| 41 |
| 42 private: |
| 43 void AddBlobRef(int64 database_id, int64 blob_key); |
| 44 void ReleaseBlobRef(int64 database_id, int64 blob_key); |
| 45 static void ReleaseBlobRefThreadSafe( |
| 46 scoped_refptr<base::TaskRunner> task_runner, |
| 47 base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, int64 database_id, |
| 48 int64 blob_key, const base::FilePath& unused); |
| 49 |
| 50 // Maps blob_key -> IsDeleted; if the record's absent, it's not in active use |
| 51 // and we don't care if it's deleted. |
| 52 typedef std::map<int64, bool> SingleDBMap; |
| 53 // Maps DB ID -> SingleDBMap |
| 54 typedef std::map<int64, SingleDBMap> AllDBsMap; |
| 55 typedef std::set<int64> DeletedDBSet; |
| 56 |
| 57 AllDBsMap use_tracker_; |
| 58 DeletedDBSet deleted_dbs_; |
| 59 // Think of backing_store_ as a scoped_refptr, but it's manually managed. |
| 60 // We'll hold a reference as long as there's a blob registered in use_counts_, |
| 61 // but not otherwise. Ideally the blobs would hold the references themselves, |
| 62 // but they live on the wrong thread. |
| 63 IndexedDBBackingStore* backing_store_; |
| 64 base::WeakPtrFactory<IndexedDBActiveBlobRegistry> weak_factory_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistry); |
| 67 }; |
| 68 |
| 69 } // namespace content |
| 70 |
| 71 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
OLD | NEW |