Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_active_blob_registry.h |
| diff --git a/content/browser/indexed_db/indexed_db_active_blob_registry.h b/content/browser/indexed_db/indexed_db_active_blob_registry.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c34274c3e2e728a5680f3bcd3f6b42acecf968aa |
| --- /dev/null |
| +++ b/content/browser/indexed_db/indexed_db_active_blob_registry.h |
| @@ -0,0 +1,73 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
|
jsbell
2014/03/20 18:04:33
2014 - here and in other new files
ericu
2014/03/25 01:22:14
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| +#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <utility> |
| +#include "base/basictypes.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "content/common/content_export.h" |
| +#include "webkit/common/blob/shareable_file_reference.h" |
| + |
| +namespace content { |
| + |
| +class IndexedDBBackingStore; |
| + |
| +class CONTENT_EXPORT IndexedDBActiveBlobRegistry { |
| + public: |
| + IndexedDBActiveBlobRegistry(IndexedDBBackingStore* backing_store); |
| + ~IndexedDBActiveBlobRegistry(); |
| + |
| + // Most methods of this class, and the closure returned by |
| + // GetAddBlobRefCallback, should only be called on the backing_store's task |
| + // runner. The exception is the closure returned by GetFinalReleaseCallback, |
| + // which just calls ReleaseBlobRefThreadSafe. |
| + |
| + // Use DatabaseMetaDataKey::AllBlobsKey for "the whole database". |
| + bool MarkDeletedCheckIfUsed(int64 database_id, int64 blob_key); |
| + |
| + webkit_blob::ShareableFileReference::FinalReleaseCallback |
| + GetFinalReleaseCallback(int64 database_id, int64 blob_key); |
|
cmumford
2014/03/24 23:14:35
These two functions have the word "get" in their n
ericu
2014/03/25 01:22:14
No, they grab weak pointers from a WeakPointerFact
|
| + // This closure holds a raw pointer to the IndexedDBActiveBlobRegistry, |
| + // and may not be called after it is deleted. |
| + base::Closure GetAddBlobRefCallback(int64 database_id, int64 blob_key); |
| + // Call this to force the registry to drop its reference to the backing store. |
| + // This will also turn any outstanding callbacks into no-ops. |
| + void ForceShutdown(); |
| + |
| + private: |
| + void AddBlobRef(int64 database_id, int64 blob_key); |
| + void ReleaseBlobRef(int64 database_id, int64 blob_key); |
| + static void ReleaseBlobRefThreadSafe( |
| + scoped_refptr<base::TaskRunner> task_runner, |
| + base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, |
| + int64 database_id, |
| + int64 blob_key, |
| + const base::FilePath& unused); |
| + |
| + // Maps blob_key -> IsDeleted; if the record's absent, it's not in active use |
| + // and we don't care if it's deleted. |
| + typedef std::map<int64, bool> SingleDBMap; |
| + // Maps DB ID -> SingleDBMap |
| + typedef std::map<int64, SingleDBMap> AllDBsMap; |
| + typedef std::set<int64> DeletedDBSet; |
| + |
| + AllDBsMap use_tracker_; |
| + DeletedDBSet deleted_dbs_; |
| + // As long as we've got blobs registered in use_tracker_, |
| + // backing_store_->factory() will keep backing_store_ alive for us. And |
| + // backing_store_ owns us, so we'll stay alive as long as we're needed. |
| + IndexedDBBackingStore* backing_store_; |
| + base::WeakPtrFactory<IndexedDBActiveBlobRegistry> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistry); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_ACTIVE_BLOB_REGISTRY_H_ |