1 // Copyright (c) 2014 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.
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
12 #include "content/browser/indexed_db/indexed_db_factory.h"
16 class IndexedDBContextImpl
;
18 class CONTENT_EXPORT IndexedDBFactoryImpl
: public IndexedDBFactory
{
20 explicit IndexedDBFactoryImpl(IndexedDBContextImpl
* context
);
22 // content::IndexedDBFactory overrides:
23 void ReleaseDatabase(const IndexedDBDatabase::Identifier
& identifier
,
24 bool forced_close
) override
;
26 void GetDatabaseNames(scoped_refptr
<IndexedDBCallbacks
> callbacks
,
27 const GURL
& origin_url
,
28 const base::FilePath
& data_directory
,
29 net::URLRequestContext
* request_context
) override
;
30 void Open(const base::string16
& name
,
31 const IndexedDBPendingConnection
& connection
,
32 net::URLRequestContext
* request_context
,
33 const GURL
& origin_url
,
34 const base::FilePath
& data_directory
) override
;
36 void DeleteDatabase(const base::string16
& name
,
37 net::URLRequestContext
* request_context
,
38 scoped_refptr
<IndexedDBCallbacks
> callbacks
,
39 const GURL
& origin_url
,
40 const base::FilePath
& data_directory
) override
;
42 void HandleBackingStoreFailure(const GURL
& origin_url
) override
;
43 void HandleBackingStoreCorruption(
44 const GURL
& origin_url
,
45 const IndexedDBDatabaseError
& error
) override
;
47 OriginDBs
GetOpenDatabasesForOrigin(const GURL
& origin_url
) const override
;
49 void ForceClose(const GURL
& origin_url
) override
;
51 // Called by the IndexedDBContext destructor so the factory can do cleanup.
52 void ContextDestroyed() override
;
54 // Called by the IndexedDBActiveBlobRegistry.
55 void ReportOutstandingBlobs(const GURL
& origin_url
,
56 bool blobs_outstanding
) override
;
58 // Called by an IndexedDBDatabase when it is actually deleted.
60 const IndexedDBDatabase::Identifier
& identifier
) override
;
62 size_t GetConnectionCount(const GURL
& origin_url
) const override
;
65 ~IndexedDBFactoryImpl() override
;
67 scoped_refptr
<IndexedDBBackingStore
> OpenBackingStore(
68 const GURL
& origin_url
,
69 const base::FilePath
& data_directory
,
70 net::URLRequestContext
* request_context
,
71 blink::WebIDBDataLoss
* data_loss
,
72 std::string
* data_loss_reason
,
74 leveldb::Status
* s
) override
;
76 scoped_refptr
<IndexedDBBackingStore
> OpenBackingStoreHelper(
77 const GURL
& origin_url
,
78 const base::FilePath
& data_directory
,
79 net::URLRequestContext
* request_context
,
80 blink::WebIDBDataLoss
* data_loss
,
81 std::string
* data_loss_message
,
84 leveldb::Status
* s
) override
;
86 void ReleaseBackingStore(const GURL
& origin_url
, bool immediate
);
87 void CloseBackingStore(const GURL
& origin_url
);
88 IndexedDBContextImpl
* context() const { return context_
; }
91 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
,
92 BackingStoreReleasedOnForcedClose
);
93 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
,
94 BackingStoreReleaseDelayedOnClose
);
95 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
, DatabaseFailedOpen
);
96 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
,
97 DeleteDatabaseClosesBackingStore
);
98 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
,
99 ForceCloseReleasesBackingStore
);
100 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest
,
101 GetDatabaseNamesClosesBackingStore
);
102 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest
,
103 ForceCloseOpenDatabasesOnCommitFailure
);
105 typedef std::map
<IndexedDBDatabase::Identifier
, IndexedDBDatabase
*>
106 IndexedDBDatabaseMap
;
107 typedef std::map
<GURL
, scoped_refptr
<IndexedDBBackingStore
> >
108 IndexedDBBackingStoreMap
;
110 // Called internally after a database is closed, with some delay. If this
111 // factory has the last reference, it will be released.
112 void MaybeCloseBackingStore(const GURL
& origin_url
);
113 bool HasLastBackingStoreReference(const GURL
& origin_url
) const;
115 // Testing helpers, so unit tests don't need to grovel through internal state.
116 bool IsDatabaseOpen(const GURL
& origin_url
, const base::string16
& name
) const;
117 bool IsBackingStoreOpen(const GURL
& origin_url
) const;
118 bool IsBackingStorePendingClose(const GURL
& origin_url
) const;
119 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier
& identifier
);
121 IndexedDBContextImpl
* context_
;
123 IndexedDBDatabaseMap database_map_
;
124 OriginDBMap origin_dbs_
;
125 IndexedDBBackingStoreMap backing_store_map_
;
127 std::set
<scoped_refptr
<IndexedDBBackingStore
> > session_only_backing_stores_
;
128 IndexedDBBackingStoreMap backing_stores_with_active_blobs_
;
129 std::set
<GURL
> backends_opened_since_boot_
;
131 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryImpl
);
134 } // namespace content
136 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_