| 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/message_loop/message_loop.h" |  | 
|    8 #include "base/stl_util.h" |    7 #include "base/stl_util.h" | 
 |    8 #include "base/threading/thread_task_runner_handle.h" | 
|    9 #include "extensions/browser/extension_function.h" |    9 #include "extensions/browser/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 constexpr int kPurgeIntervalInDays = 1; | 
|   18  |   18  | 
|   19 const char kOverQuotaError[] = "This request exceeds the * quota."; |   19 constexpr char kOverQuotaError[] = "This request exceeds the * quota."; | 
 |   20  | 
 |   21 bool g_purge_disabled_for_testing = false; | 
|   20  |   22  | 
|   21 }  // namespace |   23 }  // namespace | 
|   22  |   24  | 
|   23 namespace extensions { |   25 namespace extensions { | 
|   24  |   26  | 
|   25 QuotaService::QuotaService() { |   27 QuotaService::QuotaService() { | 
|   26   if (base::MessageLoop::current() != NULL) {  // Null in unit tests. |   28   if (!g_purge_disabled_for_testing && base::ThreadTaskRunnerHandle::IsSet()) { | 
|   27     purge_timer_.Start(FROM_HERE, |   29     purge_timer_.Start(FROM_HERE, | 
|   28                        base::TimeDelta::FromDays(kPurgeIntervalInDays), |   30                        base::TimeDelta::FromDays(kPurgeIntervalInDays), | 
|   29                        this, |   31                        this, | 
|   30                        &QuotaService::Purge); |   32                        &QuotaService::Purge); | 
|   31   } |   33   } | 
|   32 } |   34 } | 
|   33  |   35  | 
|   34 QuotaService::~QuotaService() { |   36 QuotaService::~QuotaService() { | 
|   35   DCHECK(CalledOnValidThread()); |   37   DCHECK(CalledOnValidThread()); | 
|   36   purge_timer_.Stop(); |   38   purge_timer_.Stop(); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   69   } |   71   } | 
|   70  |   72  | 
|   71   if (!failed_heuristic) |   73   if (!failed_heuristic) | 
|   72     return std::string(); |   74     return std::string(); | 
|   73  |   75  | 
|   74   std::string error = failed_heuristic->GetError(); |   76   std::string error = failed_heuristic->GetError(); | 
|   75   DCHECK_GT(error.length(), 0u); |   77   DCHECK_GT(error.length(), 0u); | 
|   76   return error; |   78   return error; | 
|   77 } |   79 } | 
|   78  |   80  | 
 |   81 QuotaService::ScopedDisablePurgeForTesting::ScopedDisablePurgeForTesting() { | 
 |   82   DCHECK(!g_purge_disabled_for_testing); | 
 |   83   g_purge_disabled_for_testing = true; | 
 |   84 } | 
 |   85  | 
 |   86 QuotaService::ScopedDisablePurgeForTesting::~ScopedDisablePurgeForTesting() { | 
 |   87   DCHECK(g_purge_disabled_for_testing); | 
 |   88   g_purge_disabled_for_testing = false; | 
 |   89 } | 
 |   90  | 
|   79 void QuotaService::PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map) { |   91 void QuotaService::PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map) { | 
|   80   FunctionHeuristicsMap::iterator heuristics = map->begin(); |   92   FunctionHeuristicsMap::iterator heuristics = map->begin(); | 
|   81   while (heuristics != map->end()) { |   93   while (heuristics != map->end()) { | 
|   82     STLDeleteElements(&heuristics->second); |   94     STLDeleteElements(&heuristics->second); | 
|   83     map->erase(heuristics++); |   95     map->erase(heuristics++); | 
|   84   } |   96   } | 
|   85 } |   97 } | 
|   86  |   98  | 
|   87 void QuotaService::Purge() { |   99 void QuotaService::Purge() { | 
|   88   DCHECK(CalledOnValidThread()); |  100   DCHECK(CalledOnValidThread()); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  130  |  142  | 
|  131 bool QuotaService::TimedLimit::Apply(Bucket* bucket, |  143 bool QuotaService::TimedLimit::Apply(Bucket* bucket, | 
|  132                                      const base::TimeTicks& event_time) { |  144                                      const base::TimeTicks& event_time) { | 
|  133   if (event_time > bucket->expiration()) |  145   if (event_time > bucket->expiration()) | 
|  134     bucket->Reset(config(), event_time); |  146     bucket->Reset(config(), event_time); | 
|  135  |  147  | 
|  136   return bucket->DeductToken(); |  148   return bucket->DeductToken(); | 
|  137 } |  149 } | 
|  138  |  150  | 
|  139 }  // namespace extensions |  151 }  // namespace extensions | 
| OLD | NEW |