indexed_db_factory.h revision 868fa2fe829687343ffae624259930155e16dbd8
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 <map>
9#include <set>
10
11#include "base/basictypes.h"
12#include "base/files/file_path.h"
13#include "base/memory/ref_counted.h"
14#include "base/memory/weak_ptr.h"
15#include "base/strings/string16.h"
16#include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h"
17#include "content/browser/indexed_db/indexed_db_database_callbacks_wrapper.h"
18#include "content/browser/indexed_db/indexed_db_factory.h"
19#include "content/common/content_export.h"
20
21namespace content {
22
23class IndexedDBBackingStore;
24class IndexedDBDatabase;
25
26class CONTENT_EXPORT IndexedDBFactory
27    : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBFactory>) {
28 public:
29  static scoped_refptr<IndexedDBFactory> Create() {
30    return make_scoped_refptr(new IndexedDBFactory());
31  }
32
33  // Notifications from weak pointers.
34  void RemoveIDBDatabaseBackend(const string16& unique_identifier);
35
36  void GetDatabaseNames(scoped_refptr<IndexedDBCallbacksWrapper> callbacks,
37                        const string16& database_identifier,
38                        const base::FilePath& data_directory);
39  void Open(const string16& name,
40            int64 version,
41            int64 transaction_id,
42            scoped_refptr<IndexedDBCallbacksWrapper> callbacks,
43            scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks,
44            const string16& database_identifier,
45            const base::FilePath& data_directory);
46
47  void DeleteDatabase(const string16& name,
48                      scoped_refptr<IndexedDBCallbacksWrapper> callbacks,
49                      const string16& database_identifier,
50                      const base::FilePath& data_directory);
51
52 protected:
53  friend class base::RefCounted<IndexedDBFactory>;
54
55  IndexedDBFactory();
56  virtual ~IndexedDBFactory();
57
58  scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
59      const string16& database_identifier,
60      const base::FilePath& data_directory);
61
62 private:
63  typedef std::map<string16, scoped_refptr<IndexedDBDatabase> >
64      IndexedDBDatabaseMap;
65  IndexedDBDatabaseMap database_backend_map_;
66
67  typedef std::map<string16, base::WeakPtr<IndexedDBBackingStore> >
68      IndexedDBBackingStoreMap;
69  IndexedDBBackingStoreMap backing_store_map_;
70
71  std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
72};
73
74}  // namespace content
75
76#endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
77