OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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() || |
1337 quota_client_mask == QuotaClient::kUnknown) { | |
kinuko
2012/01/22 18:35:31
Not sure this is really meaningful for a bitmask?
Mike West
2012/01/22 20:54:38
Actually, this doesn't make any sense at all. I ad
| |
1320 callback.Run(kQuotaStatusOk); | 1338 callback.Run(kQuotaStatusOk); |
1321 return; | 1339 return; |
1322 } | 1340 } |
1323 | 1341 |
1324 OriginDataDeleter* deleter = | 1342 OriginDataDeleter* deleter = |
1325 new OriginDataDeleter(this, origin, type, callback); | 1343 new OriginDataDeleter(this, origin, type, quota_client_mask, callback); |
1326 deleter->Start(); | 1344 deleter->Start(); |
1327 } | 1345 } |
1328 | 1346 |
1329 void QuotaManager::DeleteHostData(const std::string& host, | 1347 void QuotaManager::DeleteHostData(const std::string& host, |
1330 StorageType type, | 1348 StorageType type, |
1349 int quota_client_mask, | |
1331 const StatusCallback& callback) { | 1350 const StatusCallback& callback) { |
1332 | 1351 |
1333 LazyInitialize(); | 1352 LazyInitialize(); |
1334 | 1353 |
1335 if (host.empty() || clients_.empty()) { | 1354 if (host.empty() || clients_.empty()) { |
1336 callback.Run(kQuotaStatusOk); | 1355 callback.Run(kQuotaStatusOk); |
1337 return; | 1356 return; |
1338 } | 1357 } |
1339 | 1358 |
1340 HostDataDeleter* deleter = | 1359 HostDataDeleter* deleter = |
1341 new HostDataDeleter(this, host, type, callback); | 1360 new HostDataDeleter(this, host, type, quota_client_mask, callback); |
1342 deleter->Start(); | 1361 deleter->Start(); |
1343 } | 1362 } |
1344 | 1363 |
1345 bool QuotaManager::ResetUsageTracker(StorageType type) { | 1364 bool QuotaManager::ResetUsageTracker(StorageType type) { |
1346 switch (type) { | 1365 switch (type) { |
1347 case kStorageTypeTemporary: | 1366 case kStorageTypeTemporary: |
1348 if (temporary_usage_tracker_->IsWorking()) | 1367 if (temporary_usage_tracker_->IsWorking()) |
1349 return false; | 1368 return false; |
1350 temporary_usage_tracker_.reset( | 1369 temporary_usage_tracker_.reset( |
1351 new UsageTracker(clients_, kStorageTypeTemporary, | 1370 new UsageTracker(clients_, kStorageTypeTemporary, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 const GURL& origin, | 1539 const GURL& origin, |
1521 StorageType type, | 1540 StorageType type, |
1522 const EvictOriginDataCallback& callback) { | 1541 const EvictOriginDataCallback& callback) { |
1523 DCHECK(io_thread_->BelongsToCurrentThread()); | 1542 DCHECK(io_thread_->BelongsToCurrentThread()); |
1524 DCHECK_EQ(type, kStorageTypeTemporary); | 1543 DCHECK_EQ(type, kStorageTypeTemporary); |
1525 | 1544 |
1526 eviction_context_.evicted_origin = origin; | 1545 eviction_context_.evicted_origin = origin; |
1527 eviction_context_.evicted_type = type; | 1546 eviction_context_.evicted_type = type; |
1528 eviction_context_.evict_origin_data_callback = callback; | 1547 eviction_context_.evict_origin_data_callback = callback; |
1529 | 1548 |
1530 DeleteOriginData(origin, type, | 1549 |
kinuko
2012/01/22 18:35:31
nit: extra empty line
Mike West
2012/01/22 20:54:38
Done.
| |
1550 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, | |
1531 base::Bind(&QuotaManager::DidOriginDataEvicted, | 1551 base::Bind(&QuotaManager::DidOriginDataEvicted, |
1532 weak_factory_.GetWeakPtr())); | 1552 weak_factory_.GetWeakPtr())); |
1533 } | 1553 } |
1534 | 1554 |
1535 void QuotaManager::GetUsageAndQuotaForEviction( | 1555 void QuotaManager::GetUsageAndQuotaForEviction( |
1536 const GetUsageAndQuotaForEvictionCallback& callback) { | 1556 const GetUsageAndQuotaForEvictionCallback& callback) { |
1537 DCHECK(io_thread_->BelongsToCurrentThread()); | 1557 DCHECK(io_thread_->BelongsToCurrentThread()); |
1538 GetUsageAndQuotaInternal( | 1558 GetUsageAndQuotaInternal( |
1539 GURL(), kStorageTypeTemporary, true /* global */, callback); | 1559 GURL(), kStorageTypeTemporary, true /* global */, callback); |
1540 } | 1560 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1745 | 1765 |
1746 QuotaManagerProxy::QuotaManagerProxy( | 1766 QuotaManagerProxy::QuotaManagerProxy( |
1747 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1767 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
1748 : manager_(manager), io_thread_(io_thread) { | 1768 : manager_(manager), io_thread_(io_thread) { |
1749 } | 1769 } |
1750 | 1770 |
1751 QuotaManagerProxy::~QuotaManagerProxy() { | 1771 QuotaManagerProxy::~QuotaManagerProxy() { |
1752 } | 1772 } |
1753 | 1773 |
1754 } // namespace quota | 1774 } // namespace quota |
OLD | NEW |