| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database.h" | 16 #include "content/browser/indexed_db/indexed_db_database.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace base { |
| 22 class TaskRunner; |
| 23 } |
| 24 |
| 25 namespace net { |
| 26 class URLRequestContext; |
| 27 } |
| 28 |
| 21 namespace content { | 29 namespace content { |
| 22 | 30 |
| 23 class IndexedDBBackingStore; | 31 class IndexedDBBackingStore; |
| 24 class IndexedDBContextImpl; | 32 class IndexedDBContextImpl; |
| 25 | 33 |
| 26 class CONTENT_EXPORT IndexedDBFactory | 34 class CONTENT_EXPORT IndexedDBFactory |
| 27 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { | 35 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { |
| 28 public: | 36 public: |
| 29 explicit IndexedDBFactory(IndexedDBContextImpl* context); | 37 explicit IndexedDBFactory(IndexedDBContextImpl* context); |
| 30 | 38 |
| 31 // Notifications from weak pointers. | |
| 32 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, | 39 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, |
| 33 const GURL& origin_url, | 40 const GURL& origin_url, |
| 34 bool forcedClose); | 41 bool forcedClose); |
| 42 void ReleaseBackingStore(const GURL& origin_url, bool immediate); |
| 35 | 43 |
| 36 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, | 44 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 37 const GURL& origin_url, | 45 const GURL& origin_url, |
| 38 const base::FilePath& data_directory); | 46 const base::FilePath& data_directory, |
| 47 base::TaskRunner* task_runner); |
| 39 void Open(const string16& name, | 48 void Open(const string16& name, |
| 40 int64 version, | 49 int64 version, |
| 50 net::URLRequestContext* request_context, |
| 41 int64 transaction_id, | 51 int64 transaction_id, |
| 42 scoped_refptr<IndexedDBCallbacks> callbacks, | 52 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 43 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 53 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 44 const GURL& origin_url, | 54 const GURL& origin_url, |
| 45 const base::FilePath& data_directory); | 55 const base::FilePath& data_directory, |
| 56 int child_process_id, |
| 57 base::TaskRunner* task_runner); |
| 46 | 58 |
| 47 void DeleteDatabase(const string16& name, | 59 void DeleteDatabase(const string16& name, |
| 60 net::URLRequestContext* request_context, |
| 48 scoped_refptr<IndexedDBCallbacks> callbacks, | 61 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 49 const GURL& origin_url, | 62 const GURL& origin_url, |
| 50 const base::FilePath& data_directory); | 63 const base::FilePath& data_directory, |
| 64 base::TaskRunner* task_runner); |
| 51 | 65 |
| 52 void HandleBackingStoreFailure(const GURL& origin_url); | 66 void HandleBackingStoreFailure(const GURL& origin_url); |
| 53 | 67 |
| 54 // Iterates over all databases; for diagnostics only. | 68 // Iterates over all databases; for diagnostics only. |
| 55 std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin( | 69 std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin( |
| 56 const GURL& origin_url) const; | 70 const GURL& origin_url) const; |
| 57 | 71 |
| 58 bool IsBackingStoreOpenForTesting(const GURL& origin_url) const; | 72 bool IsBackingStoreOpenForTesting(const GURL& origin_url) const; |
| 59 | 73 |
| 60 // Called by the IndexedDBContext destructor so the factory can do cleanup. | 74 // Called by the IndexedDBContext destructor so the factory can do cleanup. |
| 61 void ContextDestroyed(); | 75 void ContextDestroyed(); |
| 62 | 76 |
| 63 protected: | 77 protected: |
| 64 friend class base::RefCountedThreadSafe<IndexedDBFactory>; | 78 friend class base::RefCountedThreadSafe<IndexedDBFactory>; |
| 65 | 79 |
| 66 virtual ~IndexedDBFactory(); | 80 virtual ~IndexedDBFactory(); |
| 67 | 81 |
| 68 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( | 82 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
| 69 const GURL& origin_url, | 83 const GURL& origin_url, |
| 70 const base::FilePath& data_directory, | 84 const base::FilePath& data_directory, |
| 85 net::URLRequestContext* request_context, |
| 71 blink::WebIDBDataLoss* data_loss, | 86 blink::WebIDBDataLoss* data_loss, |
| 72 std::string* data_loss_reason, | 87 std::string* data_loss_reason, |
| 73 bool* disk_full); | 88 bool* disk_full, |
| 89 base::TaskRunner* task_runner); |
| 74 | 90 |
| 75 void ReleaseBackingStore(const GURL& origin_url, bool immediate); | |
| 76 void CloseBackingStore(const GURL& origin_url); | 91 void CloseBackingStore(const GURL& origin_url); |
| 77 | 92 |
| 78 private: | 93 private: |
| 79 // Called internally after a database is closed, with some delay. If this | 94 // Called internally after a database is closed, with some delay. If this |
| 80 // factory has the last reference, it will be released. | 95 // factory has the last reference, it will be released. |
| 81 void MaybeCloseBackingStore(const GURL& origin_url); | 96 void MaybeCloseBackingStore(const GURL& origin_url); |
| 82 bool HasLastBackingStoreReference(const GURL& origin_url) const; | 97 bool HasLastBackingStoreReference( |
| 98 const GURL& origin_url, bool forcedClose) const; |
| 83 | 99 |
| 84 IndexedDBContextImpl* context_; | 100 IndexedDBContextImpl* context_; |
| 85 | 101 |
| 86 typedef std::map<IndexedDBDatabase::Identifier, | 102 typedef std::map<IndexedDBDatabase::Identifier, |
| 87 scoped_refptr<IndexedDBDatabase> > IndexedDBDatabaseMap; | 103 scoped_refptr<IndexedDBDatabase> > IndexedDBDatabaseMap; |
| 88 IndexedDBDatabaseMap database_map_; | 104 IndexedDBDatabaseMap database_map_; |
| 89 | 105 |
| 90 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > | 106 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > |
| 91 IndexedDBBackingStoreMap; | 107 IndexedDBBackingStoreMap; |
| 92 IndexedDBBackingStoreMap backing_store_map_; | 108 IndexedDBBackingStoreMap backing_store_map_; |
| 93 | 109 |
| 94 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; | 110 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; |
| 111 std::set<GURL> backends_opened_since_boot_; |
| 95 }; | 112 }; |
| 96 | 113 |
| 97 } // namespace content | 114 } // namespace content |
| 98 | 115 |
| 99 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 116 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| OLD | NEW |