indexed_db_factory.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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/strings/string16.h" 15#include "content/browser/indexed_db/indexed_db_callbacks.h" 16#include "content/browser/indexed_db/indexed_db_database.h" 17#include "content/browser/indexed_db/indexed_db_database_callbacks.h" 18#include "content/common/content_export.h" 19 20namespace content { 21 22class IndexedDBBackingStore; 23 24class CONTENT_EXPORT IndexedDBFactory 25 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBFactory>) { 26 public: 27 IndexedDBFactory(); 28 29 // Notifications from weak pointers. 30 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, 31 bool forcedClose); 32 33 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, 34 const std::string& origin_identifier, 35 const base::FilePath& data_directory); 36 void Open(const string16& name, 37 int64 version, 38 int64 transaction_id, 39 scoped_refptr<IndexedDBCallbacks> callbacks, 40 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 41 const std::string& origin_identifier, 42 const base::FilePath& data_directory); 43 44 void DeleteDatabase(const string16& name, 45 scoped_refptr<IndexedDBCallbacks> callbacks, 46 const std::string& origin_identifier, 47 const base::FilePath& data_directory); 48 49 // Iterates over all databases; for diagnostics only. 50 std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin( 51 const std::string& origin_identifier) const; 52 53 protected: 54 friend class base::RefCounted<IndexedDBFactory>; 55 56 virtual ~IndexedDBFactory(); 57 58 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 59 const std::string& origin_identifier, 60 const base::FilePath& data_directory, 61 WebKit::WebIDBCallbacks::DataLoss* data_loss, 62 bool* disk_full); 63 64 void ReleaseBackingStore(const std::string& identifier, bool immediate); 65 void CloseBackingStore(const std::string& identifier); 66 67 private: 68 // Called internally after a database is closed, with some delay. If this 69 // factory has the last reference, it will be released. 70 void MaybeCloseBackingStore(const std::string& identifier); 71 bool HasLastBackingStoreReference(const std::string& identifier) const; 72 73 typedef std::map<IndexedDBDatabase::Identifier, 74 scoped_refptr<IndexedDBDatabase> > IndexedDBDatabaseMap; 75 IndexedDBDatabaseMap database_map_; 76 77 typedef std::map<std::string, scoped_refptr<IndexedDBBackingStore> > 78 IndexedDBBackingStoreMap; 79 IndexedDBBackingStoreMap backing_store_map_; 80 81 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; 82}; 83 84} // namespace content 85 86#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 87