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 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 9 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
10 #include "content/browser/indexed_db/indexed_db_database_impl.h" | 10 #include "content/browser/indexed_db/indexed_db_database.h" |
11 #include "content/browser/indexed_db/indexed_db_tracing.h" | 11 #include "content/browser/indexed_db/indexed_db_tracing.h" |
12 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 12 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
13 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 13 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 template <typename K, typename M> | 17 template <typename K, typename M> |
18 static void CleanWeakMap(std::map<K, base::WeakPtr<M> >* map) { | 18 static void CleanWeakMap(std::map<K, base::WeakPtr<M> >* map) { |
19 std::map<K, base::WeakPtr<M> > other; | 19 std::map<K, base::WeakPtr<M> > other; |
20 other.swap(*map); | 20 other.swap(*map); |
(...skipping 11 matching lines...) Expand all Loading... |
32 string16 result(database_identifier); | 32 string16 result(database_identifier); |
33 result.insert(result.end(), suffix.begin(), suffix.end()); | 33 result.insert(result.end(), suffix.begin(), suffix.end()); |
34 return result; | 34 return result; |
35 } | 35 } |
36 | 36 |
37 static string16 ComputeUniqueIdentifier(const string16& name, | 37 static string16 ComputeUniqueIdentifier(const string16& name, |
38 const string16& database_identifier) { | 38 const string16& database_identifier) { |
39 return ComputeFileIdentifier(database_identifier) + name; | 39 return ComputeFileIdentifier(database_identifier) + name; |
40 } | 40 } |
41 | 41 |
42 IndexedDBFactoryImpl::IndexedDBFactoryImpl() {} | 42 IndexedDBFactory::IndexedDBFactory() {} |
43 | 43 |
44 IndexedDBFactoryImpl::~IndexedDBFactoryImpl() {} | 44 IndexedDBFactory::~IndexedDBFactory() {} |
45 | 45 |
46 void IndexedDBFactoryImpl::RemoveIDBDatabaseBackend( | 46 void IndexedDBFactory::RemoveIDBDatabaseBackend( |
47 const string16& unique_identifier) { | 47 const string16& unique_identifier) { |
48 DCHECK(database_backend_map_.find(unique_identifier) != | 48 DCHECK(database_backend_map_.find(unique_identifier) != |
49 database_backend_map_.end()); | 49 database_backend_map_.end()); |
50 database_backend_map_.erase(unique_identifier); | 50 database_backend_map_.erase(unique_identifier); |
51 } | 51 } |
52 | 52 |
53 void IndexedDBFactoryImpl::GetDatabaseNames( | 53 void IndexedDBFactory::GetDatabaseNames( |
54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
55 const string16& database_identifier, | 55 const string16& database_identifier, |
56 const base::FilePath& data_directory) { | 56 const base::FilePath& data_directory) { |
57 IDB_TRACE("IndexedDBFactoryImpl::get_database_names"); | 57 IDB_TRACE("IndexedDBFactory::get_database_names"); |
58 scoped_refptr<IndexedDBBackingStore> backing_store = | 58 scoped_refptr<IndexedDBBackingStore> backing_store = |
59 OpenBackingStore(database_identifier, data_directory); | 59 OpenBackingStore(database_identifier, data_directory); |
60 if (!backing_store) { | 60 if (!backing_store) { |
61 callbacks->OnError(IndexedDBDatabaseError( | 61 callbacks->OnError( |
62 WebKit::WebIDBDatabaseExceptionUnknownError, | 62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
63 "Internal error opening backing store for " | 63 "Internal error opening backing store for " |
64 "indexedDB.webkitGetDatabaseNames.")); | 64 "indexedDB.webkitGetDatabaseNames.")); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); |
69 } | 69 } |
70 | 70 |
71 void IndexedDBFactoryImpl::DeleteDatabase( | 71 void IndexedDBFactory::DeleteDatabase( |
72 const string16& name, | 72 const string16& name, |
73 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 73 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
74 const string16& database_identifier, | 74 const string16& database_identifier, |
75 const base::FilePath& data_directory) { | 75 const base::FilePath& data_directory) { |
76 IDB_TRACE("IndexedDBFactoryImpl::delete_database"); | 76 IDB_TRACE("IndexedDBFactory::delete_database"); |
77 const string16 unique_identifier = | 77 const string16 unique_identifier = |
78 ComputeUniqueIdentifier(name, database_identifier); | 78 ComputeUniqueIdentifier(name, database_identifier); |
79 | 79 |
80 IndexedDBDatabaseMap::iterator it = | 80 IndexedDBDatabaseMap::iterator it = |
81 database_backend_map_.find(unique_identifier); | 81 database_backend_map_.find(unique_identifier); |
82 if (it != database_backend_map_.end()) { | 82 if (it != database_backend_map_.end()) { |
83 // If there are any connections to the database, directly delete the | 83 // If there are any connections to the database, directly delete the |
84 // database. | 84 // database. |
85 it->second->DeleteDatabase(callbacks); | 85 it->second->DeleteDatabase(callbacks); |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 // TODO(jsbell): Everything from now on should be done on another thread. | 89 // TODO(jsbell): Everything from now on should be done on another thread. |
90 scoped_refptr<IndexedDBBackingStore> backing_store = | 90 scoped_refptr<IndexedDBBackingStore> backing_store = |
91 OpenBackingStore(database_identifier, data_directory); | 91 OpenBackingStore(database_identifier, data_directory); |
92 if (!backing_store) { | 92 if (!backing_store) { |
93 callbacks->OnError(IndexedDBDatabaseError( | 93 callbacks->OnError(IndexedDBDatabaseError( |
94 WebKit::WebIDBDatabaseExceptionUnknownError, | 94 WebKit::WebIDBDatabaseExceptionUnknownError, |
95 ASCIIToUTF16("Internal error opening backing store " | 95 ASCIIToUTF16("Internal error opening backing store " |
96 "for indexed_db.delete_database."))); | 96 "for indexed_db.delete_database."))); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 scoped_refptr<IndexedDBDatabaseImpl> database_backend = | 100 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( |
101 IndexedDBDatabaseImpl::Create( | 101 name, backing_store.get(), this, unique_identifier); |
102 name, backing_store.get(), this, unique_identifier); | |
103 if (!database_backend) { | 102 if (!database_backend) { |
104 callbacks->OnError(IndexedDBDatabaseError( | 103 callbacks->OnError(IndexedDBDatabaseError( |
105 WebKit::WebIDBDatabaseExceptionUnknownError, | 104 WebKit::WebIDBDatabaseExceptionUnknownError, |
106 ASCIIToUTF16("Internal error creating database backend for " | 105 ASCIIToUTF16("Internal error creating database backend for " |
107 "indexed_db.delete_database."))); | 106 "indexed_db.delete_database."))); |
108 return; | 107 return; |
109 } | 108 } |
110 | 109 |
111 database_backend_map_[unique_identifier] = database_backend.get(); | 110 database_backend_map_[unique_identifier] = database_backend.get(); |
112 database_backend->DeleteDatabase(callbacks); | 111 database_backend->DeleteDatabase(callbacks); |
113 database_backend_map_.erase(unique_identifier); | 112 database_backend_map_.erase(unique_identifier); |
114 } | 113 } |
115 | 114 |
116 scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore( | 115 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
117 const string16& database_identifier, | 116 const string16& database_identifier, |
118 const base::FilePath& data_directory) { | 117 const base::FilePath& data_directory) { |
119 const string16 file_identifier = ComputeFileIdentifier(database_identifier); | 118 const string16 file_identifier = ComputeFileIdentifier(database_identifier); |
120 const bool open_in_memory = data_directory.empty(); | 119 const bool open_in_memory = data_directory.empty(); |
121 | 120 |
122 IndexedDBBackingStoreMap::iterator it2 = | 121 IndexedDBBackingStoreMap::iterator it2 = |
123 backing_store_map_.find(file_identifier); | 122 backing_store_map_.find(file_identifier); |
124 if (it2 != backing_store_map_.end() && it2->second.get()) | 123 if (it2 != backing_store_map_.end() && it2->second.get()) |
125 return it2->second.get(); | 124 return it2->second.get(); |
126 | 125 |
(...skipping 15 matching lines...) Expand all Loading... |
142 // All backing stores associated with this factory should be of the same | 141 // All backing stores associated with this factory should be of the same |
143 // type. | 142 // type. |
144 DCHECK(session_only_backing_stores_.empty() || open_in_memory); | 143 DCHECK(session_only_backing_stores_.empty() || open_in_memory); |
145 | 144 |
146 return backing_store; | 145 return backing_store; |
147 } | 146 } |
148 | 147 |
149 return 0; | 148 return 0; |
150 } | 149 } |
151 | 150 |
152 void IndexedDBFactoryImpl::Open( | 151 void IndexedDBFactory::Open( |
153 const string16& name, | 152 const string16& name, |
154 int64 version, | 153 int64 version, |
155 int64 transaction_id, | 154 int64 transaction_id, |
156 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 155 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
157 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 156 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
158 const string16& database_identifier, | 157 const string16& database_identifier, |
159 const base::FilePath& data_directory) { | 158 const base::FilePath& data_directory) { |
160 IDB_TRACE("IndexedDBFactoryImpl::open"); | 159 IDB_TRACE("IndexedDBFactory::open"); |
161 const string16 unique_identifier = | 160 const string16 unique_identifier = |
162 ComputeUniqueIdentifier(name, database_identifier); | 161 ComputeUniqueIdentifier(name, database_identifier); |
163 | 162 |
164 scoped_refptr<IndexedDBDatabaseImpl> database_backend; | 163 scoped_refptr<IndexedDBDatabase> database_backend; |
165 IndexedDBDatabaseMap::iterator it = | 164 IndexedDBDatabaseMap::iterator it = |
166 database_backend_map_.find(unique_identifier); | 165 database_backend_map_.find(unique_identifier); |
167 if (it == database_backend_map_.end()) { | 166 if (it == database_backend_map_.end()) { |
168 scoped_refptr<IndexedDBBackingStore> backing_store = | 167 scoped_refptr<IndexedDBBackingStore> backing_store = |
169 OpenBackingStore(database_identifier, data_directory); | 168 OpenBackingStore(database_identifier, data_directory); |
170 if (!backing_store) { | 169 if (!backing_store) { |
171 callbacks->OnError(IndexedDBDatabaseError( | 170 callbacks->OnError(IndexedDBDatabaseError( |
172 WebKit::WebIDBDatabaseExceptionUnknownError, | 171 WebKit::WebIDBDatabaseExceptionUnknownError, |
173 ASCIIToUTF16( | 172 ASCIIToUTF16( |
174 "Internal error opening backing store for indexedDB.open."))); | 173 "Internal error opening backing store for indexedDB.open."))); |
175 return; | 174 return; |
176 } | 175 } |
177 | 176 |
178 database_backend = IndexedDBDatabaseImpl::Create( | 177 database_backend = IndexedDBDatabase::Create( |
179 name, backing_store.get(), this, unique_identifier); | 178 name, backing_store.get(), this, unique_identifier); |
180 if (!database_backend) { | 179 if (!database_backend) { |
181 callbacks->OnError(IndexedDBDatabaseError( | 180 callbacks->OnError(IndexedDBDatabaseError( |
182 WebKit::WebIDBDatabaseExceptionUnknownError, | 181 WebKit::WebIDBDatabaseExceptionUnknownError, |
183 ASCIIToUTF16( | 182 ASCIIToUTF16( |
184 "Internal error creating database backend for indexedDB.open."))); | 183 "Internal error creating database backend for indexedDB.open."))); |
185 return; | 184 return; |
186 } | 185 } |
187 | 186 |
188 database_backend_map_[unique_identifier] = database_backend.get(); | 187 database_backend_map_[unique_identifier] = database_backend.get(); |
189 } else { | 188 } else { |
190 database_backend = it->second; | 189 database_backend = it->second; |
191 } | 190 } |
192 | 191 |
193 database_backend->OpenConnection( | 192 database_backend->OpenConnection( |
194 callbacks, database_callbacks, transaction_id, version); | 193 callbacks, database_callbacks, transaction_id, version); |
195 } | 194 } |
196 | 195 |
197 } // namespace content | 196 } // namespace content |
OLD | NEW |