[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 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_FACTORY_H_ |
| 6 | #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| 7 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 10 | #include <map> |
cmumford | fbd8d17 | 2016-07-22 18:25:01 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 12 | #include <set> |
[email protected] | 4cfd02d | 2014-06-11 18:08:40 | [diff] [blame] | 13 | #include <utility> |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 14 | |
[email protected] | 95b2602 | 2013-06-06 18:20:19 | [diff] [blame] | 15 | #include "base/files/file_path.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 17 | #include "base/memory/ref_counted.h" |
[email protected] | 10994d13 | 2013-06-11 07:16:18 | [diff] [blame] | 18 | #include "base/strings/string16.h" |
[email protected] | 6abf88d | 2013-07-01 22:54:07 | [diff] [blame] | 19 | #include "content/browser/indexed_db/indexed_db_callbacks.h" |
[email protected] | 8df07d2 | 2013-07-22 17:57:43 | [diff] [blame] | 20 | #include "content/browser/indexed_db/indexed_db_database.h" |
[email protected] | e67c0cc | 2013-07-01 20:21:18 | [diff] [blame] | 21 | #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 22 | #include "content/common/content_export.h" |
[email protected] | 97a34c2 | 2013-10-28 17:34:34 | [diff] [blame] | 23 | #include "url/gurl.h" |
jsbell | d77cea9 | 2016-04-13 22:58:52 | [diff] [blame] | 24 | #include "url/origin.h" |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 25 | |
[email protected] | e62fe0d | 2014-04-14 19:04:35 | [diff] [blame] | 26 | namespace net { |
cmumford | 95032d5 | 2016-08-17 18:11:52 | [diff] [blame] | 27 | class URLRequestContextGetter; |
[email protected] | e62fe0d | 2014-04-14 19:04:35 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 30 | namespace content { |
| 31 | |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 32 | class IndexedDBBackingStore; |
[email protected] | d29650c | 2014-03-18 01:20:59 | [diff] [blame] | 33 | struct IndexedDBPendingConnection; |
cmumford | 2d8f8c91 | 2016-07-13 03:22:03 | [diff] [blame] | 34 | struct IndexedDBDataLossInfo; |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 35 | |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 36 | class CONTENT_EXPORT IndexedDBFactory |
Nico Weber | 43ddd7a3 | 2017-08-15 19:19:27 | [diff] [blame] | 37 | : public base::RefCountedThreadSafe<IndexedDBFactory> { |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 38 | public: |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 39 | typedef std::multimap<url::Origin, IndexedDBDatabase*> OriginDBMap; |
[email protected] | 7aba4d7 | 2014-01-11 22:38:22 | [diff] [blame] | 40 | typedef OriginDBMap::const_iterator OriginDBMapIterator; |
[email protected] | 1bdfff9 | 2014-07-31 00:04:00 | [diff] [blame] | 41 | typedef std::pair<OriginDBMapIterator, OriginDBMapIterator> OriginDBs; |
[email protected] | 7aba4d7 | 2014-01-11 22:38:22 | [diff] [blame] | 42 | |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 43 | virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, |
jsbell | e5db46e | 2015-01-22 18:55:53 | [diff] [blame] | 44 | bool forced_close) = 0; |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 45 | |
cmumford | 95032d5 | 2016-08-17 18:11:52 | [diff] [blame] | 46 | virtual void GetDatabaseNames( |
| 47 | scoped_refptr<IndexedDBCallbacks> callbacks, |
| 48 | const url::Origin& origin, |
| 49 | const base::FilePath& data_directory, |
| 50 | scoped_refptr<net::URLRequestContextGetter> request_context_getter) = 0; |
| 51 | virtual void Open( |
| 52 | const base::string16& name, |
| 53 | std::unique_ptr<IndexedDBPendingConnection> connection, |
| 54 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 55 | const url::Origin& origin, |
| 56 | const base::FilePath& data_directory) = 0; |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 57 | |
cmumford | 95032d5 | 2016-08-17 18:11:52 | [diff] [blame] | 58 | virtual void DeleteDatabase( |
| 59 | const base::string16& name, |
| 60 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 61 | scoped_refptr<IndexedDBCallbacks> callbacks, |
| 62 | const url::Origin& origin, |
eostroukhov | 1470b1f | 2017-01-23 21:13:53 | [diff] [blame] | 63 | const base::FilePath& data_directory, |
| 64 | bool force_close) = 0; |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 65 | |
kristipark | 7603dc3 | 2017-07-06 22:28:22 | [diff] [blame] | 66 | virtual void AbortTransactionsAndCompactDatabase( |
| 67 | base::OnceCallback<void(leveldb::Status)> callback, |
| 68 | const url::Origin& origin) = 0; |
kristipark | ffa7907 | 2017-07-12 01:15:30 | [diff] [blame] | 69 | virtual void AbortTransactionsForDatabase( |
| 70 | base::OnceCallback<void(leveldb::Status)> callback, |
| 71 | const url::Origin& origin) = 0; |
kristipark | 7603dc3 | 2017-07-06 22:28:22 | [diff] [blame] | 72 | |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 73 | virtual void HandleBackingStoreFailure(const url::Origin& origin) = 0; |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 74 | virtual void HandleBackingStoreCorruption( |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 75 | const url::Origin& origin, |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 76 | const IndexedDBDatabaseError& error) = 0; |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 77 | |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 78 | virtual OriginDBs GetOpenDatabasesForOrigin( |
| 79 | const url::Origin& origin) const = 0; |
[email protected] | 2f626ee | 2013-10-31 01:36:56 | [diff] [blame] | 80 | |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 81 | virtual void ForceClose(const url::Origin& origin) = 0; |
[email protected] | 7296457 | 2013-10-24 20:30:01 | [diff] [blame] | 82 | |
| 83 | // Called by the IndexedDBContext destructor so the factory can do cleanup. |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 84 | virtual void ContextDestroyed() = 0; |
[email protected] | 7296457 | 2013-10-24 20:30:01 | [diff] [blame] | 85 | |
[email protected] | 3cf0cae | 2014-04-03 16:26:19 | [diff] [blame] | 86 | // Called by the IndexedDBActiveBlobRegistry. |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 87 | virtual void ReportOutstandingBlobs(const url::Origin& origin, |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 88 | bool blobs_outstanding) = 0; |
[email protected] | 3cf0cae | 2014-04-03 16:26:19 | [diff] [blame] | 89 | |
[email protected] | 4099d254 | 2013-12-17 19:55:30 | [diff] [blame] | 90 | // Called by an IndexedDBDatabase when it is actually deleted. |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 91 | virtual void DatabaseDeleted( |
| 92 | const IndexedDBDatabase::Identifier& identifier) = 0; |
[email protected] | 4099d254 | 2013-12-17 19:55:30 | [diff] [blame] | 93 | |
Daniel Murphy | ac35e536 | 2017-10-03 01:28:12 | [diff] [blame] | 94 | // Called by IndexedDBBackingStore when blob files have been cleaned. |
| 95 | virtual void BlobFilesCleaned(const url::Origin& origin) = 0; |
| 96 | |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 97 | virtual size_t GetConnectionCount(const url::Origin& origin) const = 0; |
[email protected] | 7aba4d7 | 2014-01-11 22:38:22 | [diff] [blame] | 98 | |
kristipark | 5e4cbe0 | 2017-09-29 00:24:53 | [diff] [blame] | 99 | virtual void NotifyIndexedDBContentChanged( |
| 100 | const url::Origin& origin, |
| 101 | const base::string16& database_name, |
| 102 | const base::string16& object_store_name) = 0; |
| 103 | |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 104 | protected: |
[email protected] | c4f03aa | 2013-11-22 22:21:09 | [diff] [blame] | 105 | friend class base::RefCountedThreadSafe<IndexedDBFactory>; |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 106 | |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 107 | IndexedDBFactory() {} |
| 108 | virtual ~IndexedDBFactory() {} |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 109 | |
[email protected] | bc882ddd | 2013-09-23 22:23:03 | [diff] [blame] | 110 | virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 111 | const url::Origin& origin, |
[email protected] | 39571d1 | 2013-06-25 23:40:29 | [diff] [blame] | 112 | const base::FilePath& data_directory, |
cmumford | 95032d5 | 2016-08-17 18:11:52 | [diff] [blame] | 113 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
cmumford | 2d8f8c91 | 2016-07-13 03:22:03 | [diff] [blame] | 114 | IndexedDBDataLossInfo* data_loss_info, |
[email protected] | 6e227a8 | 2014-06-24 17:27:27 | [diff] [blame] | 115 | bool* disk_full, |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 116 | leveldb::Status* status) = 0; |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 117 | |
[email protected] | 8b9db116 | 2014-04-30 01:34:18 | [diff] [blame] | 118 | virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( |
jsbell | bebef32 | 2016-04-15 16:46:20 | [diff] [blame] | 119 | const url::Origin& origin, |
[email protected] | 8b9db116 | 2014-04-30 01:34:18 | [diff] [blame] | 120 | const base::FilePath& data_directory, |
cmumford | 95032d5 | 2016-08-17 18:11:52 | [diff] [blame] | 121 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
cmumford | 2d8f8c91 | 2016-07-13 03:22:03 | [diff] [blame] | 122 | IndexedDBDataLossInfo* data_loss_info, |
[email protected] | 8b9db116 | 2014-04-30 01:34:18 | [diff] [blame] | 123 | bool* disk_full, |
[email protected] | 6e227a8 | 2014-06-24 17:27:27 | [diff] [blame] | 124 | bool first_time, |
[email protected] | 8f4c920 | 2014-07-18 18:21:38 | [diff] [blame] | 125 | leveldb::Status* status) = 0; |
[email protected] | 59057f8 | 2013-09-11 20:52:24 | [diff] [blame] | 126 | |
[email protected] | 907a8bc5 | 2013-06-07 16:32:34 | [diff] [blame] | 127 | private: |
[email protected] | e8ca0f5 | 2014-06-07 08:46:34 | [diff] [blame] | 128 | DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory); |
[email protected] | 72a4183d | 2013-05-31 18:33:10 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace content |
| 132 | |
| 133 | #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |