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 quota_client_mask_ == QuotaClient::kAllClientsMask) { |
michaeln
2012/01/18 23:07:48
is the second condition needed or will the first e
Mike West
2012/01/19 13:09:11
In an earlier review, Kinuko suggested using -1 fo
kinuko
2012/01/19 13:53:11
If quota_client_mask_ is kAllClientsMask (-1) the
Mike West
2012/01/19 16:51:00
... I need to go back to bitwise-school. You're ri
| |
481 base::Bind(&OriginDataDeleter::DidDeleteOriginData, | 484 (*iter)->DeleteOriginData( |
482 weak_factory_.GetWeakPtr())); | 485 origin_, type_, |
486 base::Bind(&OriginDataDeleter::DidDeleteOriginData, | |
487 weak_factory_.GetWeakPtr())); | |
488 } else { | |
489 ++skipped_clients_; | |
490 if (--remaining_clients_ == 0) | |
491 CallCompleted(); | |
492 } | |
483 } | 493 } |
484 } | 494 } |
485 | 495 |
486 virtual void Completed() OVERRIDE { | 496 virtual void Completed() OVERRIDE { |
487 if (error_count_ == 0) { | 497 if (error_count_ == 0) { |
488 manager()->DeleteOriginFromDatabase(origin_, type_); | 498 // Only remove the entire origin if we didn't skip any client types. |
499 if (skipped_clients_ == 0) | |
500 manager()->DeleteOriginFromDatabase(origin_, type_); | |
489 callback_.Run(kQuotaStatusOk); | 501 callback_.Run(kQuotaStatusOk); |
490 } else { | 502 } else { |
491 callback_.Run(kQuotaErrorInvalidModification); | 503 callback_.Run(kQuotaErrorInvalidModification); |
492 } | 504 } |
493 DeleteSoon(); | 505 DeleteSoon(); |
494 } | 506 } |
495 | 507 |
496 virtual void Aborted() OVERRIDE { | 508 virtual void Aborted() OVERRIDE { |
497 callback_.Run(kQuotaErrorAbort); | 509 callback_.Run(kQuotaErrorAbort); |
498 DeleteSoon(); | 510 DeleteSoon(); |
499 } | 511 } |
500 | 512 |
501 void DidDeleteOriginData(QuotaStatusCode status) { | 513 void DidDeleteOriginData(QuotaStatusCode status) { |
502 DCHECK_GT(remaining_clients_, 0); | 514 DCHECK_GT(remaining_clients_, 0); |
503 | 515 |
504 if (status != kQuotaStatusOk) | 516 if (status != kQuotaStatusOk) |
505 ++error_count_; | 517 ++error_count_; |
506 | 518 |
507 if (--remaining_clients_ == 0) | 519 if (--remaining_clients_ == 0) |
508 CallCompleted(); | 520 CallCompleted(); |
509 } | 521 } |
510 | 522 |
511 QuotaManager* manager() const { | 523 QuotaManager* manager() const { |
512 return static_cast<QuotaManager*>(observer()); | 524 return static_cast<QuotaManager*>(observer()); |
513 } | 525 } |
514 | 526 |
515 GURL origin_; | 527 GURL origin_; |
516 StorageType type_; | 528 StorageType type_; |
529 int quota_client_mask_; | |
517 int error_count_; | 530 int error_count_; |
518 int remaining_clients_; | 531 int remaining_clients_; |
532 int skipped_clients_; | |
519 StatusCallback callback_; | 533 StatusCallback callback_; |
520 | 534 |
521 base::WeakPtrFactory<OriginDataDeleter> weak_factory_; | 535 base::WeakPtrFactory<OriginDataDeleter> weak_factory_; |
522 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter); | 536 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter); |
523 }; | 537 }; |
524 | 538 |
525 class QuotaManager::HostDataDeleter : public QuotaTask { | 539 class QuotaManager::HostDataDeleter : public QuotaTask { |
526 public: | 540 public: |
527 HostDataDeleter(QuotaManager* manager, | 541 HostDataDeleter(QuotaManager* manager, |
528 const std::string& host, | 542 const std::string& host, |
529 StorageType type, | 543 StorageType type, |
544 int quota_client_mask, | |
530 const StatusCallback& callback) | 545 const StatusCallback& callback) |
531 : QuotaTask(manager), | 546 : QuotaTask(manager), |
532 host_(host), | 547 host_(host), |
533 type_(type), | 548 type_(type), |
549 quota_client_mask_(quota_client_mask), | |
534 error_count_(0), | 550 error_count_(0), |
535 remaining_clients_(-1), | 551 remaining_clients_(-1), |
536 remaining_deleters_(-1), | 552 remaining_deleters_(-1), |
537 callback_(callback), | 553 callback_(callback), |
538 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} | 554 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
539 | 555 |
540 protected: | 556 protected: |
541 virtual void Run() OVERRIDE { | 557 virtual void Run() OVERRIDE { |
542 error_count_ = 0; | 558 error_count_ = 0; |
543 remaining_clients_ = manager()->clients_.size(); | 559 remaining_clients_ = manager()->clients_.size(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 } | 593 } |
578 } | 594 } |
579 | 595 |
580 void ScheduleOriginsDeletion() { | 596 void ScheduleOriginsDeletion() { |
581 remaining_deleters_ = origins_.size(); | 597 remaining_deleters_ = origins_.size(); |
582 for (std::set<GURL>::const_iterator p = origins_.begin(); | 598 for (std::set<GURL>::const_iterator p = origins_.begin(); |
583 p != origins_.end(); | 599 p != origins_.end(); |
584 ++p) { | 600 ++p) { |
585 OriginDataDeleter* deleter = | 601 OriginDataDeleter* deleter = |
586 new OriginDataDeleter( | 602 new OriginDataDeleter( |
587 manager(), *p, type_, | 603 manager(), *p, type_, quota_client_mask_, |
588 base::Bind(&HostDataDeleter::DidDeleteOriginData, | 604 base::Bind(&HostDataDeleter::DidDeleteOriginData, |
589 weak_factory_.GetWeakPtr())); | 605 weak_factory_.GetWeakPtr())); |
590 deleter->Start(); | 606 deleter->Start(); |
591 } | 607 } |
592 } | 608 } |
593 | 609 |
594 void DidDeleteOriginData(QuotaStatusCode status) { | 610 void DidDeleteOriginData(QuotaStatusCode status) { |
595 DCHECK_GT(remaining_deleters_, 0); | 611 DCHECK_GT(remaining_deleters_, 0); |
596 | 612 |
597 if (status != kQuotaStatusOk) | 613 if (status != kQuotaStatusOk) |
598 ++error_count_; | 614 ++error_count_; |
599 | 615 |
600 if (--remaining_deleters_ == 0) | 616 if (--remaining_deleters_ == 0) |
601 CallCompleted(); | 617 CallCompleted(); |
602 } | 618 } |
603 | 619 |
604 QuotaManager* manager() const { | 620 QuotaManager* manager() const { |
605 return static_cast<QuotaManager*>(observer()); | 621 return static_cast<QuotaManager*>(observer()); |
606 } | 622 } |
607 | 623 |
608 std::string host_; | 624 std::string host_; |
609 StorageType type_; | 625 StorageType type_; |
626 int quota_client_mask_; | |
610 std::set<GURL> origins_; | 627 std::set<GURL> origins_; |
611 int error_count_; | 628 int error_count_; |
612 int remaining_clients_; | 629 int remaining_clients_; |
613 int remaining_deleters_; | 630 int remaining_deleters_; |
614 StatusCallback callback_; | 631 StatusCallback callback_; |
615 | 632 |
616 base::WeakPtrFactory<HostDataDeleter> weak_factory_; | 633 base::WeakPtrFactory<HostDataDeleter> weak_factory_; |
617 DISALLOW_COPY_AND_ASSIGN(HostDataDeleter); | 634 DISALLOW_COPY_AND_ASSIGN(HostDataDeleter); |
618 }; | 635 }; |
619 | 636 |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 | 1323 |
1307 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { | 1324 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { |
1308 DCHECK(io_thread_->BelongsToCurrentThread()); | 1325 DCHECK(io_thread_->BelongsToCurrentThread()); |
1309 DCHECK(IsOriginInUse(origin)); | 1326 DCHECK(IsOriginInUse(origin)); |
1310 int& count = origins_in_use_[origin]; | 1327 int& count = origins_in_use_[origin]; |
1311 if (--count == 0) | 1328 if (--count == 0) |
1312 origins_in_use_.erase(origin); | 1329 origins_in_use_.erase(origin); |
1313 } | 1330 } |
1314 | 1331 |
1315 void QuotaManager::DeleteOriginData( | 1332 void QuotaManager::DeleteOriginData( |
1316 const GURL& origin, StorageType type, const StatusCallback& callback) { | 1333 const GURL& origin, StorageType type, int quota_client_mask, |
1334 const StatusCallback& callback) { | |
1317 LazyInitialize(); | 1335 LazyInitialize(); |
1318 | 1336 |
1319 if (origin.is_empty() || clients_.empty()) { | 1337 if (origin.is_empty() || clients_.empty() || |
1338 quota_client_mask == QuotaClient::kUnknown) { | |
1320 callback.Run(kQuotaStatusOk); | 1339 callback.Run(kQuotaStatusOk); |
1321 return; | 1340 return; |
1322 } | 1341 } |
1323 | 1342 |
1324 OriginDataDeleter* deleter = | 1343 OriginDataDeleter* deleter = |
1325 new OriginDataDeleter(this, origin, type, callback); | 1344 new OriginDataDeleter(this, origin, type, quota_client_mask, callback); |
1326 deleter->Start(); | 1345 deleter->Start(); |
1327 } | 1346 } |
1328 | 1347 |
1329 void QuotaManager::DeleteHostData(const std::string& host, | 1348 void QuotaManager::DeleteHostData(const std::string& host, |
1330 StorageType type, | 1349 StorageType type, |
1350 int quota_client_mask, | |
1331 const StatusCallback& callback) { | 1351 const StatusCallback& callback) { |
1332 | 1352 |
1333 LazyInitialize(); | 1353 LazyInitialize(); |
1334 | 1354 |
1335 if (host.empty() || clients_.empty()) { | 1355 if (host.empty() || clients_.empty()) { |
1336 callback.Run(kQuotaStatusOk); | 1356 callback.Run(kQuotaStatusOk); |
1337 return; | 1357 return; |
1338 } | 1358 } |
1339 | 1359 |
1340 HostDataDeleter* deleter = | 1360 HostDataDeleter* deleter = |
1341 new HostDataDeleter(this, host, type, callback); | 1361 new HostDataDeleter(this, host, type, quota_client_mask, callback); |
1342 deleter->Start(); | 1362 deleter->Start(); |
1343 } | 1363 } |
1344 | 1364 |
1345 bool QuotaManager::ResetUsageTracker(StorageType type) { | 1365 bool QuotaManager::ResetUsageTracker(StorageType type) { |
1346 switch (type) { | 1366 switch (type) { |
1347 case kStorageTypeTemporary: | 1367 case kStorageTypeTemporary: |
1348 if (temporary_usage_tracker_->IsWorking()) | 1368 if (temporary_usage_tracker_->IsWorking()) |
1349 return false; | 1369 return false; |
1350 temporary_usage_tracker_.reset( | 1370 temporary_usage_tracker_.reset( |
1351 new UsageTracker(clients_, kStorageTypeTemporary, | 1371 new UsageTracker(clients_, kStorageTypeTemporary, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 const GURL& origin, | 1540 const GURL& origin, |
1521 StorageType type, | 1541 StorageType type, |
1522 const EvictOriginDataCallback& callback) { | 1542 const EvictOriginDataCallback& callback) { |
1523 DCHECK(io_thread_->BelongsToCurrentThread()); | 1543 DCHECK(io_thread_->BelongsToCurrentThread()); |
1524 DCHECK_EQ(type, kStorageTypeTemporary); | 1544 DCHECK_EQ(type, kStorageTypeTemporary); |
1525 | 1545 |
1526 eviction_context_.evicted_origin = origin; | 1546 eviction_context_.evicted_origin = origin; |
1527 eviction_context_.evicted_type = type; | 1547 eviction_context_.evicted_type = type; |
1528 eviction_context_.evict_origin_data_callback = callback; | 1548 eviction_context_.evict_origin_data_callback = callback; |
1529 | 1549 |
1530 DeleteOriginData(origin, type, | 1550 |
1551 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, | |
1531 base::Bind(&QuotaManager::DidOriginDataEvicted, | 1552 base::Bind(&QuotaManager::DidOriginDataEvicted, |
1532 weak_factory_.GetWeakPtr())); | 1553 weak_factory_.GetWeakPtr())); |
1533 } | 1554 } |
1534 | 1555 |
1535 void QuotaManager::GetUsageAndQuotaForEviction( | 1556 void QuotaManager::GetUsageAndQuotaForEviction( |
1536 const GetUsageAndQuotaForEvictionCallback& callback) { | 1557 const GetUsageAndQuotaForEvictionCallback& callback) { |
1537 DCHECK(io_thread_->BelongsToCurrentThread()); | 1558 DCHECK(io_thread_->BelongsToCurrentThread()); |
1538 GetUsageAndQuotaInternal( | 1559 GetUsageAndQuotaInternal( |
1539 GURL(), kStorageTypeTemporary, true /* global */, callback); | 1560 GURL(), kStorageTypeTemporary, true /* global */, callback); |
1540 } | 1561 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1745 | 1766 |
1746 QuotaManagerProxy::QuotaManagerProxy( | 1767 QuotaManagerProxy::QuotaManagerProxy( |
1747 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1768 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
1748 : manager_(manager), io_thread_(io_thread) { | 1769 : manager_(manager), io_thread_(io_thread) { |
1749 } | 1770 } |
1750 | 1771 |
1751 QuotaManagerProxy::~QuotaManagerProxy() { | 1772 QuotaManagerProxy::~QuotaManagerProxy() { |
1752 } | 1773 } |
1753 | 1774 |
1754 } // namespace quota | 1775 } // namespace quota |
OLD | NEW |