| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_context_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 list->Append(info.release()); | 276 list->Append(info.release()); |
| 277 } | 277 } |
| 278 return list.release(); | 278 return list.release(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 int IndexedDBContextImpl::GetOriginBlobFileCount(const GURL& origin_url) { | 281 int IndexedDBContextImpl::GetOriginBlobFileCount(const GURL& origin_url) { |
| 282 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 282 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 283 int count = 0; | 283 int count = 0; |
| 284 base::FileEnumerator file_enumerator( | 284 base::FileEnumerator file_enumerator(GetBlobStorePath(origin_url), true, |
| 285 GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), true, | 285 base::FileEnumerator::FILES); |
| 286 base::FileEnumerator::FILES); | |
| 287 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 286 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 288 file_path = file_enumerator.Next()) { | 287 file_path = file_enumerator.Next()) { |
| 289 count++; | 288 count++; |
| 290 } | 289 } |
| 291 return count; | 290 return count; |
| 292 } | 291 } |
| 293 | 292 |
| 294 int64_t IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { | 293 int64_t IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { |
| 295 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 294 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 296 if (data_path_.empty() || !HasOrigin(origin_url)) | 295 if (data_path_.empty() || !HasOrigin(origin_url)) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 322 if (!s.ok()) { | 321 if (!s.ok()) { |
| 323 LOG(WARNING) << "Failed to delete LevelDB database: " | 322 LOG(WARNING) << "Failed to delete LevelDB database: " |
| 324 << idb_directory.AsUTF8Unsafe(); | 323 << idb_directory.AsUTF8Unsafe(); |
| 325 } else { | 324 } else { |
| 326 // LevelDB does not delete empty directories; work around this. | 325 // LevelDB does not delete empty directories; work around this. |
| 327 // TODO(jsbell): Remove when upstream bug is fixed. | 326 // TODO(jsbell): Remove when upstream bug is fixed. |
| 328 // https://code.google.com/p/leveldb/issues/detail?id=209 | 327 // https://code.google.com/p/leveldb/issues/detail?id=209 |
| 329 const bool kNonRecursive = false; | 328 const bool kNonRecursive = false; |
| 330 base::DeleteFile(idb_directory, kNonRecursive); | 329 base::DeleteFile(idb_directory, kNonRecursive); |
| 331 } | 330 } |
| 332 base::DeleteFile(GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), | 331 base::DeleteFile(GetBlobStorePath(origin_url), true /* recursive */); |
| 333 true /* recursive */); | |
| 334 QueryDiskAndUpdateQuotaUsage(origin_url); | 332 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 335 if (s.ok()) { | 333 if (s.ok()) { |
| 336 RemoveFromOriginSet(origin_url); | 334 RemoveFromOriginSet(origin_url); |
| 337 origin_size_map_.erase(origin_url); | 335 origin_size_map_.erase(origin_url); |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 | 338 |
| 341 void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url, | 339 void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url, |
| 342 IndexedDBContext* dest_context) { | 340 IndexedDBContext* dest_context) { |
| 343 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 341 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 344 | 342 |
| 345 if (data_path_.empty() || !HasOrigin(origin_url)) | 343 if (data_path_.empty() || !HasOrigin(origin_url)) |
| 346 return; | 344 return; |
| 347 | 345 |
| 348 IndexedDBContextImpl* dest_context_impl = | 346 IndexedDBContextImpl* dest_context_impl = |
| 349 static_cast<IndexedDBContextImpl*>(dest_context); | 347 static_cast<IndexedDBContextImpl*>(dest_context); |
| 350 | 348 |
| 351 ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN); | 349 ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN); |
| 352 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); | |
| 353 | 350 |
| 354 // Make sure we're not about to delete our own database. | 351 // Make sure we're not about to delete our own database. |
| 355 CHECK_NE(dest_context_impl->data_path().value(), data_path().value()); | 352 CHECK_NE(dest_context_impl->data_path().value(), data_path().value()); |
| 356 | 353 |
| 357 // Delete any existing storage paths in the destination context. | 354 // Delete any existing storage paths in the destination context. |
| 358 // A previously failed migration may have left behind partially copied | 355 // A previously failed migration may have left behind partially copied |
| 359 // directories. | 356 // directories. |
| 360 for (const base::FilePath& dest_path : | 357 for (const base::FilePath& dest_path : |
| 361 dest_context_impl->GetStoragePaths(origin_url)) | 358 dest_context_impl->GetStoragePaths(origin_url)) |
| 362 base::DeleteFile(dest_path, true); | 359 base::DeleteFile(dest_path, true); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 390 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 387 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 391 if (data_path_.empty() || !HasOrigin(origin_url)) | 388 if (data_path_.empty() || !HasOrigin(origin_url)) |
| 392 return 0; | 389 return 0; |
| 393 | 390 |
| 394 if (!factory_.get()) | 391 if (!factory_.get()) |
| 395 return 0; | 392 return 0; |
| 396 | 393 |
| 397 return factory_->GetConnectionCount(origin_url); | 394 return factory_->GetConnectionCount(origin_url); |
| 398 } | 395 } |
| 399 | 396 |
| 400 base::FilePath IndexedDBContextImpl::GetLevelDBPath( | |
| 401 const GURL& origin_url) const { | |
| 402 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); | |
| 403 return GetLevelDBPath(origin_id); | |
| 404 } | |
| 405 | |
| 406 std::vector<base::FilePath> IndexedDBContextImpl::GetStoragePaths( | 397 std::vector<base::FilePath> IndexedDBContextImpl::GetStoragePaths( |
| 407 const GURL& origin_url) const { | 398 const GURL& origin_url) const { |
| 408 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); | |
| 409 std::vector<base::FilePath> paths; | 399 std::vector<base::FilePath> paths; |
| 410 paths.push_back(GetLevelDBPath(origin_id)); | 400 paths.push_back(GetLevelDBPath(origin_url)); |
| 411 paths.push_back(GetBlobPath(origin_id)); | 401 paths.push_back(GetBlobStorePath(origin_url)); |
| 412 return paths; | 402 return paths; |
| 413 } | 403 } |
| 414 | 404 |
| 415 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 405 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
| 416 const std::string& origin_id) const { | 406 const GURL& origin_url) const { |
| 417 return GetLevelDBPath(origin_id); | 407 return GetLevelDBPath(origin_url); |
| 418 } | 408 } |
| 419 | 409 |
| 420 void IndexedDBContextImpl::SetTaskRunnerForTesting( | 410 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 421 base::SequencedTaskRunner* task_runner) { | 411 base::SequencedTaskRunner* task_runner) { |
| 422 DCHECK(!task_runner_.get()); | 412 DCHECK(!task_runner_.get()); |
| 423 task_runner_ = task_runner; | 413 task_runner_ = task_runner; |
| 424 } | 414 } |
| 425 | 415 |
| 426 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 416 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
| 427 IndexedDBConnection* connection) { | 417 IndexedDBConnection* connection) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // Clearing only session-only databases, and there are none. | 467 // Clearing only session-only databases, and there are none. |
| 478 if (!has_session_only_databases) | 468 if (!has_session_only_databases) |
| 479 return; | 469 return; |
| 480 | 470 |
| 481 TaskRunner()->PostTask( | 471 TaskRunner()->PostTask( |
| 482 FROM_HERE, | 472 FROM_HERE, |
| 483 base::Bind( | 473 base::Bind( |
| 484 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); | 474 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); |
| 485 } | 475 } |
| 486 | 476 |
| 487 base::FilePath IndexedDBContextImpl::GetBlobPath( | 477 // static |
| 488 const std::string& origin_id) const { | 478 base::FilePath IndexedDBContextImpl::GetBlobStoreFileName( |
| 489 DCHECK(!data_path_.empty()); | 479 const GURL& origin_url) { |
| 490 return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension) | 480 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); |
| 481 return base::FilePath() |
| 482 .AppendASCII(origin_id) |
| 483 .AddExtension(kIndexedDBExtension) |
| 491 .AddExtension(kBlobExtension); | 484 .AddExtension(kBlobExtension); |
| 492 } | 485 } |
| 493 | 486 |
| 494 base::FilePath IndexedDBContextImpl::GetLevelDBPath( | 487 // static |
| 495 const std::string& origin_id) const { | 488 base::FilePath IndexedDBContextImpl::GetLevelDBFileName( |
| 496 DCHECK(!data_path_.empty()); | 489 const GURL& origin_url) { |
| 497 return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension) | 490 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); |
| 491 return base::FilePath() |
| 492 .AppendASCII(origin_id) |
| 493 .AddExtension(kIndexedDBExtension) |
| 498 .AddExtension(kLevelDBExtension); | 494 .AddExtension(kLevelDBExtension); |
| 499 } | 495 } |
| 500 | 496 |
| 497 base::FilePath IndexedDBContextImpl::GetBlobStorePath( |
| 498 const GURL& origin_url) const { |
| 499 DCHECK(!data_path_.empty()); |
| 500 return data_path_.Append(GetBlobStoreFileName(origin_url)); |
| 501 } |
| 502 |
| 503 base::FilePath IndexedDBContextImpl::GetLevelDBPath( |
| 504 const GURL& origin_url) const { |
| 505 DCHECK(!data_path_.empty()); |
| 506 return data_path_.Append(GetLevelDBFileName(origin_url)); |
| 507 } |
| 508 |
| 501 int64_t IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { | 509 int64_t IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { |
| 502 if (data_path_.empty()) | 510 if (data_path_.empty()) |
| 503 return 0; | 511 return 0; |
| 504 int64_t total_size = 0; | 512 int64_t total_size = 0; |
| 505 for (const base::FilePath& path : GetStoragePaths(origin_url)) | 513 for (const base::FilePath& path : GetStoragePaths(origin_url)) |
| 506 total_size += base::ComputeDirectorySize(path); | 514 total_size += base::ComputeDirectorySize(path); |
| 507 return total_size; | 515 return total_size; |
| 508 } | 516 } |
| 509 | 517 |
| 510 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( | 518 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 538 void IndexedDBContextImpl::ResetCaches() { | 546 void IndexedDBContextImpl::ResetCaches() { |
| 539 origin_set_.reset(); | 547 origin_set_.reset(); |
| 540 origin_size_map_.clear(); | 548 origin_size_map_.clear(); |
| 541 } | 549 } |
| 542 | 550 |
| 543 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 551 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 544 return task_runner_.get(); | 552 return task_runner_.get(); |
| 545 } | 553 } |
| 546 | 554 |
| 547 } // namespace content | 555 } // namespace content |
| OLD | NEW |