Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/quota/quota_manager.h" | 5 #include "webkit/quota/quota_manager.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "webkit/quota/quota_database.h" | 17 #include "webkit/quota/quota_database.h" |
| 18 #include "webkit/quota/quota_temporary_storage_evictor.h" | |
| 18 #include "webkit/quota/quota_types.h" | 19 #include "webkit/quota/quota_types.h" |
| 19 #include "webkit/quota/usage_tracker.h" | 20 #include "webkit/quota/usage_tracker.h" |
| 20 | 21 |
| 21 using base::ScopedCallbackFactory; | 22 using base::ScopedCallbackFactory; |
| 22 | 23 |
| 23 namespace quota { | 24 namespace quota { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 // Returns the initial size of the temporary storage quota. | 27 // Returns the initial size of the temporary storage quota. |
| 27 // (This just gives a default initial size; once its initial size is determined | 28 // (This just gives a default initial size; once its initial size is determined |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 base::MessageLoopProxy* io_thread, | 488 base::MessageLoopProxy* io_thread, |
| 488 base::MessageLoopProxy* db_thread) | 489 base::MessageLoopProxy* db_thread) |
| 489 : is_incognito_(is_incognito), | 490 : is_incognito_(is_incognito), |
| 490 profile_path_(profile_path), | 491 profile_path_(profile_path), |
| 491 proxy_(new QuotaManagerProxy( | 492 proxy_(new QuotaManagerProxy( |
| 492 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), | 493 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), |
| 493 db_initialized_(false), | 494 db_initialized_(false), |
| 494 db_disabled_(false), | 495 db_disabled_(false), |
| 495 io_thread_(io_thread), | 496 io_thread_(io_thread), |
| 496 db_thread_(db_thread), | 497 db_thread_(db_thread), |
| 498 temporary_storage_evictor_(NULL), | |
| 499 num_deletion_requested_clients_(0), | |
| 500 num_deleted_clients_(0), | |
| 497 temporary_global_quota_(-1) { | 501 temporary_global_quota_(-1) { |
| 498 } | 502 } |
| 499 | 503 |
| 500 QuotaManager::~QuotaManager() { | 504 QuotaManager::~QuotaManager() { |
| 501 DCHECK(io_thread_->BelongsToCurrentThread()); | 505 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 502 proxy_->manager_ = NULL; | 506 proxy_->manager_ = NULL; |
| 507 if (temporary_storage_evictor_ != NULL) | |
| 508 temporary_storage_evictor_->OnQuotaManagerDestroyedOnIOThread(); | |
| 503 std::for_each(clients_.begin(), clients_.end(), | 509 std::for_each(clients_.begin(), clients_.end(), |
| 504 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 510 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
| 505 if (database_.get()) | 511 if (database_.get()) |
| 506 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 512 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
| 507 } | 513 } |
| 508 | 514 |
| 509 void QuotaManager::GetUsageAndQuota( | 515 void QuotaManager::GetUsageAndQuota( |
| 510 const GURL& origin, StorageType type, | 516 const GURL& origin, StorageType type, |
| 511 GetUsageAndQuotaCallback* callback_ptr) { | 517 GetUsageAndQuotaCallback* callback_ptr) { |
| 512 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); | 518 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 scoped_refptr<PersistentHostQuotaUpdateTask> task( | 612 scoped_refptr<PersistentHostQuotaUpdateTask> task( |
| 607 new PersistentHostQuotaUpdateTask( | 613 new PersistentHostQuotaUpdateTask( |
| 608 this, database_.get(), db_thread_, host, new_quota, callback)); | 614 this, database_.get(), db_thread_, host, new_quota, callback)); |
| 609 task->Start(); | 615 task->Start(); |
| 610 } else { | 616 } else { |
| 611 callback->Run(kQuotaErrorInvalidAccess, host, -1); | 617 callback->Run(kQuotaErrorInvalidAccess, host, -1); |
| 612 delete callback; | 618 delete callback; |
| 613 } | 619 } |
| 614 } | 620 } |
| 615 | 621 |
| 622 void QuotaManager::RegisterTemporaryStorageEvictor( | |
| 623 scoped_refptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor) { | |
| 624 /* | |
| 625 // TODO(dmikurube): Change this hard-coded 3 seconds. | |
| 626 temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor( | |
| 627 this, database_.get(), 10000000, 3000, io_thread_, db_thread_); | |
| 628 */ | |
| 629 | |
| 630 temporary_storage_evictor_ = temporary_storage_evictor; | |
| 631 temporary_storage_evictor_->RegisterQuotaManagerOnIOThread(this); | |
| 632 } | |
| 633 | |
| 616 void QuotaManager::LazyInitialize() { | 634 void QuotaManager::LazyInitialize() { |
| 617 DCHECK(io_thread_->BelongsToCurrentThread()); | 635 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 618 if (database_.get()) { | 636 if (database_.get()) { |
| 619 // Initialization seems to be done already. | 637 // Initialization seems to be done already. |
| 620 return; | 638 return; |
| 621 } | 639 } |
| 622 | 640 |
| 623 if (is_incognito_) | 641 if (is_incognito_) |
| 624 return; | 642 return; |
| 625 | 643 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 StorageType type, | 691 StorageType type, |
| 674 GetLRUOriginCallback* callback) { | 692 GetLRUOriginCallback* callback) { |
| 675 LazyInitialize(); | 693 LazyInitialize(); |
| 676 if (!db_disabled_) { | 694 if (!db_disabled_) { |
| 677 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 695 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
| 678 this, database_.get(), db_thread_, type, origins_in_use_, callback)); | 696 this, database_.get(), db_thread_, type, origins_in_use_, callback)); |
| 679 task->Start(); | 697 task->Start(); |
| 680 } | 698 } |
| 681 } | 699 } |
| 682 | 700 |
| 701 void QuotaManager::StartEviction() { | |
| 702 LazyInitialize(); | |
| 703 if (temporary_storage_evictor_ != NULL) | |
| 704 temporary_storage_evictor_->Start(); | |
| 705 } | |
| 706 | |
| 707 void QuotaManager::GetUsageAndQuotaForEviction( | |
| 708 DeleteOriginDataCallback* callback) { | |
| 709 const int64 USAGE = 30000; | |
| 710 const int64 QUOTA = 100000; | |
| 711 const int64 PHYSICAL_AVAILABLE = 1000000000; | |
| 712 | |
| 713 LOG(ERROR) << "QM::GetUsageAndQuotaForEviction"; | |
| 714 DCHECK(io_thread_->BelongsToCurrentThread()); | |
| 715 // TODO(dmikurube): Get usage, quota and physical space and then callback. | |
| 716 callback->Run(kQuotaStatusOk, USAGE, QUOTA, PHYSICAL_AVAILABLE); | |
| 717 delete callback; | |
| 718 } | |
| 719 | |
| 720 void QuotaManager::OnOriginDataDeleted( | |
| 721 QuotaStatusCode status, | |
| 722 DeleteOriginDataCallback* callback) { | |
| 723 LOG(ERROR) << "QM::OnOriginDataDeleted"; | |
| 724 DCHECK(io_thread_->BelongsToCurrentThread()); | |
| 725 | |
| 726 if (status != kQuotaStatusOk) { | |
| 727 // TODO(dmikurube): Handle error. | |
| 728 } | |
| 729 | |
| 730 ++num_deleted_clients_; | |
| 731 DCHECK(num_deleted_clients_ <= num_deletion_requested_clients_); | |
| 732 if (num_deleted_clients_ == num_deletion_requested_clients_) { | |
| 733 num_deletion_requested_clients_ = 0; | |
| 734 num_deleted_clients_ = 0; | |
|
michaeln
2011/05/17 00:19:45
you might be able to do this with one data member
Dai Mikurube (NOT FULLTIME)
2011/05/17 09:18:40
We can do that, but I think these two variables he
| |
| 735 | |
| 736 // TODO(dmikurube): Get usage, quota and physical space and then callback. | |
| 737 GetUsageAndQuotaForEviction(callback); | |
| 738 } | |
| 739 } | |
| 740 | |
| 741 void QuotaManager::DeleteOriginData( | |
| 742 const GURL& origin, | |
| 743 StorageType type, | |
| 744 DeleteOriginDataCallback* callback) { | |
| 745 LOG(ERROR) << "QM::DeleteOriginData"; | |
| 746 DCHECK(io_thread_->BelongsToCurrentThread()); | |
| 747 LazyInitialize(); | |
| 748 | |
| 749 int num_clients = clients_.size(); | |
| 750 | |
| 751 if (origin.is_empty() || num_clients == 0 || num_deleted_clients_ > 0) { | |
| 752 GetUsageAndQuotaForEviction(callback); | |
|
michaeln
2011/05/17 00:19:45
Seems strange to call this method for the last con
Dai Mikurube (NOT FULLTIME)
2011/05/17 09:18:40
I'm separating and re-constructing the change. Le
| |
| 753 return; | |
| 754 } | |
| 755 | |
| 756 num_deletion_requested_clients_ = num_clients; | |
| 757 num_deleted_clients_ = 0; | |
| 758 | |
| 759 for (QuotaClientList::iterator p = clients_.begin(); | |
| 760 p != clients_.end(); | |
| 761 ++p) { | |
| 762 /* | |
| 763 p->DeleteOriginData(origin, kStorageTypeTemporary, NewRunnableMethod( | |
| 764 this, &QuotaManager::OnOriginDataDeleted)); | |
| 765 */ | |
| 766 OnOriginDataDeleted(kQuotaStatusOk, callback); // test. | |
| 767 } | |
| 768 } | |
| 769 | |
| 683 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const { | 770 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const { |
| 684 switch (type) { | 771 switch (type) { |
| 685 case kStorageTypeTemporary: | 772 case kStorageTypeTemporary: |
| 686 return temporary_usage_tracker_.get(); | 773 return temporary_usage_tracker_.get(); |
| 687 case kStorageTypePersistent: | 774 case kStorageTypePersistent: |
| 688 return persistent_usage_tracker_.get(); | 775 return persistent_usage_tracker_.get(); |
| 689 default: | 776 default: |
| 690 NOTREACHED(); | 777 NOTREACHED(); |
| 691 } | 778 } |
| 692 return NULL; | 779 return NULL; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 | 879 |
| 793 QuotaManagerProxy::QuotaManagerProxy( | 880 QuotaManagerProxy::QuotaManagerProxy( |
| 794 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 881 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
| 795 : manager_(manager), io_thread_(io_thread) { | 882 : manager_(manager), io_thread_(io_thread) { |
| 796 } | 883 } |
| 797 | 884 |
| 798 QuotaManagerProxy::~QuotaManagerProxy() { | 885 QuotaManagerProxy::~QuotaManagerProxy() { |
| 799 } | 886 } |
| 800 | 887 |
| 801 } // namespace quota | 888 } // namespace quota |
| OLD | NEW |