Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: content/browser/indexed_db/indexed_db_factory.cc

Issue 198223002: Added IndexedDBPendingConnection to group up a bunch of parameters that get (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge out Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // All backing stores associated with this factory should be of the same 287 // All backing stores associated with this factory should be of the same
288 // type. 288 // type.
289 DCHECK(session_only_backing_stores_.empty() || open_in_memory); 289 DCHECK(session_only_backing_stores_.empty() || open_in_memory);
290 290
291 return backing_store; 291 return backing_store;
292 } 292 }
293 293
294 return 0; 294 return 0;
295 } 295 }
296 296
297 void IndexedDBFactory::Open( 297 void IndexedDBFactory::Open(const base::string16& name,
298 const base::string16& name, 298 const IndexedDBPendingConnection& connection,
299 int64 version, 299 const GURL& origin_url,
300 int64 transaction_id, 300 const base::FilePath& data_directory) {
301 scoped_refptr<IndexedDBCallbacks> callbacks,
302 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
303 const GURL& origin_url,
304 const base::FilePath& data_directory) {
305 IDB_TRACE("IndexedDBFactory::Open"); 301 IDB_TRACE("IndexedDBFactory::Open");
306 scoped_refptr<IndexedDBDatabase> database; 302 scoped_refptr<IndexedDBDatabase> database;
307 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); 303 IndexedDBDatabase::Identifier unique_identifier(origin_url, name);
308 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); 304 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier);
309 blink::WebIDBDataLoss data_loss = 305 blink::WebIDBDataLoss data_loss =
310 blink::WebIDBDataLossNone; 306 blink::WebIDBDataLossNone;
311 std::string data_loss_message; 307 std::string data_loss_message;
312 bool disk_full = false; 308 bool disk_full = false;
313 bool was_open = (it != database_map_.end()); 309 bool was_open = (it != database_map_.end());
314 if (!was_open) { 310 if (!was_open) {
315 scoped_refptr<IndexedDBBackingStore> backing_store = 311 scoped_refptr<IndexedDBBackingStore> backing_store =
316 OpenBackingStore(origin_url, 312 OpenBackingStore(origin_url,
317 data_directory, 313 data_directory,
318 &data_loss, 314 &data_loss,
319 &data_loss_message, 315 &data_loss_message,
320 &disk_full); 316 &disk_full);
321 if (!backing_store) { 317 if (!backing_store) {
322 if (disk_full) { 318 if (disk_full) {
323 callbacks->OnError( 319 connection.callbacks->OnError(
324 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError, 320 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError,
325 ASCIIToUTF16( 321 ASCIIToUTF16(
326 "Encountered full disk while opening " 322 "Encountered full disk while opening "
327 "backing store for indexedDB.open."))); 323 "backing store for indexedDB.open.")));
328 return; 324 return;
329 } 325 }
330 callbacks->OnError(IndexedDBDatabaseError( 326 connection.callbacks->OnError(IndexedDBDatabaseError(
331 blink::WebIDBDatabaseExceptionUnknownError, 327 blink::WebIDBDatabaseExceptionUnknownError,
332 ASCIIToUTF16( 328 ASCIIToUTF16(
333 "Internal error opening backing store for indexedDB.open."))); 329 "Internal error opening backing store for indexedDB.open.")));
334 return; 330 return;
335 } 331 }
336 332
337 database = 333 database =
338 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier); 334 IndexedDBDatabase::Create(name, backing_store, this, unique_identifier);
339 if (!database) { 335 if (!database) {
340 callbacks->OnError(IndexedDBDatabaseError( 336 connection.callbacks->OnError(IndexedDBDatabaseError(
341 blink::WebIDBDatabaseExceptionUnknownError, 337 blink::WebIDBDatabaseExceptionUnknownError,
342 ASCIIToUTF16( 338 ASCIIToUTF16(
343 "Internal error creating database backend for indexedDB.open."))); 339 "Internal error creating database backend for indexedDB.open.")));
344 return; 340 return;
345 } 341 }
346 } else { 342 } else {
347 database = it->second; 343 database = it->second;
348 } 344 }
349 345
350 if (data_loss != blink::WebIDBDataLossNone) 346 if (data_loss != blink::WebIDBDataLossNone)
351 callbacks->OnDataLoss(data_loss, data_loss_message); 347 connection.callbacks->OnDataLoss(data_loss, data_loss_message);
352 348
353 database->OpenConnection( 349 database->OpenConnection(connection);
354 callbacks, database_callbacks, transaction_id, version);
355 350
356 if (!was_open && database->ConnectionCount() > 0) { 351 if (!was_open && database->ConnectionCount() > 0) {
357 database_map_[unique_identifier] = database; 352 database_map_[unique_identifier] = database;
358 origin_dbs_.insert(std::make_pair(origin_url, database)); 353 origin_dbs_.insert(std::make_pair(origin_url, database));
359 } 354 }
360 } 355 }
361 356
362 std::pair<IndexedDBFactory::OriginDBMapIterator, 357 std::pair<IndexedDBFactory::OriginDBMapIterator,
363 IndexedDBFactory::OriginDBMapIterator> 358 IndexedDBFactory::OriginDBMapIterator>
364 IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const { 359 IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const {
365 return origin_dbs_.equal_range(origin_url); 360 return origin_dbs_.equal_range(origin_url);
366 } 361 }
367 362
368 size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const { 363 size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const {
369 size_t count(0); 364 size_t count(0);
370 365
371 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = 366 std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
372 GetOpenDatabasesForOrigin(origin_url); 367 GetOpenDatabasesForOrigin(origin_url);
373 for (OriginDBMapIterator it = range.first; it != range.second; ++it) 368 for (OriginDBMapIterator it = range.first; it != range.second; ++it)
374 count += it->second->ConnectionCount(); 369 count += it->second->ConnectionCount();
375 370
376 return count; 371 return count;
377 } 372 }
378 373
379 } // namespace content 374 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.h ('k') | content/browser/indexed_db/indexed_db_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698