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 
8 #include <stddef.h>
9 
10 #include <memory>
11 #include <tuple>
12 #include <utility>
13 #include <vector>
14 
15 #include "base/callback.h"
16 #include "base/containers/flat_map.h"
17 #include "base/files/file_path.h"
18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/strings/string16.h"
21 #include "content/browser/indexed_db/indexed_db_callbacks.h"
22 #include "content/browser/indexed_db/indexed_db_database.h"
23 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
24 #include "content/common/content_export.h"
25 #include "url/gurl.h"
26 #include "url/origin.h"
27 
28 namespace content {
29 
30 class IndexedDBBackingStore;
31 struct IndexedDBPendingConnection;
32 
33 // TODO(dmurph): Remove this interface.
34 class CONTENT_EXPORT IndexedDBFactory {
35  public:
36   virtual ~IndexedDBFactory() = default;
37 
38   using OriginDBMap =
39       base::flat_map<base::string16, std::unique_ptr<IndexedDBDatabase>>;
40 
41   virtual void GetDatabaseInfo(scoped_refptr<IndexedDBCallbacks> callbacks,
42                                const url::Origin& origin,
43                                const base::FilePath& data_directory) = 0;
44   virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
45                                 const url::Origin& origin,
46                                 const base::FilePath& data_directory) = 0;
47   virtual void Open(
48       const base::string16& name,
49       std::unique_ptr<IndexedDBPendingConnection> connection,
50       const url::Origin& origin,
51       const base::FilePath& data_directory) = 0;
52 
53   virtual void DeleteDatabase(
54       const base::string16& name,
55       scoped_refptr<IndexedDBCallbacks> callbacks,
56       const url::Origin& origin,
57       const base::FilePath& data_directory,
58       bool force_close) = 0;
59 
60   virtual void AbortTransactionsAndCompactDatabase(
61       base::OnceCallback<void(leveldb::Status)> callback,
62       const url::Origin& origin) = 0;
63   virtual void AbortTransactionsForDatabase(
64       base::OnceCallback<void(leveldb::Status)> callback,
65       const url::Origin& origin) = 0;
66 
67   virtual void HandleBackingStoreFailure(const url::Origin& origin) = 0;
68   virtual void HandleBackingStoreCorruption(
69       const url::Origin& origin,
70       const IndexedDBDatabaseError& error) = 0;
71 
72   virtual std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin(
73       const url::Origin& origin) const = 0;
74 
75   // Close all connections to all databases within the origin. If
76   // |delete_in_memory_store| is true, references to in-memory databases will be
77   // dropped thereby allowing their deletion (otherwise they are retained for
78   // the lifetime of the factory).
79   virtual void ForceClose(const url::Origin& origin,
80                           bool delete_in_memory_store = false) = 0;
81 
82   virtual void ForceSchemaDowngrade(const url::Origin& origin) = 0;
83   virtual V2SchemaCorruptionStatus HasV2SchemaCorruption(
84       const url::Origin& origin) = 0;
85 
86   // Called by the IndexedDBContext destructor so the factory can do cleanup.
87   virtual void ContextDestroyed() = 0;
88 
89   // Called by the IndexedDBActiveBlobRegistry.
90   virtual void ReportOutstandingBlobs(const url::Origin& origin,
91                                       bool blobs_outstanding) = 0;
92 
93   // Called by IndexedDBBackingStore when blob files have been cleaned.
94   virtual void BlobFilesCleaned(const url::Origin& origin) = 0;
95 
96   virtual size_t GetConnectionCount(const url::Origin& origin) const = 0;
97 
98   virtual int64_t GetInMemoryDBSize(const url::Origin& origin) const = 0;
99 
100   virtual base::Time GetLastModified(const url::Origin& origin) const = 0;
101 
102   virtual void NotifyIndexedDBContentChanged(
103       const url::Origin& origin,
104       const base::string16& database_name,
105       const base::string16& object_store_name) = 0;
106 
107  protected:
IndexedDBFactory()108   IndexedDBFactory() {}
109 
110  private:
111   DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory);
112 };
113 
114 }  // namespace content
115 
116 #endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
117