| 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_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 12 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 13 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 13 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 14 #include "content/browser/indexed_db/indexed_db_database_error.h" | 14 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 15 #include "content/browser/indexed_db/indexed_db_tracing.h" | 15 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 16 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 16 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 17 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 17 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 18 #include "third_party/leveldatabase/env_chromium.h" | 18 #include "third_party/leveldatabase/env_chromium.h" |
| 19 #include "webkit/common/database/database_identifier.h" | 19 #include "webkit/common/database/database_identifier.h" |
| 20 | 20 |
| 21 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 const int64 kBackingStoreGracePeriodMs = 2000; | 25 const int64 kBackingStoreGracePeriodMs = 2000; |
| 26 | 26 |
| 27 IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context) | 27 IndexedDBFactoryImpl::IndexedDBFactoryImpl(IndexedDBContextImpl* context) |
| 28 : context_(context) {} | 28 : context_(context) { |
| 29 } |
| 29 | 30 |
| 30 IndexedDBFactory::~IndexedDBFactory() {} | 31 IndexedDBFactoryImpl::~IndexedDBFactoryImpl() { |
| 32 } |
| 31 | 33 |
| 32 void IndexedDBFactory::RemoveDatabaseFromMaps( | 34 void IndexedDBFactoryImpl::RemoveDatabaseFromMaps( |
| 33 const IndexedDBDatabase::Identifier& identifier) { | 35 const IndexedDBDatabase::Identifier& identifier) { |
| 34 IndexedDBDatabaseMap::iterator it = database_map_.find(identifier); | 36 IndexedDBDatabaseMap::iterator it = database_map_.find(identifier); |
| 35 DCHECK(it != database_map_.end()); | 37 DCHECK(it != database_map_.end()); |
| 36 IndexedDBDatabase* database = it->second; | 38 IndexedDBDatabase* database = it->second; |
| 37 database_map_.erase(it); | 39 database_map_.erase(it); |
| 38 | 40 |
| 39 std::pair<OriginDBMap::iterator, OriginDBMap::iterator> range = | 41 std::pair<OriginDBMap::iterator, OriginDBMap::iterator> range = |
| 40 origin_dbs_.equal_range(database->identifier().first); | 42 origin_dbs_.equal_range(database->identifier().first); |
| 41 DCHECK(range.first != range.second); | 43 DCHECK(range.first != range.second); |
| 42 for (OriginDBMap::iterator it2 = range.first; it2 != range.second; ++it2) { | 44 for (OriginDBMap::iterator it2 = range.first; it2 != range.second; ++it2) { |
| 43 if (it2->second == database) { | 45 if (it2->second == database) { |
| 44 origin_dbs_.erase(it2); | 46 origin_dbs_.erase(it2); |
| 45 break; | 47 break; |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 } | 50 } |
| 49 | 51 |
| 50 void IndexedDBFactory::ReleaseDatabase( | 52 void IndexedDBFactoryImpl::ReleaseDatabase( |
| 51 const IndexedDBDatabase::Identifier& identifier, | 53 const IndexedDBDatabase::Identifier& identifier, |
| 52 bool forcedClose) { | 54 bool forcedClose) { |
| 53 | |
| 54 DCHECK(!database_map_.find(identifier)->second->backing_store()); | 55 DCHECK(!database_map_.find(identifier)->second->backing_store()); |
| 55 | 56 |
| 56 RemoveDatabaseFromMaps(identifier); | 57 RemoveDatabaseFromMaps(identifier); |
| 57 | 58 |
| 58 // No grace period on a forced-close, as the initiator is | 59 // No grace period on a forced-close, as the initiator is |
| 59 // assuming the backing store will be released once all | 60 // assuming the backing store will be released once all |
| 60 // connections are closed. | 61 // connections are closed. |
| 61 ReleaseBackingStore(identifier.first, forcedClose); | 62 ReleaseBackingStore(identifier.first, forcedClose); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url, | 65 void IndexedDBFactoryImpl::ReleaseBackingStore(const GURL& origin_url, |
| 65 bool immediate) { | 66 bool immediate) { |
| 66 if (immediate) { | 67 if (immediate) { |
| 67 IndexedDBBackingStoreMap::iterator it = | 68 IndexedDBBackingStoreMap::iterator it = |
| 68 backing_stores_with_active_blobs_.find(origin_url); | 69 backing_stores_with_active_blobs_.find(origin_url); |
| 69 if (it != backing_stores_with_active_blobs_.end()) { | 70 if (it != backing_stores_with_active_blobs_.end()) { |
| 70 it->second->active_blob_registry()->ForceShutdown(); | 71 it->second->active_blob_registry()->ForceShutdown(); |
| 71 backing_stores_with_active_blobs_.erase(it); | 72 backing_stores_with_active_blobs_.erase(it); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Only close if this is the last reference. | 76 // Only close if this is the last reference. |
| 76 if (!HasLastBackingStoreReference(origin_url)) | 77 if (!HasLastBackingStoreReference(origin_url)) |
| 77 return; | 78 return; |
| 78 | 79 |
| 79 // If this factory does hold the last reference to the backing store, it can | 80 // If this factory does hold the last reference to the backing store, it can |
| 80 // be closed - but unless requested to close it immediately, keep it around | 81 // be closed - but unless requested to close it immediately, keep it around |
| 81 // for a short period so that a re-open is fast. | 82 // for a short period so that a re-open is fast. |
| 82 if (immediate) { | 83 if (immediate) { |
| 83 CloseBackingStore(origin_url); | 84 CloseBackingStore(origin_url); |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 | 87 |
| 87 // Start a timer to close the backing store, unless something else opens it | 88 // Start a timer to close the backing store, unless something else opens it |
| 88 // in the mean time. | 89 // in the mean time. |
| 89 DCHECK(!backing_store_map_[origin_url]->close_timer()->IsRunning()); | 90 DCHECK(!backing_store_map_[origin_url]->close_timer()->IsRunning()); |
| 90 backing_store_map_[origin_url]->close_timer()->Start( | 91 backing_store_map_[origin_url]->close_timer()->Start( |
| 91 FROM_HERE, | 92 FROM_HERE, |
| 92 base::TimeDelta::FromMilliseconds(kBackingStoreGracePeriodMs), | 93 base::TimeDelta::FromMilliseconds(kBackingStoreGracePeriodMs), |
| 93 base::Bind(&IndexedDBFactory::MaybeCloseBackingStore, this, origin_url)); | 94 base::Bind( |
| 95 &IndexedDBFactoryImpl::MaybeCloseBackingStore, this, origin_url)); |
| 94 } | 96 } |
| 95 | 97 |
| 96 void IndexedDBFactory::MaybeCloseBackingStore(const GURL& origin_url) { | 98 void IndexedDBFactoryImpl::MaybeCloseBackingStore(const GURL& origin_url) { |
| 97 // Another reference may have opened since the maybe-close was posted, so it | 99 // Another reference may have opened since the maybe-close was posted, so it |
| 98 // is necessary to check again. | 100 // is necessary to check again. |
| 99 if (HasLastBackingStoreReference(origin_url)) | 101 if (HasLastBackingStoreReference(origin_url)) |
| 100 CloseBackingStore(origin_url); | 102 CloseBackingStore(origin_url); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void IndexedDBFactory::CloseBackingStore(const GURL& origin_url) { | 105 void IndexedDBFactoryImpl::CloseBackingStore(const GURL& origin_url) { |
| 104 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); | 106 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); |
| 105 DCHECK(it != backing_store_map_.end()); | 107 DCHECK(it != backing_store_map_.end()); |
| 106 // Stop the timer (if it's running) - this may happen if the timer was started | 108 // Stop the timer (if it's running) - this may happen if the timer was started |
| 107 // and then a forced close occurs. | 109 // and then a forced close occurs. |
| 108 it->second->close_timer()->Stop(); | 110 it->second->close_timer()->Stop(); |
| 109 backing_store_map_.erase(it); | 111 backing_store_map_.erase(it); |
| 110 } | 112 } |
| 111 | 113 |
| 112 bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url) | 114 bool IndexedDBFactoryImpl::HasLastBackingStoreReference( |
| 113 const { | 115 const GURL& origin_url) const { |
| 114 IndexedDBBackingStore* ptr; | 116 IndexedDBBackingStore* ptr; |
| 115 { | 117 { |
| 116 // Scope so that the implicit scoped_refptr<> is freed. | 118 // Scope so that the implicit scoped_refptr<> is freed. |
| 117 IndexedDBBackingStoreMap::const_iterator it = | 119 IndexedDBBackingStoreMap::const_iterator it = |
| 118 backing_store_map_.find(origin_url); | 120 backing_store_map_.find(origin_url); |
| 119 DCHECK(it != backing_store_map_.end()); | 121 DCHECK(it != backing_store_map_.end()); |
| 120 ptr = it->second.get(); | 122 ptr = it->second.get(); |
| 121 } | 123 } |
| 122 return ptr->HasOneRef(); | 124 return ptr->HasOneRef(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void IndexedDBFactory::ForceClose(const GURL& origin_url) { | 127 void IndexedDBFactoryImpl::ForceClose(const GURL& origin_url) { |
| 126 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 128 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
| 127 GetOpenDatabasesForOrigin(origin_url); | 129 GetOpenDatabasesForOrigin(origin_url); |
| 128 | 130 |
| 129 while (range.first != range.second) { | 131 while (range.first != range.second) { |
| 130 IndexedDBDatabase* db = range.first->second; | 132 IndexedDBDatabase* db = range.first->second; |
| 131 ++range.first; | 133 ++range.first; |
| 132 db->ForceClose(); | 134 db->ForceClose(); |
| 133 } | 135 } |
| 134 | 136 |
| 135 if (backing_store_map_.find(origin_url) != backing_store_map_.end()) | 137 if (backing_store_map_.find(origin_url) != backing_store_map_.end()) |
| 136 ReleaseBackingStore(origin_url, true /* immediate */); | 138 ReleaseBackingStore(origin_url, true /* immediate */); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void IndexedDBFactory::ContextDestroyed() { | 141 void IndexedDBFactoryImpl::ContextDestroyed() { |
| 140 // Timers on backing stores hold a reference to this factory. When the | 142 // Timers on backing stores hold a reference to this factory. When the |
| 141 // context (which nominally owns this factory) is destroyed during thread | 143 // context (which nominally owns this factory) is destroyed during thread |
| 142 // termination the timers must be stopped so that this factory and the | 144 // termination the timers must be stopped so that this factory and the |
| 143 // stores can be disposed of. | 145 // stores can be disposed of. |
| 144 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin(); | 146 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin(); |
| 145 it != backing_store_map_.end(); | 147 it != backing_store_map_.end(); |
| 146 ++it) | 148 ++it) |
| 147 it->second->close_timer()->Stop(); | 149 it->second->close_timer()->Stop(); |
| 148 backing_store_map_.clear(); | 150 backing_store_map_.clear(); |
| 149 backing_stores_with_active_blobs_.clear(); | 151 backing_stores_with_active_blobs_.clear(); |
| 150 context_ = NULL; | 152 context_ = NULL; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void IndexedDBFactory::ReportOutstandingBlobs(const GURL& origin_url, | 155 void IndexedDBFactoryImpl::ReportOutstandingBlobs(const GURL& origin_url, |
| 154 bool blobs_outstanding) { | 156 bool blobs_outstanding) { |
| 155 if (!context_) | 157 if (!context_) |
| 156 return; | 158 return; |
| 157 if (blobs_outstanding) { | 159 if (blobs_outstanding) { |
| 158 DCHECK(!backing_stores_with_active_blobs_.count(origin_url)); | 160 DCHECK(!backing_stores_with_active_blobs_.count(origin_url)); |
| 159 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); | 161 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); |
| 160 if (it != backing_store_map_.end()) | 162 if (it != backing_store_map_.end()) |
| 161 backing_stores_with_active_blobs_.insert(*it); | 163 backing_stores_with_active_blobs_.insert(*it); |
| 162 else | 164 else |
| 163 DCHECK(false); | 165 DCHECK(false); |
| 164 } else { | 166 } else { |
| 165 IndexedDBBackingStoreMap::iterator it = | 167 IndexedDBBackingStoreMap::iterator it = |
| 166 backing_stores_with_active_blobs_.find(origin_url); | 168 backing_stores_with_active_blobs_.find(origin_url); |
| 167 if (it != backing_stores_with_active_blobs_.end()) { | 169 if (it != backing_stores_with_active_blobs_.end()) { |
| 168 backing_stores_with_active_blobs_.erase(it); | 170 backing_stores_with_active_blobs_.erase(it); |
| 169 ReleaseBackingStore(origin_url, false /* immediate */); | 171 ReleaseBackingStore(origin_url, false /* immediate */); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 void IndexedDBFactory::GetDatabaseNames( | 176 void IndexedDBFactoryImpl::GetDatabaseNames( |
| 175 scoped_refptr<IndexedDBCallbacks> callbacks, | 177 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 176 const GURL& origin_url, | 178 const GURL& origin_url, |
| 177 const base::FilePath& data_directory, | 179 const base::FilePath& data_directory, |
| 178 net::URLRequestContext* request_context) { | 180 net::URLRequestContext* request_context) { |
| 179 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); | 181 IDB_TRACE("IndexedDBFactoryImpl::GetDatabaseNames"); |
| 180 // TODO(dgrogan): Plumb data_loss back to script eventually? | 182 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 181 blink::WebIDBDataLoss data_loss; | 183 blink::WebIDBDataLoss data_loss; |
| 182 std::string data_loss_message; | 184 std::string data_loss_message; |
| 183 bool disk_full; | 185 bool disk_full; |
| 184 leveldb::Status s; | 186 leveldb::Status s; |
| 185 // TODO(cmumford): Handle this error | 187 // TODO(cmumford): Handle this error |
| 186 scoped_refptr<IndexedDBBackingStore> backing_store = | 188 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 187 OpenBackingStore(origin_url, | 189 OpenBackingStore(origin_url, |
| 188 data_directory, | 190 data_directory, |
| 189 request_context, | 191 request_context, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 209 backing_store = NULL; | 211 backing_store = NULL; |
| 210 if (s.IsCorruption()) | 212 if (s.IsCorruption()) |
| 211 HandleBackingStoreCorruption(origin_url, error); | 213 HandleBackingStoreCorruption(origin_url, error); |
| 212 return; | 214 return; |
| 213 } | 215 } |
| 214 callbacks->OnSuccess(names); | 216 callbacks->OnSuccess(names); |
| 215 backing_store = NULL; | 217 backing_store = NULL; |
| 216 ReleaseBackingStore(origin_url, false /* immediate */); | 218 ReleaseBackingStore(origin_url, false /* immediate */); |
| 217 } | 219 } |
| 218 | 220 |
| 219 void IndexedDBFactory::DeleteDatabase( | 221 void IndexedDBFactoryImpl::DeleteDatabase( |
| 220 const base::string16& name, | 222 const base::string16& name, |
| 221 net::URLRequestContext* request_context, | 223 net::URLRequestContext* request_context, |
| 222 scoped_refptr<IndexedDBCallbacks> callbacks, | 224 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 223 const GURL& origin_url, | 225 const GURL& origin_url, |
| 224 const base::FilePath& data_directory) { | 226 const base::FilePath& data_directory) { |
| 225 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 227 IDB_TRACE("IndexedDBFactoryImpl::DeleteDatabase"); |
| 226 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 228 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| 227 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 229 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
| 228 if (it != database_map_.end()) { | 230 if (it != database_map_.end()) { |
| 229 // If there are any connections to the database, directly delete the | 231 // If there are any connections to the database, directly delete the |
| 230 // database. | 232 // database. |
| 231 it->second->DeleteDatabase(callbacks); | 233 it->second->DeleteDatabase(callbacks); |
| 232 return; | 234 return; |
| 233 } | 235 } |
| 234 | 236 |
| 235 // TODO(dgrogan): Plumb data_loss back to script eventually? | 237 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 277 |
| 276 database_map_[unique_identifier] = database; | 278 database_map_[unique_identifier] = database; |
| 277 origin_dbs_.insert(std::make_pair(origin_url, database)); | 279 origin_dbs_.insert(std::make_pair(origin_url, database)); |
| 278 database->DeleteDatabase(callbacks); | 280 database->DeleteDatabase(callbacks); |
| 279 RemoveDatabaseFromMaps(unique_identifier); | 281 RemoveDatabaseFromMaps(unique_identifier); |
| 280 database = NULL; | 282 database = NULL; |
| 281 backing_store = NULL; | 283 backing_store = NULL; |
| 282 ReleaseBackingStore(origin_url, false /* immediate */); | 284 ReleaseBackingStore(origin_url, false /* immediate */); |
| 283 } | 285 } |
| 284 | 286 |
| 285 void IndexedDBFactory::DatabaseDeleted( | 287 void IndexedDBFactoryImpl::DatabaseDeleted( |
| 286 const IndexedDBDatabase::Identifier& identifier) { | 288 const IndexedDBDatabase::Identifier& identifier) { |
| 287 // NULL after ContextDestroyed() called, and in some unit tests. | 289 // NULL after ContextDestroyed() called, and in some unit tests. |
| 288 if (!context_) | 290 if (!context_) |
| 289 return; | 291 return; |
| 290 context_->DatabaseDeleted(identifier.first); | 292 context_->DatabaseDeleted(identifier.first); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { | 295 void IndexedDBFactoryImpl::HandleBackingStoreFailure(const GURL& origin_url) { |
| 294 // NULL after ContextDestroyed() called, and in some unit tests. | 296 // NULL after ContextDestroyed() called, and in some unit tests. |
| 295 if (!context_) | 297 if (!context_) |
| 296 return; | 298 return; |
| 297 context_->ForceClose(origin_url, | 299 context_->ForceClose(origin_url, |
| 298 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); | 300 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void IndexedDBFactory::HandleBackingStoreCorruption( | 303 void IndexedDBFactoryImpl::HandleBackingStoreCorruption( |
| 302 const GURL& origin_url, | 304 const GURL& origin_url, |
| 303 const IndexedDBDatabaseError& error) { | 305 const IndexedDBDatabaseError& error) { |
| 304 // Make a copy of origin_url as this is likely a reference to a member of a | 306 // Make a copy of origin_url as this is likely a reference to a member of a |
| 305 // backing store which this function will be deleting. | 307 // backing store which this function will be deleting. |
| 306 GURL saved_origin_url(origin_url); | 308 GURL saved_origin_url(origin_url); |
| 307 DCHECK(context_); | 309 DCHECK(context_); |
| 308 base::FilePath path_base = context_->data_path(); | 310 base::FilePath path_base = context_->data_path(); |
| 309 IndexedDBBackingStore::RecordCorruptionInfo( | 311 IndexedDBBackingStore::RecordCorruptionInfo( |
| 310 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); | 312 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); |
| 311 HandleBackingStoreFailure(saved_origin_url); | 313 HandleBackingStoreFailure(saved_origin_url); |
| 312 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, | 314 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, |
| 313 // so our corruption info file will remain. | 315 // so our corruption info file will remain. |
| 314 leveldb::Status s = | 316 leveldb::Status s = |
| 315 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); | 317 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); |
| 316 if (!s.ok()) | 318 if (!s.ok()) |
| 317 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); | 319 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); |
| 318 } | 320 } |
| 319 | 321 |
| 320 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 322 bool IndexedDBFactoryImpl::IsDatabaseOpen(const GURL& origin_url, |
| 321 const base::string16& name) const { | 323 const base::string16& name) const { |
| 322 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 324 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
| 323 } | 325 } |
| 324 | 326 |
| 325 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 327 bool IndexedDBFactoryImpl::IsBackingStoreOpen(const GURL& origin_url) const { |
| 326 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 328 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
| 327 } | 329 } |
| 328 | 330 |
| 329 bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url) | 331 bool IndexedDBFactoryImpl::IsBackingStorePendingClose( |
| 330 const { | 332 const GURL& origin_url) const { |
| 331 IndexedDBBackingStoreMap::const_iterator it = | 333 IndexedDBBackingStoreMap::const_iterator it = |
| 332 backing_store_map_.find(origin_url); | 334 backing_store_map_.find(origin_url); |
| 333 if (it == backing_store_map_.end()) | 335 if (it == backing_store_map_.end()) |
| 334 return false; | 336 return false; |
| 335 return it->second->close_timer()->IsRunning(); | 337 return it->second->close_timer()->IsRunning(); |
| 336 } | 338 } |
| 337 | 339 |
| 338 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStoreHelper( | 340 scoped_refptr<IndexedDBBackingStore> |
| 341 IndexedDBFactoryImpl::OpenBackingStoreHelper( |
| 339 const GURL& origin_url, | 342 const GURL& origin_url, |
| 340 const base::FilePath& data_directory, | 343 const base::FilePath& data_directory, |
| 341 net::URLRequestContext* request_context, | 344 net::URLRequestContext* request_context, |
| 342 blink::WebIDBDataLoss* data_loss, | 345 blink::WebIDBDataLoss* data_loss, |
| 343 std::string* data_loss_message, | 346 std::string* data_loss_message, |
| 344 bool* disk_full, | 347 bool* disk_full, |
| 345 bool first_time, | 348 bool first_time, |
| 346 leveldb::Status* status) { | 349 leveldb::Status* status) { |
| 347 return IndexedDBBackingStore::Open(this, | 350 return IndexedDBBackingStore::Open(this, |
| 348 origin_url, | 351 origin_url, |
| 349 data_directory, | 352 data_directory, |
| 350 request_context, | 353 request_context, |
| 351 data_loss, | 354 data_loss, |
| 352 data_loss_message, | 355 data_loss_message, |
| 353 disk_full, | 356 disk_full, |
| 354 context_->TaskRunner(), | 357 context_->TaskRunner(), |
| 355 first_time, | 358 first_time, |
| 356 status); | 359 status); |
| 357 } | 360 } |
| 358 | 361 |
| 359 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 362 scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore( |
| 360 const GURL& origin_url, | 363 const GURL& origin_url, |
| 361 const base::FilePath& data_directory, | 364 const base::FilePath& data_directory, |
| 362 net::URLRequestContext* request_context, | 365 net::URLRequestContext* request_context, |
| 363 blink::WebIDBDataLoss* data_loss, | 366 blink::WebIDBDataLoss* data_loss, |
| 364 std::string* data_loss_message, | 367 std::string* data_loss_message, |
| 365 bool* disk_full, | 368 bool* disk_full, |
| 366 leveldb::Status* status) { | 369 leveldb::Status* status) { |
| 367 const bool open_in_memory = data_directory.empty(); | 370 const bool open_in_memory = data_directory.empty(); |
| 368 | 371 |
| 369 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); | 372 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // All backing stores associated with this factory should be of the same | 404 // All backing stores associated with this factory should be of the same |
| 402 // type. | 405 // type. |
| 403 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); | 406 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); |
| 404 | 407 |
| 405 return backing_store; | 408 return backing_store; |
| 406 } | 409 } |
| 407 | 410 |
| 408 return 0; | 411 return 0; |
| 409 } | 412 } |
| 410 | 413 |
| 411 void IndexedDBFactory::Open(const base::string16& name, | 414 void IndexedDBFactoryImpl::Open(const base::string16& name, |
| 412 const IndexedDBPendingConnection& connection, | 415 const IndexedDBPendingConnection& connection, |
| 413 net::URLRequestContext* request_context, | 416 net::URLRequestContext* request_context, |
| 414 const GURL& origin_url, | 417 const GURL& origin_url, |
| 415 const base::FilePath& data_directory) { | 418 const base::FilePath& data_directory) { |
| 416 IDB_TRACE("IndexedDBFactory::Open"); | 419 IDB_TRACE("IndexedDBFactoryImpl::Open"); |
| 417 scoped_refptr<IndexedDBDatabase> database; | 420 scoped_refptr<IndexedDBDatabase> database; |
| 418 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 421 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
| 419 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 422 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
| 420 blink::WebIDBDataLoss data_loss = | 423 blink::WebIDBDataLoss data_loss = |
| 421 blink::WebIDBDataLossNone; | 424 blink::WebIDBDataLossNone; |
| 422 std::string data_loss_message; | 425 std::string data_loss_message; |
| 423 bool disk_full = false; | 426 bool disk_full = false; |
| 424 bool was_open = (it != database_map_.end()); | 427 bool was_open = (it != database_map_.end()); |
| 425 if (!was_open) { | 428 if (!was_open) { |
| 426 leveldb::Status s; | 429 leveldb::Status s; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 connection.callbacks->OnDataLoss(data_loss, data_loss_message); | 479 connection.callbacks->OnDataLoss(data_loss, data_loss_message); |
| 477 | 480 |
| 478 database->OpenConnection(connection); | 481 database->OpenConnection(connection); |
| 479 | 482 |
| 480 if (!was_open && database->ConnectionCount() > 0) { | 483 if (!was_open && database->ConnectionCount() > 0) { |
| 481 database_map_[unique_identifier] = database; | 484 database_map_[unique_identifier] = database; |
| 482 origin_dbs_.insert(std::make_pair(origin_url, database)); | 485 origin_dbs_.insert(std::make_pair(origin_url, database)); |
| 483 } | 486 } |
| 484 } | 487 } |
| 485 | 488 |
| 486 std::pair<IndexedDBFactory::OriginDBMapIterator, | 489 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator, |
| 487 IndexedDBFactory::OriginDBMapIterator> | 490 IndexedDBFactoryImpl::OriginDBMapIterator> |
| 488 IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const { | 491 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const GURL& origin_url) const { |
| 489 return origin_dbs_.equal_range(origin_url); | 492 return origin_dbs_.equal_range(origin_url); |
| 490 } | 493 } |
| 491 | 494 |
| 492 size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const { | 495 size_t IndexedDBFactoryImpl::GetConnectionCount(const GURL& origin_url) const { |
| 493 size_t count(0); | 496 size_t count(0); |
| 494 | 497 |
| 495 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 498 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
| 496 GetOpenDatabasesForOrigin(origin_url); | 499 GetOpenDatabasesForOrigin(origin_url); |
| 497 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 500 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
| 498 count += it->second->ConnectionCount(); | 501 count += it->second->ConnectionCount(); |
| 499 | 502 |
| 500 return count; | 503 return count; |
| 501 } | 504 } |
| 502 | 505 |
| 503 } // namespace content | 506 } // namespace content |
| OLD | NEW |