| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (!s.ok()) { | 306 if (!s.ok()) { |
| 307 LOG(WARNING) << "Failed to delete LevelDB database: " | 307 LOG(WARNING) << "Failed to delete LevelDB database: " |
| 308 << idb_directory.AsUTF8Unsafe(); | 308 << idb_directory.AsUTF8Unsafe(); |
| 309 } else { | 309 } else { |
| 310 // LevelDB does not delete empty directories; work around this. | 310 // LevelDB does not delete empty directories; work around this. |
| 311 // TODO(jsbell): Remove when upstream bug is fixed. | 311 // TODO(jsbell): Remove when upstream bug is fixed. |
| 312 // https://code.google.com/p/leveldb/issues/detail?id=209 | 312 // https://code.google.com/p/leveldb/issues/detail?id=209 |
| 313 const bool kNonRecursive = false; | 313 const bool kNonRecursive = false; |
| 314 base::DeleteFile(idb_directory, kNonRecursive); | 314 base::DeleteFile(idb_directory, kNonRecursive); |
| 315 } | 315 } |
| 316 base::DeleteFile(GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), | 316 |
| 317 true /* recursive */); | |
| 318 QueryDiskAndUpdateQuotaUsage(origin_url); | 317 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 319 if (s.ok()) { | 318 if (s.ok()) { |
| 320 RemoveFromOriginSet(origin_url); | 319 RemoveFromOriginSet(origin_url); |
| 321 origin_size_map_.erase(origin_url); | 320 origin_size_map_.erase(origin_url); |
| 322 space_available_map_.erase(origin_url); | 321 space_available_map_.erase(origin_url); |
| 323 } | 322 } |
| 324 } | 323 } |
| 325 | 324 |
| 325 void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url, |
| 326 IndexedDBContext* dest_context) { |
| 327 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 328 |
| 329 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 330 return; |
| 331 |
| 332 IndexedDBContextImpl* dest_context_impl = |
| 333 static_cast<IndexedDBContextImpl*>(dest_context); |
| 334 |
| 335 ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN); |
| 336 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); |
| 337 |
| 338 // Make sure we're not about to delete our own database. |
| 339 CHECK_NE(dest_context_impl->data_path().value(), data_path().value()); |
| 340 |
| 341 // Delete any existing storage paths in the destination context. |
| 342 // A previously failed migration may have left behind partially copied |
| 343 // directories. |
| 344 for (const base::FilePath& dest_path : |
| 345 dest_context_impl->GetStoragePaths(origin_url)) |
| 346 base::DeleteFile(dest_path, true); |
| 347 |
| 348 base::FilePath dest_data_path = dest_context_impl->data_path(); |
| 349 base::CreateDirectory(dest_data_path); |
| 350 |
| 351 for (const base::FilePath& src_data_path : GetStoragePaths(origin_url)) { |
| 352 if (base::PathExists(src_data_path)) { |
| 353 base::CopyDirectory(src_data_path, dest_data_path, true); |
| 354 } |
| 355 } |
| 356 } |
| 357 |
| 326 void IndexedDBContextImpl::ForceClose(const GURL origin_url, | 358 void IndexedDBContextImpl::ForceClose(const GURL origin_url, |
| 327 ForceCloseReason reason) { | 359 ForceCloseReason reason) { |
| 328 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 360 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 329 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", | 361 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", |
| 330 reason, | 362 reason, |
| 331 FORCE_CLOSE_REASON_MAX); | 363 FORCE_CLOSE_REASON_MAX); |
| 332 | 364 |
| 333 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 365 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 334 return; | 366 return; |
| 335 | 367 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 origin_set_.reset(); | 604 origin_set_.reset(); |
| 573 origin_size_map_.clear(); | 605 origin_size_map_.clear(); |
| 574 space_available_map_.clear(); | 606 space_available_map_.clear(); |
| 575 } | 607 } |
| 576 | 608 |
| 577 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 609 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 578 return task_runner_.get(); | 610 return task_runner_.get(); |
| 579 } | 611 } |
| 580 | 612 |
| 581 } // namespace content | 613 } // namespace content |
| OLD | NEW |