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

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

Issue 259063004: Track which IndexedDBBackingStores have been opened since boot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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(
cmumford 2014/04/29 16:08:34 I'm missing the point of this function.
ericu 2014/04/29 18:24:19 Ah, sorry--there's no actual point in this CL. It
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 data_loss, 364 data_directory,
344 data_loss_message, 365 request_context,
345 disk_full, 366 data_loss,
346 context_->TaskRunner()); 367 data_loss_message,
368 disk_full,
369 first_time);
347 } 370 }
348 371
349 if (backing_store.get()) { 372 if (backing_store.get()) {
373 if (first_time)
374 backends_opened_since_boot_.insert(origin_url);
cmumford 2014/04/29 16:08:34 If this is already a set why calculate/pass the fi
ericu 2014/04/29 18:24:19 I don't understand the question. Do you mean why
350 backing_store_map_[origin_url] = backing_store; 375 backing_store_map_[origin_url] = backing_store;
351 // If an in-memory database, bind lifetime to this factory instance. 376 // If an in-memory database, bind lifetime to this factory instance.
352 if (open_in_memory) 377 if (open_in_memory)
353 session_only_backing_stores_.insert(backing_store); 378 session_only_backing_stores_.insert(backing_store);
354 379
355 // 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
356 // type. 381 // type.
357 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); 382 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory);
358 383
359 return backing_store; 384 return backing_store;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 468
444 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = 469 std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
445 GetOpenDatabasesForOrigin(origin_url); 470 GetOpenDatabasesForOrigin(origin_url);
446 for (OriginDBMapIterator it = range.first; it != range.second; ++it) 471 for (OriginDBMapIterator it = range.first; it != range.second; ++it)
447 count += it->second->ConnectionCount(); 472 count += it->second->ConnectionCount();
448 473
449 return count; 474 return count;
450 } 475 }
451 476
452 } // namespace content 477 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698