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

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

Issue 7839029: QuotaManager::DeleteOriginData now allows deletion of specific QuotaClients (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kinuko's feedback (modulo kMockStart) Created 8 years, 10 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
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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 "webkit/quota/quota_manager.h" 5 #include "webkit/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 NOTREACHED(); 454 NOTREACHED();
455 } 455 }
456 return NULL; 456 return NULL;
457 } 457 }
458 458
459 class QuotaManager::OriginDataDeleter : public QuotaTask { 459 class QuotaManager::OriginDataDeleter : public QuotaTask {
460 public: 460 public:
461 OriginDataDeleter(QuotaManager* manager, 461 OriginDataDeleter(QuotaManager* manager,
462 const GURL& origin, 462 const GURL& origin,
463 StorageType type, 463 StorageType type,
464 int quota_client_mask,
464 const StatusCallback& callback) 465 const StatusCallback& callback)
465 : QuotaTask(manager), 466 : QuotaTask(manager),
466 origin_(origin), 467 origin_(origin),
467 type_(type), 468 type_(type),
469 quota_client_mask_(quota_client_mask),
468 error_count_(0), 470 error_count_(0),
469 remaining_clients_(-1), 471 remaining_clients_(-1),
472 skipped_clients_(0),
470 callback_(callback), 473 callback_(callback),
471 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 474 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
472 475
473 protected: 476 protected:
474 virtual void Run() OVERRIDE { 477 virtual void Run() OVERRIDE {
475 error_count_ = 0; 478 error_count_ = 0;
476 remaining_clients_ = manager()->clients_.size(); 479 remaining_clients_ = manager()->clients_.size();
477 for (QuotaClientList::iterator iter = manager()->clients_.begin(); 480 for (QuotaClientList::iterator iter = manager()->clients_.begin();
478 iter != manager()->clients_.end(); ++iter) { 481 iter != manager()->clients_.end(); ++iter) {
479 (*iter)->DeleteOriginData( 482 if (quota_client_mask_ & (*iter)->id()) {
480 origin_, type_, 483 (*iter)->DeleteOriginData(
481 base::Bind(&OriginDataDeleter::DidDeleteOriginData, 484 origin_, type_,
482 weak_factory_.GetWeakPtr())); 485 base::Bind(&OriginDataDeleter::DidDeleteOriginData,
486 weak_factory_.GetWeakPtr()));
487 } else {
488 ++skipped_clients_;
489 if (--remaining_clients_ == 0)
490 CallCompleted();
491 }
483 } 492 }
484 } 493 }
485 494
486 virtual void Completed() OVERRIDE { 495 virtual void Completed() OVERRIDE {
487 if (error_count_ == 0) { 496 if (error_count_ == 0) {
488 manager()->DeleteOriginFromDatabase(origin_, type_); 497 // Only remove the entire origin if we didn't skip any client types.
498 if (skipped_clients_ == 0)
499 manager()->DeleteOriginFromDatabase(origin_, type_);
489 callback_.Run(kQuotaStatusOk); 500 callback_.Run(kQuotaStatusOk);
490 } else { 501 } else {
491 callback_.Run(kQuotaErrorInvalidModification); 502 callback_.Run(kQuotaErrorInvalidModification);
492 } 503 }
493 DeleteSoon(); 504 DeleteSoon();
494 } 505 }
495 506
496 virtual void Aborted() OVERRIDE { 507 virtual void Aborted() OVERRIDE {
497 callback_.Run(kQuotaErrorAbort); 508 callback_.Run(kQuotaErrorAbort);
498 DeleteSoon(); 509 DeleteSoon();
499 } 510 }
500 511
501 void DidDeleteOriginData(QuotaStatusCode status) { 512 void DidDeleteOriginData(QuotaStatusCode status) {
502 DCHECK_GT(remaining_clients_, 0); 513 DCHECK_GT(remaining_clients_, 0);
503 514
504 if (status != kQuotaStatusOk) 515 if (status != kQuotaStatusOk)
505 ++error_count_; 516 ++error_count_;
506 517
507 if (--remaining_clients_ == 0) 518 if (--remaining_clients_ == 0)
508 CallCompleted(); 519 CallCompleted();
509 } 520 }
510 521
511 QuotaManager* manager() const { 522 QuotaManager* manager() const {
512 return static_cast<QuotaManager*>(observer()); 523 return static_cast<QuotaManager*>(observer());
513 } 524 }
514 525
515 GURL origin_; 526 GURL origin_;
516 StorageType type_; 527 StorageType type_;
528 int quota_client_mask_;
517 int error_count_; 529 int error_count_;
518 int remaining_clients_; 530 int remaining_clients_;
531 int skipped_clients_;
519 StatusCallback callback_; 532 StatusCallback callback_;
520 533
521 base::WeakPtrFactory<OriginDataDeleter> weak_factory_; 534 base::WeakPtrFactory<OriginDataDeleter> weak_factory_;
522 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter); 535 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter);
523 }; 536 };
524 537
525 class QuotaManager::HostDataDeleter : public QuotaTask { 538 class QuotaManager::HostDataDeleter : public QuotaTask {
526 public: 539 public:
527 HostDataDeleter(QuotaManager* manager, 540 HostDataDeleter(QuotaManager* manager,
528 const std::string& host, 541 const std::string& host,
529 StorageType type, 542 StorageType type,
543 int quota_client_mask,
530 const StatusCallback& callback) 544 const StatusCallback& callback)
531 : QuotaTask(manager), 545 : QuotaTask(manager),
532 host_(host), 546 host_(host),
533 type_(type), 547 type_(type),
548 quota_client_mask_(quota_client_mask),
534 error_count_(0), 549 error_count_(0),
535 remaining_clients_(-1), 550 remaining_clients_(-1),
536 remaining_deleters_(-1), 551 remaining_deleters_(-1),
537 callback_(callback), 552 callback_(callback),
538 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 553 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
539 554
540 protected: 555 protected:
541 virtual void Run() OVERRIDE { 556 virtual void Run() OVERRIDE {
542 error_count_ = 0; 557 error_count_ = 0;
543 remaining_clients_ = manager()->clients_.size(); 558 remaining_clients_ = manager()->clients_.size();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 } 592 }
578 } 593 }
579 594
580 void ScheduleOriginsDeletion() { 595 void ScheduleOriginsDeletion() {
581 remaining_deleters_ = origins_.size(); 596 remaining_deleters_ = origins_.size();
582 for (std::set<GURL>::const_iterator p = origins_.begin(); 597 for (std::set<GURL>::const_iterator p = origins_.begin();
583 p != origins_.end(); 598 p != origins_.end();
584 ++p) { 599 ++p) {
585 OriginDataDeleter* deleter = 600 OriginDataDeleter* deleter =
586 new OriginDataDeleter( 601 new OriginDataDeleter(
587 manager(), *p, type_, 602 manager(), *p, type_, quota_client_mask_,
588 base::Bind(&HostDataDeleter::DidDeleteOriginData, 603 base::Bind(&HostDataDeleter::DidDeleteOriginData,
589 weak_factory_.GetWeakPtr())); 604 weak_factory_.GetWeakPtr()));
590 deleter->Start(); 605 deleter->Start();
591 } 606 }
592 } 607 }
593 608
594 void DidDeleteOriginData(QuotaStatusCode status) { 609 void DidDeleteOriginData(QuotaStatusCode status) {
595 DCHECK_GT(remaining_deleters_, 0); 610 DCHECK_GT(remaining_deleters_, 0);
596 611
597 if (status != kQuotaStatusOk) 612 if (status != kQuotaStatusOk)
598 ++error_count_; 613 ++error_count_;
599 614
600 if (--remaining_deleters_ == 0) 615 if (--remaining_deleters_ == 0)
601 CallCompleted(); 616 CallCompleted();
602 } 617 }
603 618
604 QuotaManager* manager() const { 619 QuotaManager* manager() const {
605 return static_cast<QuotaManager*>(observer()); 620 return static_cast<QuotaManager*>(observer());
606 } 621 }
607 622
608 std::string host_; 623 std::string host_;
609 StorageType type_; 624 StorageType type_;
625 int quota_client_mask_;
610 std::set<GURL> origins_; 626 std::set<GURL> origins_;
611 int error_count_; 627 int error_count_;
612 int remaining_clients_; 628 int remaining_clients_;
613 int remaining_deleters_; 629 int remaining_deleters_;
614 StatusCallback callback_; 630 StatusCallback callback_;
615 631
616 base::WeakPtrFactory<HostDataDeleter> weak_factory_; 632 base::WeakPtrFactory<HostDataDeleter> weak_factory_;
617 DISALLOW_COPY_AND_ASSIGN(HostDataDeleter); 633 DISALLOW_COPY_AND_ASSIGN(HostDataDeleter);
618 }; 634 };
619 635
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 1322
1307 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { 1323 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) {
1308 DCHECK(io_thread_->BelongsToCurrentThread()); 1324 DCHECK(io_thread_->BelongsToCurrentThread());
1309 DCHECK(IsOriginInUse(origin)); 1325 DCHECK(IsOriginInUse(origin));
1310 int& count = origins_in_use_[origin]; 1326 int& count = origins_in_use_[origin];
1311 if (--count == 0) 1327 if (--count == 0)
1312 origins_in_use_.erase(origin); 1328 origins_in_use_.erase(origin);
1313 } 1329 }
1314 1330
1315 void QuotaManager::DeleteOriginData( 1331 void QuotaManager::DeleteOriginData(
1316 const GURL& origin, StorageType type, const StatusCallback& callback) { 1332 const GURL& origin, StorageType type, int quota_client_mask,
1333 const StatusCallback& callback) {
1317 LazyInitialize(); 1334 LazyInitialize();
1318 1335
1319 if (origin.is_empty() || clients_.empty()) { 1336 if (origin.is_empty() || clients_.empty()) {
1320 callback.Run(kQuotaStatusOk); 1337 callback.Run(kQuotaStatusOk);
1321 return; 1338 return;
1322 } 1339 }
1323 1340
1324 OriginDataDeleter* deleter = 1341 OriginDataDeleter* deleter =
1325 new OriginDataDeleter(this, origin, type, callback); 1342 new OriginDataDeleter(this, origin, type, quota_client_mask, callback);
1326 deleter->Start(); 1343 deleter->Start();
1327 } 1344 }
1328 1345
1329 void QuotaManager::DeleteHostData(const std::string& host, 1346 void QuotaManager::DeleteHostData(const std::string& host,
1330 StorageType type, 1347 StorageType type,
1348 int quota_client_mask,
1331 const StatusCallback& callback) { 1349 const StatusCallback& callback) {
1332 1350
1333 LazyInitialize(); 1351 LazyInitialize();
1334 1352
1335 if (host.empty() || clients_.empty()) { 1353 if (host.empty() || clients_.empty()) {
1336 callback.Run(kQuotaStatusOk); 1354 callback.Run(kQuotaStatusOk);
1337 return; 1355 return;
1338 } 1356 }
1339 1357
1340 HostDataDeleter* deleter = 1358 HostDataDeleter* deleter =
1341 new HostDataDeleter(this, host, type, callback); 1359 new HostDataDeleter(this, host, type, quota_client_mask, callback);
1342 deleter->Start(); 1360 deleter->Start();
1343 } 1361 }
1344 1362
1345 bool QuotaManager::ResetUsageTracker(StorageType type) { 1363 bool QuotaManager::ResetUsageTracker(StorageType type) {
1346 switch (type) { 1364 switch (type) {
1347 case kStorageTypeTemporary: 1365 case kStorageTypeTemporary:
1348 if (temporary_usage_tracker_->IsWorking()) 1366 if (temporary_usage_tracker_->IsWorking())
1349 return false; 1367 return false;
1350 temporary_usage_tracker_.reset( 1368 temporary_usage_tracker_.reset(
1351 new UsageTracker(clients_, kStorageTypeTemporary, 1369 new UsageTracker(clients_, kStorageTypeTemporary,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 const GURL& origin, 1538 const GURL& origin,
1521 StorageType type, 1539 StorageType type,
1522 const EvictOriginDataCallback& callback) { 1540 const EvictOriginDataCallback& callback) {
1523 DCHECK(io_thread_->BelongsToCurrentThread()); 1541 DCHECK(io_thread_->BelongsToCurrentThread());
1524 DCHECK_EQ(type, kStorageTypeTemporary); 1542 DCHECK_EQ(type, kStorageTypeTemporary);
1525 1543
1526 eviction_context_.evicted_origin = origin; 1544 eviction_context_.evicted_origin = origin;
1527 eviction_context_.evicted_type = type; 1545 eviction_context_.evicted_type = type;
1528 eviction_context_.evict_origin_data_callback = callback; 1546 eviction_context_.evict_origin_data_callback = callback;
1529 1547
1530 DeleteOriginData(origin, type, 1548 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask,
1531 base::Bind(&QuotaManager::DidOriginDataEvicted, 1549 base::Bind(&QuotaManager::DidOriginDataEvicted,
1532 weak_factory_.GetWeakPtr())); 1550 weak_factory_.GetWeakPtr()));
1533 } 1551 }
1534 1552
1535 void QuotaManager::GetUsageAndQuotaForEviction( 1553 void QuotaManager::GetUsageAndQuotaForEviction(
1536 const GetUsageAndQuotaForEvictionCallback& callback) { 1554 const GetUsageAndQuotaForEvictionCallback& callback) {
1537 DCHECK(io_thread_->BelongsToCurrentThread()); 1555 DCHECK(io_thread_->BelongsToCurrentThread());
1538 GetUsageAndQuotaInternal( 1556 GetUsageAndQuotaInternal(
1539 GURL(), kStorageTypeTemporary, true /* global */, callback); 1557 GURL(), kStorageTypeTemporary, true /* global */, callback);
1540 } 1558 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 1763
1746 QuotaManagerProxy::QuotaManagerProxy( 1764 QuotaManagerProxy::QuotaManagerProxy(
1747 QuotaManager* manager, base::MessageLoopProxy* io_thread) 1765 QuotaManager* manager, base::MessageLoopProxy* io_thread)
1748 : manager_(manager), io_thread_(io_thread) { 1766 : manager_(manager), io_thread_(io_thread) {
1749 } 1767 }
1750 1768
1751 QuotaManagerProxy::~QuotaManagerProxy() { 1769 QuotaManagerProxy::~QuotaManagerProxy() {
1752 } 1770 }
1753 1771
1754 } // namespace quota 1772 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698