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" | |
13 #include "content/browser/indexed_db/indexed_db_tracing.h" | 12 #include "content/browser/indexed_db/indexed_db_tracing.h" |
14 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 13 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
15 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 14 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
16 #include "webkit/common/database/database_identifier.h" | 15 #include "webkit/common/database/database_identifier.h" |
17 | 16 |
18 using base::ASCIIToUTF16; | 17 using base::ASCIIToUTF16; |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 | 20 |
22 const int64 kBackingStoreGracePeriodMs = 2000; | 21 const int64 kBackingStoreGracePeriodMs = 2000; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 227 } |
229 | 228 |
230 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { | 229 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { |
231 // NULL after ContextDestroyed() called, and in some unit tests. | 230 // NULL after ContextDestroyed() called, and in some unit tests. |
232 if (!context_) | 231 if (!context_) |
233 return; | 232 return; |
234 context_->ForceClose(origin_url, | 233 context_->ForceClose(origin_url, |
235 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); | 234 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); |
236 } | 235 } |
237 | 236 |
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 | |
256 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 237 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, |
257 const base::string16& name) const { | 238 const base::string16& name) const { |
258 | 239 |
259 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 240 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
260 } | 241 } |
261 | 242 |
262 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 243 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { |
263 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 244 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
264 } | 245 } |
265 | 246 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 365 |
385 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 366 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
386 GetOpenDatabasesForOrigin(origin_url); | 367 GetOpenDatabasesForOrigin(origin_url); |
387 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 368 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
388 count += it->second->ConnectionCount(); | 369 count += it->second->ConnectionCount(); |
389 | 370 |
390 return count; | 371 return count; |
391 } | 372 } |
392 | 373 |
393 } // namespace content | 374 } // namespace content |
OLD | NEW |