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

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

Issue 203833003: Add the IndexedDBActiveBlobRegistry, currently unused, to enable future blob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix override mismatch Created 6 years, 8 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 RemoveDatabaseFromMaps(identifier); 53 RemoveDatabaseFromMaps(identifier);
54 54
55 // No grace period on a forced-close, as the initiator is 55 // No grace period on a forced-close, as the initiator is
56 // assuming the backing store will be released once all 56 // assuming the backing store will be released once all
57 // connections are closed. 57 // connections are closed.
58 ReleaseBackingStore(identifier.first, forcedClose); 58 ReleaseBackingStore(identifier.first, forcedClose);
59 } 59 }
60 60
61 void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url, 61 void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url,
62 bool immediate) { 62 bool immediate) {
63 if (immediate) {
64 IndexedDBBackingStoreMap::iterator it =
65 backing_stores_with_active_blobs_.find(origin_url);
66 if (it != backing_stores_with_active_blobs_.end()) {
67 it->second->active_blob_registry()->ForceShutdown();
68 backing_stores_with_active_blobs_.erase(it);
69 }
70 }
71
63 // Only close if this is the last reference. 72 // Only close if this is the last reference.
64 if (!HasLastBackingStoreReference(origin_url)) 73 if (!HasLastBackingStoreReference(origin_url))
65 return; 74 return;
66 75
67 // If this factory does hold the last reference to the backing store, it can 76 // If this factory does hold the last reference to the backing store, it can
68 // be closed - but unless requested to close it immediately, keep it around 77 // be closed - but unless requested to close it immediately, keep it around
69 // for a short period so that a re-open is fast. 78 // for a short period so that a re-open is fast.
70 if (immediate) { 79 if (immediate) {
71 CloseBackingStore(origin_url); 80 CloseBackingStore(origin_url);
72 return; 81 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 void IndexedDBFactory::ContextDestroyed() { 136 void IndexedDBFactory::ContextDestroyed() {
128 // Timers on backing stores hold a reference to this factory. When the 137 // Timers on backing stores hold a reference to this factory. When the
129 // context (which nominally owns this factory) is destroyed during thread 138 // context (which nominally owns this factory) is destroyed during thread
130 // termination the timers must be stopped so that this factory and the 139 // termination the timers must be stopped so that this factory and the
131 // stores can be disposed of. 140 // stores can be disposed of.
132 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin(); 141 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin();
133 it != backing_store_map_.end(); 142 it != backing_store_map_.end();
134 ++it) 143 ++it)
135 it->second->close_timer()->Stop(); 144 it->second->close_timer()->Stop();
136 backing_store_map_.clear(); 145 backing_store_map_.clear();
146 backing_stores_with_active_blobs_.clear();
137 context_ = NULL; 147 context_ = NULL;
138 } 148 }
139 149
150 void IndexedDBFactory::ReportOutstandingBlobs(const GURL& origin_url,
151 bool blobs_outstanding) {
152 if (!context_)
153 return;
154 if (blobs_outstanding) {
155 DCHECK(!backing_stores_with_active_blobs_.count(origin_url));
156 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url);
157 if (it != backing_store_map_.end())
158 backing_stores_with_active_blobs_.insert(*it);
159 else
160 DCHECK(false);
161 } else {
162 IndexedDBBackingStoreMap::iterator it =
163 backing_stores_with_active_blobs_.find(origin_url);
164 if (it != backing_stores_with_active_blobs_.end()) {
165 backing_stores_with_active_blobs_.erase(it);
166 ReleaseBackingStore(origin_url, false /* immediate */);
167 }
168 }
169 }
170
140 void IndexedDBFactory::GetDatabaseNames( 171 void IndexedDBFactory::GetDatabaseNames(
141 scoped_refptr<IndexedDBCallbacks> callbacks, 172 scoped_refptr<IndexedDBCallbacks> callbacks,
142 const GURL& origin_url, 173 const GURL& origin_url,
143 const base::FilePath& data_directory) { 174 const base::FilePath& data_directory) {
144 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); 175 IDB_TRACE("IndexedDBFactory::GetDatabaseNames");
145 // TODO(dgrogan): Plumb data_loss back to script eventually? 176 // TODO(dgrogan): Plumb data_loss back to script eventually?
146 blink::WebIDBDataLoss data_loss; 177 blink::WebIDBDataLoss data_loss;
147 std::string data_loss_message; 178 std::string data_loss_message;
148 bool disk_full; 179 bool disk_full;
149 scoped_refptr<IndexedDBBackingStore> backing_store = 180 scoped_refptr<IndexedDBBackingStore> backing_store =
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 const bool open_in_memory = data_directory.empty(); 312 const bool open_in_memory = data_directory.empty();
282 313
283 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); 314 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url);
284 if (it2 != backing_store_map_.end()) { 315 if (it2 != backing_store_map_.end()) {
285 it2->second->close_timer()->Stop(); 316 it2->second->close_timer()->Stop();
286 return it2->second; 317 return it2->second;
287 } 318 }
288 319
289 scoped_refptr<IndexedDBBackingStore> backing_store; 320 scoped_refptr<IndexedDBBackingStore> backing_store;
290 if (open_in_memory) { 321 if (open_in_memory) {
291 backing_store = IndexedDBBackingStore::OpenInMemory(origin_url); 322 backing_store =
323 IndexedDBBackingStore::OpenInMemory(origin_url, context_->TaskRunner());
292 } else { 324 } else {
293 backing_store = IndexedDBBackingStore::Open(origin_url, 325 backing_store = IndexedDBBackingStore::Open(this,
326 origin_url,
294 data_directory, 327 data_directory,
295 data_loss, 328 data_loss,
296 data_loss_message, 329 data_loss_message,
297 disk_full); 330 disk_full,
331 context_->TaskRunner());
298 } 332 }
299 333
300 if (backing_store.get()) { 334 if (backing_store.get()) {
301 backing_store_map_[origin_url] = backing_store; 335 backing_store_map_[origin_url] = backing_store;
302 // If an in-memory database, bind lifetime to this factory instance. 336 // If an in-memory database, bind lifetime to this factory instance.
303 if (open_in_memory) 337 if (open_in_memory)
304 session_only_backing_stores_.insert(backing_store); 338 session_only_backing_stores_.insert(backing_store);
305 339
306 // All backing stores associated with this factory should be of the same 340 // All backing stores associated with this factory should be of the same
307 // type. 341 // type.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 418
385 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = 419 std::pair<OriginDBMapIterator, OriginDBMapIterator> range =
386 GetOpenDatabasesForOrigin(origin_url); 420 GetOpenDatabasesForOrigin(origin_url);
387 for (OriginDBMapIterator it = range.first; it != range.second; ++it) 421 for (OriginDBMapIterator it = range.first; it != range.second; ++it)
388 count += it->second->ConnectionCount(); 422 count += it->second->ConnectionCount();
389 423
390 return count; 424 return count;
391 } 425 }
392 426
393 } // namespace content 427 } // 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