OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/quota_service.h" | 5 #include "extensions/browser/quota_service.h" |
6 | 6 |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "extensions/browser/extension_function.h" | 8 #include "extensions/browser/extension_function.h" |
9 #include "extensions/common/error_utils.h" | 9 #include "extensions/common/error_utils.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 QuotaService::QuotaService() { | 26 QuotaService::QuotaService() { |
27 if (!g_purge_disabled_for_testing && base::ThreadTaskRunnerHandle::IsSet()) { | 27 if (!g_purge_disabled_for_testing && base::ThreadTaskRunnerHandle::IsSet()) { |
28 purge_timer_.Start(FROM_HERE, | 28 purge_timer_.Start(FROM_HERE, |
29 base::TimeDelta::FromDays(kPurgeIntervalInDays), | 29 base::TimeDelta::FromDays(kPurgeIntervalInDays), |
30 this, | 30 this, |
31 &QuotaService::Purge); | 31 &QuotaService::Purge); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 QuotaService::~QuotaService() { | 35 QuotaService::~QuotaService() { |
36 DCHECK(CalledOnValidThread()); | 36 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
37 purge_timer_.Stop(); | 37 purge_timer_.Stop(); |
38 Purge(); | 38 Purge(); |
39 } | 39 } |
40 | 40 |
41 std::string QuotaService::Assess(const std::string& extension_id, | 41 std::string QuotaService::Assess(const std::string& extension_id, |
42 ExtensionFunction* function, | 42 ExtensionFunction* function, |
43 const base::ListValue* args, | 43 const base::ListValue* args, |
44 const base::TimeTicks& event_time) { | 44 const base::TimeTicks& event_time) { |
45 DCHECK(CalledOnValidThread()); | 45 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
46 | 46 |
47 if (function->ShouldSkipQuotaLimiting()) | 47 if (function->ShouldSkipQuotaLimiting()) |
48 return std::string(); | 48 return std::string(); |
49 | 49 |
50 // Lookup function list for extension. | 50 // Lookup function list for extension. |
51 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; | 51 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; |
52 | 52 |
53 // Lookup heuristics for function, create if necessary. | 53 // Lookup heuristics for function, create if necessary. |
54 QuotaLimitHeuristics& heuristics = functions[function->name()]; | 54 QuotaLimitHeuristics& heuristics = functions[function->name()]; |
55 if (heuristics.empty()) | 55 if (heuristics.empty()) |
(...skipping 23 matching lines...) Expand all Loading... |
79 DCHECK(!g_purge_disabled_for_testing); | 79 DCHECK(!g_purge_disabled_for_testing); |
80 g_purge_disabled_for_testing = true; | 80 g_purge_disabled_for_testing = true; |
81 } | 81 } |
82 | 82 |
83 QuotaService::ScopedDisablePurgeForTesting::~ScopedDisablePurgeForTesting() { | 83 QuotaService::ScopedDisablePurgeForTesting::~ScopedDisablePurgeForTesting() { |
84 DCHECK(g_purge_disabled_for_testing); | 84 DCHECK(g_purge_disabled_for_testing); |
85 g_purge_disabled_for_testing = false; | 85 g_purge_disabled_for_testing = false; |
86 } | 86 } |
87 | 87 |
88 void QuotaService::Purge() { | 88 void QuotaService::Purge() { |
89 DCHECK(CalledOnValidThread()); | 89 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
90 for (auto it = function_heuristics_.begin(); it != function_heuristics_.end(); | 90 for (auto it = function_heuristics_.begin(); it != function_heuristics_.end(); |
91 function_heuristics_.erase(it++)) { | 91 function_heuristics_.erase(it++)) { |
92 it->second.clear(); | 92 it->second.clear(); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void QuotaLimitHeuristic::Bucket::Reset(const Config& config, | 96 void QuotaLimitHeuristic::Bucket::Reset(const Config& config, |
97 const base::TimeTicks& start) { | 97 const base::TimeTicks& start) { |
98 num_tokens_ = config.refill_token_count; | 98 num_tokens_ = config.refill_token_count; |
99 expiration_ = start + config.refill_interval; | 99 expiration_ = start + config.refill_interval; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 bool QuotaService::TimedLimit::Apply(Bucket* bucket, | 132 bool QuotaService::TimedLimit::Apply(Bucket* bucket, |
133 const base::TimeTicks& event_time) { | 133 const base::TimeTicks& event_time) { |
134 if (event_time > bucket->expiration()) | 134 if (event_time > bucket->expiration()) |
135 bucket->Reset(config(), event_time); | 135 bucket->Reset(config(), event_time); |
136 | 136 |
137 return bucket->DeductToken(); | 137 return bucket->DeductToken(); |
138 } | 138 } |
139 | 139 |
140 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |