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.h" 17#include "content/browser/indexed_db/indexed_db_database.h" 18#include "content/browser/indexed_db/indexed_db_database_callbacks.h" 19#include "content/browser/indexed_db/indexed_db_factory.h" 20#include "content/common/content_export.h" 21 22namespace content { 23 24class IndexedDBBackingStore; 25 26class CONTENT_EXPORT IndexedDBFactory 27 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBFactory>) { 28 public: 29 IndexedDBFactory(); 30 31 // Notifications from weak pointers. 32 void RemoveIDBDatabaseBackend( 33 const IndexedDBDatabase::Identifier& unique_identifier); 34 35 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, 36 const std::string& origin_identifier, 37 const base::FilePath& data_directory); 38 void Open(const string16& name, 39 int64 version, 40 int64 transaction_id, 41 scoped_refptr<IndexedDBCallbacks> callbacks, 42 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 43 const std::string& origin_identifier, 44 const base::FilePath& data_directory); 45 46 void DeleteDatabase(const string16& name, 47 scoped_refptr<IndexedDBCallbacks> callbacks, 48 const std::string& origin_identifier, 49 const base::FilePath& data_directory); 50 51 // Iterates over all databases; for diagnostics only. 52 std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin( 53 const std::string& origin_identifier) const; 54 55 protected: 56 friend class base::RefCounted<IndexedDBFactory>; 57 58 virtual ~IndexedDBFactory(); 59 60 scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 61 const std::string& origin_identifier, 62 const base::FilePath& data_directory, 63 WebKit::WebIDBCallbacks::DataLoss* data_loss); 64 65 private: 66 typedef std::map<IndexedDBDatabase::Identifier, 67 scoped_refptr<IndexedDBDatabase> > IndexedDBDatabaseMap; 68 IndexedDBDatabaseMap database_backend_map_; 69 70 typedef std::map<std::string, base::WeakPtr<IndexedDBBackingStore> > 71 IndexedDBBackingStoreMap; 72 IndexedDBBackingStoreMap backing_store_map_; 73 74 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; 75}; 76 77} // namespace content 78 79#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 80