Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: webkit/quota/quota_manager.cc

Issue 7002024: Implement QuotaTemporaryStorageEvictor. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added a TODO to call OnQuotaManagerDestroyed. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 temporary_global_quota_(-1) { 448 temporary_global_quota_(-1) {
448 } 449 }
449 450
450 QuotaManager::~QuotaManager() { 451 QuotaManager::~QuotaManager() {
451 DCHECK(io_thread_->BelongsToCurrentThread()); 452 DCHECK(io_thread_->BelongsToCurrentThread());
452 proxy_->manager_ = NULL; 453 proxy_->manager_ = NULL;
453 std::for_each(clients_.begin(), clients_.end(), 454 std::for_each(clients_.begin(), clients_.end(),
454 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); 455 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed));
455 if (database_.get()) 456 if (database_.get())
456 db_thread_->DeleteSoon(FROM_HERE, database_.release()); 457 db_thread_->DeleteSoon(FROM_HERE, database_.release());
458 // TODO(dmikurube): Evictor::OnQuotaManagerDestroyedOnIOThread() appropriately.
457 } 459 }
458 460
459 void QuotaManager::GetUsageAndQuota( 461 void QuotaManager::GetUsageAndQuota(
460 const GURL& origin, StorageType type, 462 const GURL& origin, StorageType type,
461 GetUsageAndQuotaCallback* callback_ptr) { 463 GetUsageAndQuotaCallback* callback_ptr) {
462 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); 464 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr);
463 LazyInitialize(); 465 LazyInitialize();
464 if (is_incognito_) { 466 if (is_incognito_) {
465 int64 quota = 0; 467 int64 quota = 0;
466 if (type == kStorageTypeTemporary) 468 if (type == kStorageTypeTemporary)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 575
574 if (is_incognito_) 576 if (is_incognito_)
575 return; 577 return;
576 578
577 database_.reset(new QuotaDatabase(profile_path_.AppendASCII(kDatabaseName))); 579 database_.reset(new QuotaDatabase(profile_path_.AppendASCII(kDatabaseName)));
578 580
579 temporary_usage_tracker_.reset( 581 temporary_usage_tracker_.reset(
580 new UsageTracker(clients_, kStorageTypeTemporary)); 582 new UsageTracker(clients_, kStorageTypeTemporary));
581 persistent_usage_tracker_.reset( 583 persistent_usage_tracker_.reset(
582 new UsageTracker(clients_, kStorageTypePersistent)); 584 new UsageTracker(clients_, kStorageTypePersistent));
585 // TODO(dmikurube): Change this hard-coded 3 seconds.
586 // TODO(dmikurube): This init. could be delayed until InitializeTask finishes.
587 temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor(
588 this, database_.get(), 3000, io_thread_, db_thread_);
583 589
584 scoped_refptr<InitializeTask> task( 590 scoped_refptr<InitializeTask> task(
585 new InitializeTask(this, database_.get(), db_thread_, profile_path_)); 591 new InitializeTask(this, database_.get(), db_thread_, profile_path_));
586 task->Start(); 592 task->Start();
593
594 temporary_storage_evictor_->Start();
587 } 595 }
588 596
589 void QuotaManager::RegisterClient(QuotaClient* client) { 597 void QuotaManager::RegisterClient(QuotaClient* client) {
590 DCHECK(io_thread_->BelongsToCurrentThread()); 598 DCHECK(io_thread_->BelongsToCurrentThread());
591 DCHECK(!database_.get()); 599 DCHECK(!database_.get());
592 clients_.push_back(client); 600 clients_.push_back(client);
593 } 601 }
594 602
595 void QuotaManager::NotifyStorageModified( 603 void QuotaManager::NotifyStorageModified(
596 QuotaClient::ID client_id, 604 QuotaClient::ID client_id,
597 const GURL& origin, StorageType type, int64 delta) { 605 const GURL& origin, StorageType type, int64 delta) {
598 LazyInitialize(); 606 LazyInitialize();
599 UsageTracker* tracker = GetUsageTracker(type); 607 UsageTracker* tracker = GetUsageTracker(type);
600 DCHECK(tracker); 608 DCHECK(tracker);
601 tracker->UpdateUsageCache(client_id, origin, delta); 609 tracker->UpdateUsageCache(client_id, origin, delta);
602 } 610 }
603 611
612 void QuotaManager::DeleteOriginDataOnIOThread(
613 const GURL& origin,
614 StorageType type,
615 DeleteOriginDataCallback* callback) {
616 LazyInitialize();
617 LOG(ERROR) << "QM::DeleteOriginDataOnIOThread";
618 // TODO(dmikurube): Delete data of the |origin|.
619 /*
620 ++num_deleted_clients_;
621 DCHECK(num_deleted_clients_ <= num_clients_);
622 if (num_deleted_clients_ == num_clients_) {
623 if (is_deletion_failed_) {
624 // TODO(dmikurube): Should try ignoring the failed origin?
625 }
626
627 if (false ) { // More deletion required?
628 // Delete another origin.
629 db_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
630 this, &QuotaTemporaryStorageEvictor::Evict));
631 } else {
632 // Post the next task.
633 db_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
634 this, &QuotaTemporaryStorageEvictor::Evict), delay_ms_);
635 }
636 num_clients_ = 0;
637 num_deleted_clients_ = 0;
638 is_deletion_failed_ = false;
639 }
640 */
641 callback->Run(kQuotaStatusOk);
642 delete callback;
643 }
644
604 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const { 645 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const {
605 switch (type) { 646 switch (type) {
606 case kStorageTypeTemporary: 647 case kStorageTypeTemporary:
607 return temporary_usage_tracker_.get(); 648 return temporary_usage_tracker_.get();
608 case kStorageTypePersistent: 649 case kStorageTypePersistent:
609 return persistent_usage_tracker_.get(); 650 return persistent_usage_tracker_.get();
610 default: 651 default:
611 NOTREACHED(); 652 NOTREACHED();
612 } 653 }
613 return NULL; 654 return NULL;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 834
794 QuotaManagerProxy::QuotaManagerProxy( 835 QuotaManagerProxy::QuotaManagerProxy(
795 QuotaManager* manager, base::MessageLoopProxy* io_thread) 836 QuotaManager* manager, base::MessageLoopProxy* io_thread)
796 : manager_(manager), io_thread_(io_thread) { 837 : manager_(manager), io_thread_(io_thread) {
797 } 838 }
798 839
799 QuotaManagerProxy::~QuotaManagerProxy() { 840 QuotaManagerProxy::~QuotaManagerProxy() {
800 } 841 }
801 842
802 } // namespace quota 843 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698