| 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 // The QuotaService uses heuristics to limit abusive requests | 5 // The QuotaService uses heuristics to limit abusive requests |
| 6 // made by extensions. In this model 'items' (e.g individual bookmarks) are | 6 // made by extensions. In this model 'items' (e.g individual bookmarks) are |
| 7 // represented by a 'Bucket' that holds state for that item for one single | 7 // represented by a 'Bucket' that holds state for that item for one single |
| 8 // interval of time. The interval of time is defined as 'how long we need to | 8 // interval of time. The interval of time is defined as 'how long we need to |
| 9 // watch an item (for a particular heuristic) before making a decision about | 9 // watch an item (for a particular heuristic) before making a decision about |
| 10 // quota violations'. A heuristic is two functions: one mapping input | 10 // quota violations'. A heuristic is two functions: one mapping input |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Decide whether the invocation of |function| with argument |args| by the | 55 // Decide whether the invocation of |function| with argument |args| by the |
| 56 // extension specified by |extension_id| results in a quota limit violation. | 56 // extension specified by |extension_id| results in a quota limit violation. |
| 57 // Returns an error message representing the failure if quota was exceeded, | 57 // Returns an error message representing the failure if quota was exceeded, |
| 58 // or empty-string if the request is fine and can proceed. | 58 // or empty-string if the request is fine and can proceed. |
| 59 std::string Assess(const std::string& extension_id, | 59 std::string Assess(const std::string& extension_id, |
| 60 ExtensionFunction* function, | 60 ExtensionFunction* function, |
| 61 const base::ListValue* args, | 61 const base::ListValue* args, |
| 62 const base::TimeTicks& event_time); | 62 const base::TimeTicks& event_time); |
| 63 | 63 |
| 64 // An active ScopedDisablePurgeForTesting prevents QuotaService's constructor |
| 65 // from starting a purge timer. |
| 66 class ScopedDisablePurgeForTesting { |
| 67 public: |
| 68 ScopedDisablePurgeForTesting(); |
| 69 ~ScopedDisablePurgeForTesting(); |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ScopedDisablePurgeForTesting); |
| 73 }; |
| 74 |
| 64 private: | 75 private: |
| 65 typedef std::string ExtensionId; | 76 typedef std::string ExtensionId; |
| 66 typedef std::string FunctionName; | 77 typedef std::string FunctionName; |
| 67 // All QuotaLimitHeuristic instances in this map are owned by us. | 78 // All QuotaLimitHeuristic instances in this map are owned by us. |
| 68 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; | 79 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; |
| 69 | 80 |
| 70 // Purge resets all accumulated data as if the service was just created. | 81 // Purge resets all accumulated data as if the service was just created. |
| 71 // Called periodically so we don't consume an unbounded amount of memory | 82 // Called periodically so we don't consume an unbounded amount of memory |
| 72 // while tracking quota. | 83 // while tracking quota. |
| 73 void Purge(); | 84 void Purge(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 class QuotaService::TimedLimit : public QuotaLimitHeuristic { | 216 class QuotaService::TimedLimit : public QuotaLimitHeuristic { |
| 206 public: | 217 public: |
| 207 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) | 218 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) |
| 208 : QuotaLimitHeuristic(config, map, name) {} | 219 : QuotaLimitHeuristic(config, map, name) {} |
| 209 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; | 220 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; |
| 210 }; | 221 }; |
| 211 | 222 |
| 212 } // namespace extensions | 223 } // namespace extensions |
| 213 | 224 |
| 214 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 225 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
| OLD | NEW |