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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (it != backing_stores_with_active_blobs_.end()) { | 164 if (it != backing_stores_with_active_blobs_.end()) { |
165 backing_stores_with_active_blobs_.erase(it); | 165 backing_stores_with_active_blobs_.erase(it); |
166 ReleaseBackingStore(origin_url, false /* immediate */); | 166 ReleaseBackingStore(origin_url, false /* immediate */); |
167 } | 167 } |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 void IndexedDBFactory::GetDatabaseNames( | 171 void IndexedDBFactory::GetDatabaseNames( |
172 scoped_refptr<IndexedDBCallbacks> callbacks, | 172 scoped_refptr<IndexedDBCallbacks> callbacks, |
173 const GURL& origin_url, | 173 const GURL& origin_url, |
174 const base::FilePath& data_directory) { | 174 const base::FilePath& data_directory, |
| 175 net::URLRequestContext* request_context) { |
175 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); | 176 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); |
176 // TODO(dgrogan): Plumb data_loss back to script eventually? | 177 // TODO(dgrogan): Plumb data_loss back to script eventually? |
177 blink::WebIDBDataLoss data_loss; | 178 blink::WebIDBDataLoss data_loss; |
178 std::string data_loss_message; | 179 std::string data_loss_message; |
179 bool disk_full; | 180 bool disk_full; |
180 scoped_refptr<IndexedDBBackingStore> backing_store = | 181 scoped_refptr<IndexedDBBackingStore> backing_store = |
181 OpenBackingStore(origin_url, | 182 OpenBackingStore(origin_url, |
182 data_directory, | 183 data_directory, |
183 NULL /* request_context */, | 184 request_context, |
184 &data_loss, | 185 &data_loss, |
185 &data_loss_message, | 186 &data_loss_message, |
186 &disk_full); | 187 &disk_full); |
187 if (!backing_store) { | 188 if (!backing_store) { |
188 callbacks->OnError( | 189 callbacks->OnError( |
189 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 190 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
190 "Internal error opening backing store for " | 191 "Internal error opening backing store for " |
191 "indexedDB.webkitGetDatabaseNames.")); | 192 "indexedDB.webkitGetDatabaseNames.")); |
192 return; | 193 return; |
193 } | 194 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 311 |
311 bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url) | 312 bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url) |
312 const { | 313 const { |
313 IndexedDBBackingStoreMap::const_iterator it = | 314 IndexedDBBackingStoreMap::const_iterator it = |
314 backing_store_map_.find(origin_url); | 315 backing_store_map_.find(origin_url); |
315 if (it == backing_store_map_.end()) | 316 if (it == backing_store_map_.end()) |
316 return false; | 317 return false; |
317 return it->second->close_timer()->IsRunning(); | 318 return it->second->close_timer()->IsRunning(); |
318 } | 319 } |
319 | 320 |
| 321 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStoreHelper( |
| 322 const GURL& origin_url, |
| 323 const base::FilePath& data_directory, |
| 324 net::URLRequestContext* request_context, |
| 325 blink::WebIDBDataLoss* data_loss, |
| 326 std::string* data_loss_message, |
| 327 bool* disk_full, |
| 328 bool first_time) { |
| 329 return IndexedDBBackingStore::Open(this, |
| 330 origin_url, |
| 331 data_directory, |
| 332 request_context, |
| 333 data_loss, |
| 334 data_loss_message, |
| 335 disk_full, |
| 336 context_->TaskRunner(), |
| 337 first_time); |
| 338 } |
| 339 |
320 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 340 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
321 const GURL& origin_url, | 341 const GURL& origin_url, |
322 const base::FilePath& data_directory, | 342 const base::FilePath& data_directory, |
323 net::URLRequestContext* request_context, | 343 net::URLRequestContext* request_context, |
324 blink::WebIDBDataLoss* data_loss, | 344 blink::WebIDBDataLoss* data_loss, |
325 std::string* data_loss_message, | 345 std::string* data_loss_message, |
326 bool* disk_full) { | 346 bool* disk_full) { |
327 const bool open_in_memory = data_directory.empty(); | 347 const bool open_in_memory = data_directory.empty(); |
328 | 348 |
329 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); | 349 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); |
330 if (it2 != backing_store_map_.end()) { | 350 if (it2 != backing_store_map_.end()) { |
331 it2->second->close_timer()->Stop(); | 351 it2->second->close_timer()->Stop(); |
332 return it2->second; | 352 return it2->second; |
333 } | 353 } |
334 | 354 |
335 scoped_refptr<IndexedDBBackingStore> backing_store; | 355 scoped_refptr<IndexedDBBackingStore> backing_store; |
| 356 bool first_time = false; |
336 if (open_in_memory) { | 357 if (open_in_memory) { |
337 backing_store = | 358 backing_store = |
338 IndexedDBBackingStore::OpenInMemory(origin_url, context_->TaskRunner()); | 359 IndexedDBBackingStore::OpenInMemory(origin_url, context_->TaskRunner()); |
339 } else { | 360 } else { |
340 backing_store = IndexedDBBackingStore::Open(this, | 361 first_time = !backends_opened_since_boot_.count(origin_url); |
341 origin_url, | 362 |
342 data_directory, | 363 backing_store = OpenBackingStoreHelper(origin_url, |
343 request_context, | 364 data_directory, |
344 data_loss, | 365 request_context, |
345 data_loss_message, | 366 data_loss, |
346 disk_full, | 367 data_loss_message, |
347 context_->TaskRunner()); | 368 disk_full, |
| 369 first_time); |
348 } | 370 } |
349 | 371 |
350 if (backing_store.get()) { | 372 if (backing_store.get()) { |
| 373 if (first_time) |
| 374 backends_opened_since_boot_.insert(origin_url); |
351 backing_store_map_[origin_url] = backing_store; | 375 backing_store_map_[origin_url] = backing_store; |
352 // If an in-memory database, bind lifetime to this factory instance. | 376 // If an in-memory database, bind lifetime to this factory instance. |
353 if (open_in_memory) | 377 if (open_in_memory) |
354 session_only_backing_stores_.insert(backing_store); | 378 session_only_backing_stores_.insert(backing_store); |
355 | 379 |
356 // All backing stores associated with this factory should be of the same | 380 // All backing stores associated with this factory should be of the same |
357 // type. | 381 // type. |
358 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); | 382 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); |
359 | 383 |
360 return backing_store; | 384 return backing_store; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 468 |
445 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 469 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
446 GetOpenDatabasesForOrigin(origin_url); | 470 GetOpenDatabasesForOrigin(origin_url); |
447 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 471 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
448 count += it->second->ConnectionCount(); | 472 count += it->second->ConnectionCount(); |
449 | 473 |
450 return count; | 474 return count; |
451 } | 475 } |
452 | 476 |
453 } // namespace content | 477 } // namespace content |
OLD | NEW |