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.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.h" | 10 #include "content/browser/indexed_db/indexed_db_database.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 IndexedDBFactory::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("IndexedDBFactory::get_database_names"); | 57 IDB_TRACE("IndexedDBFactory::get_database_names"); |
| 58 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 59 WebKit::WebIDBCallbacks::DataLoss data_loss; |
58 scoped_refptr<IndexedDBBackingStore> backing_store = | 60 scoped_refptr<IndexedDBBackingStore> backing_store = |
59 OpenBackingStore(database_identifier, data_directory); | 61 OpenBackingStore(database_identifier, data_directory, &data_loss); |
60 if (!backing_store.get()) { | 62 if (!backing_store.get()) { |
61 callbacks->OnError( | 63 callbacks->OnError( |
62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 64 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
63 "Internal error opening backing store for " | 65 "Internal error opening backing store for " |
64 "indexedDB.webkitGetDatabaseNames.")); | 66 "indexedDB.webkitGetDatabaseNames.")); |
65 return; | 67 return; |
66 } | 68 } |
67 | 69 |
68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 70 callbacks->OnSuccess(backing_store->GetDatabaseNames()); |
69 } | 71 } |
(...skipping 10 matching lines...) Expand all Loading... |
80 IndexedDBDatabaseMap::iterator it = | 82 IndexedDBDatabaseMap::iterator it = |
81 database_backend_map_.find(unique_identifier); | 83 database_backend_map_.find(unique_identifier); |
82 if (it != database_backend_map_.end()) { | 84 if (it != database_backend_map_.end()) { |
83 // If there are any connections to the database, directly delete the | 85 // If there are any connections to the database, directly delete the |
84 // database. | 86 // database. |
85 it->second->DeleteDatabase(callbacks); | 87 it->second->DeleteDatabase(callbacks); |
86 return; | 88 return; |
87 } | 89 } |
88 | 90 |
89 // TODO(jsbell): Everything from now on should be done on another thread. | 91 // TODO(jsbell): Everything from now on should be done on another thread. |
| 92 |
| 93 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 94 WebKit::WebIDBCallbacks::DataLoss data_loss; |
90 scoped_refptr<IndexedDBBackingStore> backing_store = | 95 scoped_refptr<IndexedDBBackingStore> backing_store = |
91 OpenBackingStore(database_identifier, data_directory); | 96 OpenBackingStore(database_identifier, data_directory, &data_loss); |
92 if (!backing_store.get()) { | 97 if (!backing_store.get()) { |
93 callbacks->OnError(IndexedDBDatabaseError( | 98 callbacks->OnError(IndexedDBDatabaseError( |
94 WebKit::WebIDBDatabaseExceptionUnknownError, | 99 WebKit::WebIDBDatabaseExceptionUnknownError, |
95 ASCIIToUTF16("Internal error opening backing store " | 100 ASCIIToUTF16("Internal error opening backing store " |
96 "for indexed_db.delete_database."))); | 101 "for indexed_db.delete_database."))); |
97 return; | 102 return; |
98 } | 103 } |
99 | 104 |
100 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( | 105 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( |
101 name, backing_store.get(), this, unique_identifier); | 106 name, backing_store.get(), this, unique_identifier); |
102 if (!database_backend.get()) { | 107 if (!database_backend.get()) { |
103 callbacks->OnError(IndexedDBDatabaseError( | 108 callbacks->OnError(IndexedDBDatabaseError( |
104 WebKit::WebIDBDatabaseExceptionUnknownError, | 109 WebKit::WebIDBDatabaseExceptionUnknownError, |
105 ASCIIToUTF16("Internal error creating database backend for " | 110 ASCIIToUTF16("Internal error creating database backend for " |
106 "indexed_db.delete_database."))); | 111 "indexed_db.delete_database."))); |
107 return; | 112 return; |
108 } | 113 } |
109 | 114 |
110 database_backend_map_[unique_identifier] = database_backend.get(); | 115 database_backend_map_[unique_identifier] = database_backend.get(); |
111 database_backend->DeleteDatabase(callbacks); | 116 database_backend->DeleteDatabase(callbacks); |
112 database_backend_map_.erase(unique_identifier); | 117 database_backend_map_.erase(unique_identifier); |
113 } | 118 } |
114 | 119 |
115 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 120 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
116 const string16& database_identifier, | 121 const string16& database_identifier, |
117 const base::FilePath& data_directory) { | 122 const base::FilePath& data_directory, |
| 123 WebKit::WebIDBCallbacks::DataLoss* data_loss) { |
118 const string16 file_identifier = ComputeFileIdentifier(database_identifier); | 124 const string16 file_identifier = ComputeFileIdentifier(database_identifier); |
119 const bool open_in_memory = data_directory.empty(); | 125 const bool open_in_memory = data_directory.empty(); |
120 | 126 |
121 IndexedDBBackingStoreMap::iterator it2 = | 127 IndexedDBBackingStoreMap::iterator it2 = |
122 backing_store_map_.find(file_identifier); | 128 backing_store_map_.find(file_identifier); |
123 if (it2 != backing_store_map_.end() && it2->second.get()) | 129 if (it2 != backing_store_map_.end() && it2->second.get()) |
124 return it2->second.get(); | 130 return it2->second.get(); |
125 | 131 |
126 scoped_refptr<IndexedDBBackingStore> backing_store; | 132 scoped_refptr<IndexedDBBackingStore> backing_store; |
127 if (open_in_memory) { | 133 if (open_in_memory) { |
128 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); | 134 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); |
129 } else { | 135 } else { |
130 backing_store = IndexedDBBackingStore::Open( | 136 backing_store = IndexedDBBackingStore::Open( |
131 database_identifier, data_directory, file_identifier); | 137 database_identifier, data_directory, file_identifier, data_loss); |
132 } | 138 } |
133 | 139 |
134 if (backing_store.get()) { | 140 if (backing_store.get()) { |
135 CleanWeakMap(&backing_store_map_); | 141 CleanWeakMap(&backing_store_map_); |
136 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); | 142 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); |
137 // If an in-memory database, bind lifetime to this factory instance. | 143 // If an in-memory database, bind lifetime to this factory instance. |
138 if (open_in_memory) | 144 if (open_in_memory) |
139 session_only_backing_stores_.insert(backing_store); | 145 session_only_backing_stores_.insert(backing_store); |
140 | 146 |
141 // All backing stores associated with this factory should be of the same | 147 // All backing stores associated with this factory should be of the same |
(...skipping 14 matching lines...) Expand all Loading... |
156 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 162 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
157 const string16& database_identifier, | 163 const string16& database_identifier, |
158 const base::FilePath& data_directory) { | 164 const base::FilePath& data_directory) { |
159 IDB_TRACE("IndexedDBFactory::open"); | 165 IDB_TRACE("IndexedDBFactory::open"); |
160 const string16 unique_identifier = | 166 const string16 unique_identifier = |
161 ComputeUniqueIdentifier(name, database_identifier); | 167 ComputeUniqueIdentifier(name, database_identifier); |
162 | 168 |
163 scoped_refptr<IndexedDBDatabase> database_backend; | 169 scoped_refptr<IndexedDBDatabase> database_backend; |
164 IndexedDBDatabaseMap::iterator it = | 170 IndexedDBDatabaseMap::iterator it = |
165 database_backend_map_.find(unique_identifier); | 171 database_backend_map_.find(unique_identifier); |
| 172 WebKit::WebIDBCallbacks::DataLoss data_loss = WebKit::WebIDBCallbacks::None; |
166 if (it == database_backend_map_.end()) { | 173 if (it == database_backend_map_.end()) { |
167 scoped_refptr<IndexedDBBackingStore> backing_store = | 174 scoped_refptr<IndexedDBBackingStore> backing_store = |
168 OpenBackingStore(database_identifier, data_directory); | 175 OpenBackingStore(database_identifier, data_directory, &data_loss); |
169 if (!backing_store.get()) { | 176 if (!backing_store.get()) { |
170 callbacks->OnError(IndexedDBDatabaseError( | 177 callbacks->OnError(IndexedDBDatabaseError( |
171 WebKit::WebIDBDatabaseExceptionUnknownError, | 178 WebKit::WebIDBDatabaseExceptionUnknownError, |
172 ASCIIToUTF16( | 179 ASCIIToUTF16( |
173 "Internal error opening backing store for indexedDB.open."))); | 180 "Internal error opening backing store for indexedDB.open."))); |
174 return; | 181 return; |
175 } | 182 } |
176 | 183 |
177 database_backend = IndexedDBDatabase::Create( | 184 database_backend = IndexedDBDatabase::Create( |
178 name, backing_store.get(), this, unique_identifier); | 185 name, backing_store.get(), this, unique_identifier); |
179 if (!database_backend.get()) { | 186 if (!database_backend.get()) { |
180 callbacks->OnError(IndexedDBDatabaseError( | 187 callbacks->OnError(IndexedDBDatabaseError( |
181 WebKit::WebIDBDatabaseExceptionUnknownError, | 188 WebKit::WebIDBDatabaseExceptionUnknownError, |
182 ASCIIToUTF16( | 189 ASCIIToUTF16( |
183 "Internal error creating database backend for indexedDB.open."))); | 190 "Internal error creating database backend for indexedDB.open."))); |
184 return; | 191 return; |
185 } | 192 } |
186 | 193 |
187 database_backend_map_[unique_identifier] = database_backend.get(); | 194 database_backend_map_[unique_identifier] = database_backend.get(); |
188 } else { | 195 } else { |
189 database_backend = it->second; | 196 database_backend = it->second; |
190 } | 197 } |
191 | 198 |
192 database_backend->OpenConnection( | 199 database_backend->OpenConnection( |
193 callbacks, database_callbacks, transaction_id, version); | 200 callbacks, database_callbacks, transaction_id, version, data_loss); |
194 } | 201 } |
195 | 202 |
196 } // namespace content | 203 } // namespace content |
OLD | NEW |