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" |
11 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 11 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 12 #include "content/browser/indexed_db/indexed_db_database_error.h" |
12 #include "content/browser/indexed_db/indexed_db_tracing.h" | 13 #include "content/browser/indexed_db/indexed_db_tracing.h" |
13 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 14 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
14 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 15 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
15 #include "webkit/common/database/database_identifier.h" | 16 #include "webkit/common/database/database_identifier.h" |
16 | 17 |
17 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 const int64 kBackingStoreGracePeriodMs = 2000; | 22 const int64 kBackingStoreGracePeriodMs = 2000; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 228 } |
228 | 229 |
229 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { | 230 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { |
230 // NULL after ContextDestroyed() called, and in some unit tests. | 231 // NULL after ContextDestroyed() called, and in some unit tests. |
231 if (!context_) | 232 if (!context_) |
232 return; | 233 return; |
233 context_->ForceClose(origin_url, | 234 context_->ForceClose(origin_url, |
234 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); | 235 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); |
235 } | 236 } |
236 | 237 |
| 238 void IndexedDBFactory::HandleBackingStoreCorruption( |
| 239 const GURL& origin_url, |
| 240 const IndexedDBDatabaseError& error) { |
| 241 // Make a copy of origin_url as this is likely a reference to a member of a |
| 242 // backing store which this function will be deleting. |
| 243 GURL saved_origin_url(origin_url); |
| 244 DCHECK(context_); |
| 245 base::FilePath path_base = context_->data_path(); |
| 246 IndexedDBBackingStore::RecordCorruptionInfo( |
| 247 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); |
| 248 HandleBackingStoreFailure(saved_origin_url); |
| 249 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, |
| 250 // so our corruption info file will remain. |
| 251 if (!IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url) |
| 252 .ok()) |
| 253 DLOG(ERROR) << "Unable to delete backing store"; |
| 254 } |
| 255 |
237 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 256 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, |
238 const base::string16& name) const { | 257 const base::string16& name) const { |
239 | 258 |
240 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 259 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
241 } | 260 } |
242 | 261 |
243 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 262 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { |
244 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 263 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
245 } | 264 } |
246 | 265 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 384 |
366 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 385 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
367 GetOpenDatabasesForOrigin(origin_url); | 386 GetOpenDatabasesForOrigin(origin_url); |
368 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 387 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
369 count += it->second->ConnectionCount(); | 388 count += it->second->ConnectionCount(); |
370 | 389 |
371 return count; | 390 return count; |
372 } | 391 } |
373 | 392 |
374 } // namespace content | 393 } // namespace content |
OLD | NEW |