| 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 "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 backing_store_map_.clear(); | 102 backing_store_map_.clear(); |
| 103 context_ = NULL; | 103 context_ = NULL; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void IndexedDBFactory::GetDatabaseNames( | 106 void IndexedDBFactory::GetDatabaseNames( |
| 107 scoped_refptr<IndexedDBCallbacks> callbacks, | 107 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 108 const GURL& origin_url, | 108 const GURL& origin_url, |
| 109 const base::FilePath& data_directory) { | 109 const base::FilePath& data_directory) { |
| 110 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); | 110 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); |
| 111 // TODO(dgrogan): Plumb data_loss back to script eventually? | 111 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 112 WebKit::WebIDBCallbacks::DataLoss data_loss; | 112 blink::WebIDBCallbacks::DataLoss data_loss; |
| 113 std::string data_loss_message; | 113 std::string data_loss_message; |
| 114 bool disk_full; | 114 bool disk_full; |
| 115 scoped_refptr<IndexedDBBackingStore> backing_store = | 115 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 116 OpenBackingStore(origin_url, | 116 OpenBackingStore(origin_url, |
| 117 data_directory, | 117 data_directory, |
| 118 &data_loss, | 118 &data_loss, |
| 119 &data_loss_message, | 119 &data_loss_message, |
| 120 &disk_full); | 120 &disk_full); |
| 121 if (!backing_store) { | 121 if (!backing_store) { |
| 122 callbacks->OnError( | 122 callbacks->OnError( |
| 123 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 123 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 124 "Internal error opening backing store for " | 124 "Internal error opening backing store for " |
| 125 "indexedDB.webkitGetDatabaseNames.")); | 125 "indexedDB.webkitGetDatabaseNames.")); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 129 callbacks->OnSuccess(backing_store->GetDatabaseNames()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void IndexedDBFactory::DeleteDatabase( | 132 void IndexedDBFactory::DeleteDatabase( |
| 133 const string16& name, | 133 const string16& name, |
| 134 scoped_refptr<IndexedDBCallbacks> callbacks, | 134 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 135 const GURL& origin_url, | 135 const GURL& origin_url, |
| 136 const base::FilePath& data_directory) { | 136 const base::FilePath& data_directory) { |
| 137 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 137 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); |
| 138 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 138 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| 139 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 139 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
| 140 if (it != database_map_.end()) { | 140 if (it != database_map_.end()) { |
| 141 // If there are any connections to the database, directly delete the | 141 // If there are any connections to the database, directly delete the |
| 142 // database. | 142 // database. |
| 143 it->second->DeleteDatabase(callbacks); | 143 it->second->DeleteDatabase(callbacks); |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 | 146 |
| 147 // TODO(dgrogan): Plumb data_loss back to script eventually? | 147 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 148 WebKit::WebIDBCallbacks::DataLoss data_loss; | 148 blink::WebIDBCallbacks::DataLoss data_loss; |
| 149 std::string data_loss_message; | 149 std::string data_loss_message; |
| 150 bool disk_full = false; | 150 bool disk_full = false; |
| 151 scoped_refptr<IndexedDBBackingStore> backing_store = | 151 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 152 OpenBackingStore(origin_url, | 152 OpenBackingStore(origin_url, |
| 153 data_directory, | 153 data_directory, |
| 154 &data_loss, | 154 &data_loss, |
| 155 &data_loss_message, | 155 &data_loss_message, |
| 156 &disk_full); | 156 &disk_full); |
| 157 if (!backing_store) { | 157 if (!backing_store) { |
| 158 callbacks->OnError( | 158 callbacks->OnError( |
| 159 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 159 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 160 ASCIIToUTF16( | 160 ASCIIToUTF16( |
| 161 "Internal error opening backing store " | 161 "Internal error opening backing store " |
| 162 "for indexedDB.deleteDatabase."))); | 162 "for indexedDB.deleteDatabase."))); |
| 163 return; | 163 return; |
| 164 } | 164 } |
| 165 | 165 |
| 166 scoped_refptr<IndexedDBDatabase> database = | 166 scoped_refptr<IndexedDBDatabase> database = |
| 167 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 167 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); |
| 168 if (!database) { | 168 if (!database) { |
| 169 callbacks->OnError(IndexedDBDatabaseError( | 169 callbacks->OnError(IndexedDBDatabaseError( |
| 170 WebKit::WebIDBDatabaseExceptionUnknownError, | 170 blink::WebIDBDatabaseExceptionUnknownError, |
| 171 ASCIIToUTF16( | 171 ASCIIToUTF16( |
| 172 "Internal error creating database backend for " | 172 "Internal error creating database backend for " |
| 173 "indexedDB.deleteDatabase."))); | 173 "indexedDB.deleteDatabase."))); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 database_map_[unique_identifier] = database; | 177 database_map_[unique_identifier] = database; |
| 178 database->DeleteDatabase(callbacks); | 178 database->DeleteDatabase(callbacks); |
| 179 database_map_.erase(unique_identifier); | 179 database_map_.erase(unique_identifier); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { | 182 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { |
| 183 // NULL after ContextDestroyed() called, and in some unit tests. | 183 // NULL after ContextDestroyed() called, and in some unit tests. |
| 184 if (!context_) | 184 if (!context_) |
| 185 return; | 185 return; |
| 186 context_->ForceClose(origin_url); | 186 context_->ForceClose(origin_url); |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool IndexedDBFactory::IsBackingStoreOpenForTesting(const GURL& origin_url) | 189 bool IndexedDBFactory::IsBackingStoreOpenForTesting(const GURL& origin_url) |
| 190 const { | 190 const { |
| 191 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 191 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 194 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
| 195 const GURL& origin_url, | 195 const GURL& origin_url, |
| 196 const base::FilePath& data_directory, | 196 const base::FilePath& data_directory, |
| 197 WebKit::WebIDBCallbacks::DataLoss* data_loss, | 197 blink::WebIDBCallbacks::DataLoss* data_loss, |
| 198 std::string* data_loss_message, | 198 std::string* data_loss_message, |
| 199 bool* disk_full) { | 199 bool* disk_full) { |
| 200 const bool open_in_memory = data_directory.empty(); | 200 const bool open_in_memory = data_directory.empty(); |
| 201 | 201 |
| 202 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); | 202 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); |
| 203 if (it2 != backing_store_map_.end()) { | 203 if (it2 != backing_store_map_.end()) { |
| 204 it2->second->close_timer()->Stop(); | 204 it2->second->close_timer()->Stop(); |
| 205 return it2->second; | 205 return it2->second; |
| 206 } | 206 } |
| 207 | 207 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 237 int64 version, | 237 int64 version, |
| 238 int64 transaction_id, | 238 int64 transaction_id, |
| 239 scoped_refptr<IndexedDBCallbacks> callbacks, | 239 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 240 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 240 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 241 const GURL& origin_url, | 241 const GURL& origin_url, |
| 242 const base::FilePath& data_directory) { | 242 const base::FilePath& data_directory) { |
| 243 IDB_TRACE("IndexedDBFactory::Open"); | 243 IDB_TRACE("IndexedDBFactory::Open"); |
| 244 scoped_refptr<IndexedDBDatabase> database; | 244 scoped_refptr<IndexedDBDatabase> database; |
| 245 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 245 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| 246 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 246 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
| 247 WebKit::WebIDBCallbacks::DataLoss data_loss = | 247 blink::WebIDBCallbacks::DataLoss data_loss = |
| 248 WebKit::WebIDBCallbacks::DataLossNone; | 248 blink::WebIDBCallbacks::DataLossNone; |
| 249 std::string data_loss_message; | 249 std::string data_loss_message; |
| 250 bool disk_full = false; | 250 bool disk_full = false; |
| 251 if (it == database_map_.end()) { | 251 if (it == database_map_.end()) { |
| 252 scoped_refptr<IndexedDBBackingStore> backing_store = | 252 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 253 OpenBackingStore(origin_url, | 253 OpenBackingStore(origin_url, |
| 254 data_directory, | 254 data_directory, |
| 255 &data_loss, | 255 &data_loss, |
| 256 &data_loss_message, | 256 &data_loss_message, |
| 257 &disk_full); | 257 &disk_full); |
| 258 if (!backing_store) { | 258 if (!backing_store) { |
| 259 if (disk_full) { | 259 if (disk_full) { |
| 260 callbacks->OnError( | 260 callbacks->OnError( |
| 261 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError, | 261 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError, |
| 262 ASCIIToUTF16( | 262 ASCIIToUTF16( |
| 263 "Encountered full disk while opening " | 263 "Encountered full disk while opening " |
| 264 "backing store for indexedDB.open."))); | 264 "backing store for indexedDB.open."))); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 callbacks->OnError(IndexedDBDatabaseError( | 267 callbacks->OnError(IndexedDBDatabaseError( |
| 268 WebKit::WebIDBDatabaseExceptionUnknownError, | 268 blink::WebIDBDatabaseExceptionUnknownError, |
| 269 ASCIIToUTF16( | 269 ASCIIToUTF16( |
| 270 "Internal error opening backing store for indexedDB.open."))); | 270 "Internal error opening backing store for indexedDB.open."))); |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 | 273 |
| 274 database = | 274 database = |
| 275 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); | 275 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); |
| 276 if (!database) { | 276 if (!database) { |
| 277 callbacks->OnError(IndexedDBDatabaseError( | 277 callbacks->OnError(IndexedDBDatabaseError( |
| 278 WebKit::WebIDBDatabaseExceptionUnknownError, | 278 blink::WebIDBDatabaseExceptionUnknownError, |
| 279 ASCIIToUTF16( | 279 ASCIIToUTF16( |
| 280 "Internal error creating database backend for indexedDB.open."))); | 280 "Internal error creating database backend for indexedDB.open."))); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 database_map_[unique_identifier] = database; | 284 database_map_[unique_identifier] = database; |
| 285 } else { | 285 } else { |
| 286 database = it->second; | 286 database = it->second; |
| 287 } | 287 } |
| 288 | 288 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 300 for (IndexedDBDatabaseMap::const_iterator it = database_map_.begin(); | 300 for (IndexedDBDatabaseMap::const_iterator it = database_map_.begin(); |
| 301 it != database_map_.end(); | 301 it != database_map_.end(); |
| 302 ++it) { | 302 ++it) { |
| 303 if (it->first.first == origin_url) | 303 if (it->first.first == origin_url) |
| 304 result.push_back(it->second.get()); | 304 result.push_back(it->second.get()); |
| 305 } | 305 } |
| 306 return result; | 306 return result; |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace content | 309 } // namespace content |
| OLD | NEW |