Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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 "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 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // If the browser stays open long enough, we reset state once a day. | 14 // If the browser stays open long enough, we reset state once a day. |
| 15 // Whatever this value is, it should be an order of magnitude longer than | 15 // Whatever this value is, it should be an order of magnitude longer than |
| 16 // the longest interval in any of the QuotaLimitHeuristics in use. | 16 // the longest interval in any of the QuotaLimitHeuristics in use. |
| 17 const int kPurgeIntervalInDays = 1; | 17 const int kPurgeIntervalInDays = 1; |
| 18 | 18 |
| 19 const char kOverQuotaError[] = "This request exceeds the * quota."; | 19 const char kOverQuotaError[] = "This request exceeds the * quota."; |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 ExtensionsQuotaService::ExtensionsQuotaService() { | 23 ExtensionsQuotaService::ExtensionsQuotaService() { |
| 24 if (MessageLoop::current() != NULL) { // Null in unit tests. | 24 if (base::MessageLoop::current() != NULL) { // Null in unit tests. |
| 25 purge_timer_.Start(FROM_HERE, | 25 purge_timer_.Start(FROM_HERE, |
| 26 base::TimeDelta::FromDays(kPurgeIntervalInDays), | 26 base::TimeDelta::FromDays(kPurgeIntervalInDays), |
| 27 this, &ExtensionsQuotaService::Purge); | 27 this, |
|
brettw
2013/04/28 04:26:27
Ditto
| |
| 28 &ExtensionsQuotaService::Purge); | |
| 28 } | 29 } |
| 29 } | 30 } |
| 30 | 31 |
| 31 ExtensionsQuotaService::~ExtensionsQuotaService() { | 32 ExtensionsQuotaService::~ExtensionsQuotaService() { |
| 32 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 33 purge_timer_.Stop(); | 34 purge_timer_.Stop(); |
| 34 Purge(); | 35 Purge(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 std::string ExtensionsQuotaService::Assess( | 38 std::string ExtensionsQuotaService::Assess( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 return false; | 183 return false; |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 // We can go negative since we check has_tokens when we get to *next* bucket, | 187 // We can go negative since we check has_tokens when we get to *next* bucket, |
| 187 // and for the small interval all that matters is whether we used up all the | 188 // and for the small interval all that matters is whether we used up all the |
| 188 // tokens (which is true if num_tokens_ <= 0). | 189 // tokens (which is true if num_tokens_ <= 0). |
| 189 bucket->DeductToken(); | 190 bucket->DeductToken(); |
| 190 return true; | 191 return true; |
| 191 } | 192 } |
| OLD | NEW |