OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/extensions/extensions_quota_service.h" | 5 #include "chrome/browser/extensions/extensions_quota_service.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/extensions/extension_function.h" | 9 #include "chrome/browser/extensions/extension_function.h" |
10 | 10 |
11 // If the browser stays open long enough, we reset state once a day. | 11 // If the browser stays open long enough, we reset state once a day. |
12 // Whatever this value is, it should be an order of magnitude longer than | 12 // Whatever this value is, it should be an order of magnitude longer than |
13 // the longest interval in any of the QuotaLimitHeuristics in use. | 13 // the longest interval in any of the QuotaLimitHeuristics in use. |
14 static const int kPurgeIntervalInDays = 1; | 14 static const int kPurgeIntervalInDays = 1; |
15 | 15 |
16 const char QuotaLimitHeuristic::kGenericOverQuotaError[] = | 16 const char QuotaLimitHeuristic::kGenericOverQuotaError[] = |
17 "This request exceeds available quota."; | 17 "This request exceeds available quota."; |
18 | 18 |
19 ExtensionsQuotaService::ExtensionsQuotaService() { | 19 ExtensionsQuotaService::ExtensionsQuotaService() { |
20 if (MessageLoop::current() != NULL) { // Null in unit tests. | 20 if (MessageLoop::current() != NULL) { // Null in unit tests. |
21 purge_timer_.Start(base::TimeDelta::FromDays(kPurgeIntervalInDays), | 21 purge_timer_.Start(FROM_HERE, |
| 22 base::TimeDelta::FromDays(kPurgeIntervalInDays), |
22 this, &ExtensionsQuotaService::Purge); | 23 this, &ExtensionsQuotaService::Purge); |
23 } | 24 } |
24 } | 25 } |
25 | 26 |
26 ExtensionsQuotaService::~ExtensionsQuotaService() { | 27 ExtensionsQuotaService::~ExtensionsQuotaService() { |
27 purge_timer_.Stop(); | 28 purge_timer_.Stop(); |
28 Purge(); | 29 Purge(); |
29 } | 30 } |
30 | 31 |
31 bool ExtensionsQuotaService::Assess(const std::string& extension_id, | 32 bool ExtensionsQuotaService::Assess(const std::string& extension_id, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return false; | 147 return false; |
147 } | 148 } |
148 } | 149 } |
149 | 150 |
150 // We can go negative since we check has_tokens when we get to *next* bucket, | 151 // We can go negative since we check has_tokens when we get to *next* bucket, |
151 // and for the small interval all that matters is whether we used up all the | 152 // and for the small interval all that matters is whether we used up all the |
152 // tokens (which is true if num_tokens_ <= 0). | 153 // tokens (which is true if num_tokens_ <= 0). |
153 bucket->DeductToken(); | 154 bucket->DeductToken(); |
154 return true; | 155 return true; |
155 } | 156 } |
OLD | NEW |