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

Side by Side Diff: storage/browser/quota/client_usage_tracker.cc

Issue 2908223002: Deprecate NonThreadSafe in storage/browser/quota in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "storage/browser/quota/client_usage_tracker.h" 5 #include "storage/browser/quota/client_usage_tracker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 global_unlimited_usage_(0), 69 global_unlimited_usage_(0),
70 global_usage_retrieved_(false), 70 global_usage_retrieved_(false),
71 special_storage_policy_(special_storage_policy) { 71 special_storage_policy_(special_storage_policy) {
72 DCHECK(tracker_); 72 DCHECK(tracker_);
73 DCHECK(client_); 73 DCHECK(client_);
74 if (special_storage_policy_.get()) 74 if (special_storage_policy_.get())
75 special_storage_policy_->AddObserver(this); 75 special_storage_policy_->AddObserver(this);
76 } 76 }
77 77
78 ClientUsageTracker::~ClientUsageTracker() { 78 ClientUsageTracker::~ClientUsageTracker() {
79 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
79 if (special_storage_policy_.get()) 80 if (special_storage_policy_.get())
80 special_storage_policy_->RemoveObserver(this); 81 special_storage_policy_->RemoveObserver(this);
81 } 82 }
82 83
83 void ClientUsageTracker::GetGlobalLimitedUsage(const UsageCallback& callback) { 84 void ClientUsageTracker::GetGlobalLimitedUsage(const UsageCallback& callback) {
84 if (!global_usage_retrieved_) { 85 if (!global_usage_retrieved_) {
85 GetGlobalUsage(base::Bind(&DidGetGlobalUsageForLimitedGlobalUsage, 86 GetGlobalUsage(base::Bind(&DidGetGlobalUsageForLimitedGlobalUsage,
86 callback)); 87 callback));
87 return; 88 return;
88 } 89 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 const GURL& origin) const { 417 const GURL& origin) const {
417 std::string host = net::GetHostOrSpecFromURL(origin); 418 std::string host = net::GetHostOrSpecFromURL(origin);
418 return !OriginSetContainsOrigin(non_cached_limited_origins_by_host_, 419 return !OriginSetContainsOrigin(non_cached_limited_origins_by_host_,
419 host, origin) && 420 host, origin) &&
420 !OriginSetContainsOrigin(non_cached_unlimited_origins_by_host_, 421 !OriginSetContainsOrigin(non_cached_unlimited_origins_by_host_,
421 host, origin); 422 host, origin);
422 } 423 }
423 424
424 void ClientUsageTracker::OnGranted(const GURL& origin, 425 void ClientUsageTracker::OnGranted(const GURL& origin,
425 int change_flags) { 426 int change_flags) {
426 DCHECK(CalledOnValidThread()); 427 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
427 if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) { 428 if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) {
428 int64_t usage = 0; 429 int64_t usage = 0;
429 if (GetCachedOriginUsage(origin, &usage)) { 430 if (GetCachedOriginUsage(origin, &usage)) {
430 global_unlimited_usage_ += usage; 431 global_unlimited_usage_ += usage;
431 global_limited_usage_ -= usage; 432 global_limited_usage_ -= usage;
432 } 433 }
433 434
434 std::string host = net::GetHostOrSpecFromURL(origin); 435 std::string host = net::GetHostOrSpecFromURL(origin);
435 if (EraseOriginFromOriginSet(&non_cached_limited_origins_by_host_, 436 if (EraseOriginFromOriginSet(&non_cached_limited_origins_by_host_,
436 host, origin)) 437 host, origin))
437 non_cached_unlimited_origins_by_host_[host].insert(origin); 438 non_cached_unlimited_origins_by_host_[host].insert(origin);
438 } 439 }
439 } 440 }
440 441
441 void ClientUsageTracker::OnRevoked(const GURL& origin, 442 void ClientUsageTracker::OnRevoked(const GURL& origin,
442 int change_flags) { 443 int change_flags) {
443 DCHECK(CalledOnValidThread()); 444 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
444 if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) { 445 if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) {
445 int64_t usage = 0; 446 int64_t usage = 0;
446 if (GetCachedOriginUsage(origin, &usage)) { 447 if (GetCachedOriginUsage(origin, &usage)) {
447 global_unlimited_usage_ -= usage; 448 global_unlimited_usage_ -= usage;
448 global_limited_usage_ += usage; 449 global_limited_usage_ += usage;
449 } 450 }
450 451
451 std::string host = net::GetHostOrSpecFromURL(origin); 452 std::string host = net::GetHostOrSpecFromURL(origin);
452 if (EraseOriginFromOriginSet(&non_cached_unlimited_origins_by_host_, 453 if (EraseOriginFromOriginSet(&non_cached_unlimited_origins_by_host_,
453 host, origin)) 454 host, origin))
454 non_cached_limited_origins_by_host_[host].insert(origin); 455 non_cached_limited_origins_by_host_[host].insert(origin);
455 } 456 }
456 } 457 }
457 458
458 void ClientUsageTracker::OnCleared() { 459 void ClientUsageTracker::OnCleared() {
459 DCHECK(CalledOnValidThread()); 460 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
460 global_limited_usage_ += global_unlimited_usage_; 461 global_limited_usage_ += global_unlimited_usage_;
461 global_unlimited_usage_ = 0; 462 global_unlimited_usage_ = 0;
462 463
463 for (const auto& host_and_origins : non_cached_unlimited_origins_by_host_) { 464 for (const auto& host_and_origins : non_cached_unlimited_origins_by_host_) {
464 const auto& host = host_and_origins.first; 465 const auto& host = host_and_origins.first;
465 for (const auto& origin : host_and_origins.second) 466 for (const auto& origin : host_and_origins.second)
466 non_cached_limited_origins_by_host_[host].insert(origin); 467 non_cached_limited_origins_by_host_[host].insert(origin);
467 } 468 }
468 non_cached_unlimited_origins_by_host_.clear(); 469 non_cached_unlimited_origins_by_host_.clear();
469 } 470 }
470 471
471 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { 472 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const {
472 if (type_ == kStorageTypeSyncable) 473 if (type_ == kStorageTypeSyncable)
473 return false; 474 return false;
474 return special_storage_policy_.get() && 475 return special_storage_policy_.get() &&
475 special_storage_policy_->IsStorageUnlimited(origin); 476 special_storage_policy_->IsStorageUnlimited(origin);
476 } 477 }
477 478
478 } // namespace storage 479 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/quota/client_usage_tracker.h ('k') | storage/browser/quota/quota_temporary_storage_evictor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698