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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 typedef std::string ExtensionId; | 62 typedef std::string ExtensionId; |
63 typedef std::string FunctionName; | 63 typedef std::string FunctionName; |
64 // All QuotaLimitHeuristic instances in this map are owned by us. | 64 // All QuotaLimitHeuristic instances in this map are owned by us. |
65 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; | 65 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; |
66 | 66 |
67 // Purge resets all accumulated data as if the service was just created. | 67 // Purge resets all accumulated data as if the service was just created. |
68 // Called periodically so we don't consume an unbounded amount of memory | 68 // Called periodically so we don't consume an unbounded amount of memory |
69 // while tracking quota. | 69 // while tracking quota. |
70 void Purge(); | 70 void Purge(); |
71 void PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map); | 71 void PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map); |
72 base::RepeatingTimer<QuotaService> purge_timer_; | 72 base::RepeatingTimer purge_timer_; |
73 | 73 |
74 // Our quota tracking state for extensions that have invoked quota limited | 74 // Our quota tracking state for extensions that have invoked quota limited |
75 // functions. Each extension is treated separately, so extension ids are the | 75 // functions. Each extension is treated separately, so extension ids are the |
76 // key for the mapping. As an extension invokes functions, the map keeps | 76 // key for the mapping. As an extension invokes functions, the map keeps |
77 // track of which functions it has invoked and the heuristics for each one. | 77 // track of which functions it has invoked and the heuristics for each one. |
78 // Each heuristic will be evaluated and ANDed together to get a final answer. | 78 // Each heuristic will be evaluated and ANDed together to get a final answer. |
79 std::map<ExtensionId, FunctionHeuristicsMap> function_heuristics_; | 79 std::map<ExtensionId, FunctionHeuristicsMap> function_heuristics_; |
80 | 80 |
81 DISALLOW_COPY_AND_ASSIGN(QuotaService); | 81 DISALLOW_COPY_AND_ASSIGN(QuotaService); |
82 }; | 82 }; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 class QuotaService::TimedLimit : public QuotaLimitHeuristic { | 202 class QuotaService::TimedLimit : public QuotaLimitHeuristic { |
203 public: | 203 public: |
204 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) | 204 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) |
205 : QuotaLimitHeuristic(config, map, name) {} | 205 : QuotaLimitHeuristic(config, map, name) {} |
206 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; | 206 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; |
207 }; | 207 }; |
208 | 208 |
209 } // namespace extensions | 209 } // namespace extensions |
210 | 210 |
211 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 211 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
OLD | NEW |