| 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/usage_tracker.h" | 5 #include "webkit/quota/usage_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 36 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 36 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 37 DCHECK(tracker_); | 37 DCHECK(tracker_); |
| 38 DCHECK(client_); | 38 DCHECK(client_); |
| 39 client_tracker_ = tracker_->GetClientTracker(client_->id()); | 39 client_tracker_ = tracker_->GetClientTracker(client_->id()); |
| 40 DCHECK(client_tracker_); | 40 DCHECK(client_tracker_); |
| 41 } | 41 } |
| 42 virtual ~GatherUsageTaskBase() {} | 42 virtual ~GatherUsageTaskBase() {} |
| 43 | 43 |
| 44 // Get total usage for the given |origins|. | 44 // Get total usage for the given |origins|. |
| 45 void GetUsageForOrigins(const std::set<GURL>& origins, StorageType type) { | 45 void GetUsageForOrigins(const std::set<GURL>& origins, StorageType type) { |
| 46 DCHECK(original_message_loop()->BelongsToCurrentThread()); | 46 DCHECK(original_task_runner()->BelongsToCurrentThread()); |
| 47 // We do not get usage for origins for which we have valid usage cache. | 47 // We do not get usage for origins for which we have valid usage cache. |
| 48 std::vector<GURL> origins_to_gather; | 48 std::vector<GURL> origins_to_gather; |
| 49 std::set<GURL> cached_origins; | 49 std::set<GURL> cached_origins; |
| 50 client_tracker()->GetCachedOrigins(&cached_origins); | 50 client_tracker()->GetCachedOrigins(&cached_origins); |
| 51 std::set<GURL> already_added; | 51 std::set<GURL> already_added; |
| 52 for (std::set<GURL>::const_iterator iter = origins.begin(); | 52 for (std::set<GURL>::const_iterator iter = origins.begin(); |
| 53 iter != origins.end(); ++iter) { | 53 iter != origins.end(); ++iter) { |
| 54 if (cached_origins.find(*iter) == cached_origins.end() && | 54 if (cached_origins.find(*iter) == cached_origins.end() && |
| 55 already_added.insert(*iter).second) { | 55 already_added.insert(*iter).second) { |
| 56 origins_to_gather.push_back(*iter); | 56 origins_to_gather.push_back(*iter); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 protected: | 84 protected: |
| 85 virtual void Aborted() OVERRIDE { | 85 virtual void Aborted() OVERRIDE { |
| 86 DeleteSoon(); | 86 DeleteSoon(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 UsageTracker* tracker() const { return tracker_; } | 89 UsageTracker* tracker() const { return tracker_; } |
| 90 ClientUsageTracker* client_tracker() const { return client_tracker_; } | 90 ClientUsageTracker* client_tracker() const { return client_tracker_; } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 void DidGetUsage(int64 usage) { | 93 void DidGetUsage(int64 usage) { |
| 94 DCHECK(original_message_loop()->BelongsToCurrentThread()); | 94 DCHECK(original_task_runner()->BelongsToCurrentThread()); |
| 95 DCHECK(!pending_origins_.empty()); | 95 DCHECK(!pending_origins_.empty()); |
| 96 DCHECK(client_tracker_); | 96 DCHECK(client_tracker_); |
| 97 | 97 |
| 98 // Defend against confusing inputs from QuotaClients. | 98 // Defend against confusing inputs from QuotaClients. |
| 99 DCHECK_GE(usage, 0); | 99 DCHECK_GE(usage, 0); |
| 100 if (usage < 0) | 100 if (usage < 0) |
| 101 usage = 0; | 101 usage = 0; |
| 102 | 102 |
| 103 // This code assumes DidGetUsage callbacks are called in the same | 103 // This code assumes DidGetUsage callbacks are called in the same |
| 104 // order as we dispatched GetOriginUsage calls. | 104 // order as we dispatched GetOriginUsage calls. |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 void ClientUsageTracker::NoopHostUsageCallback( | 510 void ClientUsageTracker::NoopHostUsageCallback( |
| 511 const std::string& host, StorageType type, int64 usage) { | 511 const std::string& host, StorageType type, int64 usage) { |
| 512 } | 512 } |
| 513 | 513 |
| 514 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { | 514 bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { |
| 515 return special_storage_policy_.get() && | 515 return special_storage_policy_.get() && |
| 516 special_storage_policy_->IsStorageUnlimited(origin); | 516 special_storage_policy_->IsStorageUnlimited(origin); |
| 517 } | 517 } |
| 518 | 518 |
| 519 } // namespace quota | 519 } // namespace quota |
| OLD | NEW |