| 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(FROM_HERE, | 21 purge_timer_.Start(base::TimeDelta::FromDays(kPurgeIntervalInDays), |
| 22 base::TimeDelta::FromDays(kPurgeIntervalInDays), | |
| 23 this, &ExtensionsQuotaService::Purge); | 22 this, &ExtensionsQuotaService::Purge); |
| 24 } | 23 } |
| 25 } | 24 } |
| 26 | 25 |
| 27 ExtensionsQuotaService::~ExtensionsQuotaService() { | 26 ExtensionsQuotaService::~ExtensionsQuotaService() { |
| 28 purge_timer_.Stop(); | 27 purge_timer_.Stop(); |
| 29 Purge(); | 28 Purge(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 bool ExtensionsQuotaService::Assess(const std::string& extension_id, | 31 bool ExtensionsQuotaService::Assess(const std::string& extension_id, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 return false; | 146 return false; |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 // We can go negative since we check has_tokens when we get to *next* bucket, | 150 // We can go negative since we check has_tokens when we get to *next* bucket, |
| 152 // and for the small interval all that matters is whether we used up all the | 151 // and for the small interval all that matters is whether we used up all the |
| 153 // tokens (which is true if num_tokens_ <= 0). | 152 // tokens (which is true if num_tokens_ <= 0). |
| 154 bucket->DeductToken(); | 153 bucket->DeductToken(); |
| 155 return true; | 154 return true; |
| 156 } | 155 } |
| OLD | NEW |