| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 308 } |
| 309 | 309 |
| 310 QueryDiskAndUpdateQuotaUsage(origin_url); | 310 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 311 if (s.ok()) { | 311 if (s.ok()) { |
| 312 RemoveFromOriginSet(origin_url); | 312 RemoveFromOriginSet(origin_url); |
| 313 origin_size_map_.erase(origin_url); | 313 origin_size_map_.erase(origin_url); |
| 314 space_available_map_.erase(origin_url); | 314 space_available_map_.erase(origin_url); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url, |
| 319 IndexedDBContext* dest_context) { |
| 320 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 321 ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN); |
| 322 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 323 return; |
| 324 |
| 325 base::FilePath idb_directory = GetFilePath(origin_url); |
| 326 base::FilePath dest_directory = dest_context->GetFilePath(origin_url); |
| 327 |
| 328 if (base::PathExists(dest_directory)) { |
| 329 return; |
| 330 } |
| 331 |
| 332 if (!base::PathExists(dest_directory.DirName())) { |
| 333 base::CreateDirectory(dest_directory.DirName()); |
| 334 } |
| 335 |
| 336 base::CopyDirectory(idb_directory, dest_directory.DirName(), true); |
| 337 } |
| 338 |
| 318 void IndexedDBContextImpl::ForceClose(const GURL origin_url, | 339 void IndexedDBContextImpl::ForceClose(const GURL origin_url, |
| 319 ForceCloseReason reason) { | 340 ForceCloseReason reason) { |
| 320 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 341 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 321 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", | 342 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", |
| 322 reason, | 343 reason, |
| 323 FORCE_CLOSE_REASON_MAX); | 344 FORCE_CLOSE_REASON_MAX); |
| 324 | 345 |
| 325 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 346 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
| 326 return; | 347 return; |
| 327 | 348 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 return 0; | 360 return 0; |
| 340 | 361 |
| 341 return factory_->GetConnectionCount(origin_url); | 362 return factory_->GetConnectionCount(origin_url); |
| 342 } | 363 } |
| 343 | 364 |
| 344 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) const { | 365 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) const { |
| 345 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); | 366 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); |
| 346 return GetIndexedDBFilePath(origin_id); | 367 return GetIndexedDBFilePath(origin_id); |
| 347 } | 368 } |
| 348 | 369 |
| 349 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | |
| 350 const std::string& origin_id) const { | |
| 351 return GetIndexedDBFilePath(origin_id); | |
| 352 } | |
| 353 | |
| 354 void IndexedDBContextImpl::SetTaskRunnerForTesting( | 370 void IndexedDBContextImpl::SetTaskRunnerForTesting( |
| 355 base::SequencedTaskRunner* task_runner) { | 371 base::SequencedTaskRunner* task_runner) { |
| 356 DCHECK(!task_runner_.get()); | 372 DCHECK(!task_runner_.get()); |
| 357 task_runner_ = task_runner; | 373 task_runner_ = task_runner; |
| 358 } | 374 } |
| 359 | 375 |
| 360 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 376 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
| 361 IndexedDBConnection* connection) { | 377 IndexedDBConnection* connection) { |
| 362 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 378 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
| 363 if (quota_manager_proxy()) { | 379 if (quota_manager_proxy()) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 origin_set_.reset(); | 561 origin_set_.reset(); |
| 546 origin_size_map_.clear(); | 562 origin_size_map_.clear(); |
| 547 space_available_map_.clear(); | 563 space_available_map_.clear(); |
| 548 } | 564 } |
| 549 | 565 |
| 550 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 566 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
| 551 return task_runner_.get(); | 567 return task_runner_.get(); |
| 552 } | 568 } |
| 553 | 569 |
| 554 } // namespace content | 570 } // namespace content |
| OLD | NEW |