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 |
11 // arguments to a unique Bucket (the BucketMapper), and another to determine | 11 // arguments to a unique Bucket (the BucketMapper), and another to determine |
12 // if a new request involving such an item at a given time is a violation. | 12 // if a new request involving such an item at a given time is a violation. |
13 | 13 |
14 #ifndef EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 14 #ifndef EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
15 #define EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 15 #define EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
16 | 16 |
17 #include <stdint.h> | 17 #include <stdint.h> |
18 | 18 |
19 #include <list> | 19 #include <list> |
20 #include <map> | 20 #include <map> |
| 21 #include <memory> |
21 #include <string> | 22 #include <string> |
22 | 23 |
23 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
24 #include "base/containers/hash_tables.h" | 25 #include "base/containers/hash_tables.h" |
25 #include "base/macros.h" | 26 #include "base/macros.h" |
26 #include "base/memory/scoped_ptr.h" | |
27 #include "base/threading/non_thread_safe.h" | 27 #include "base/threading/non_thread_safe.h" |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "base/timer/timer.h" | 29 #include "base/timer/timer.h" |
30 #include "base/values.h" | 30 #include "base/values.h" |
31 | 31 |
32 class ExtensionFunction; | 32 class ExtensionFunction; |
33 | 33 |
34 namespace extensions { | 34 namespace extensions { |
35 class QuotaLimitHeuristic; | 35 class QuotaLimitHeuristic; |
36 | 36 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Determine if the new event occurring at |event_time| involving |bucket| | 185 // Determine if the new event occurring at |event_time| involving |bucket| |
186 // constitutes a quota violation according to this heuristic. | 186 // constitutes a quota violation according to this heuristic. |
187 virtual bool Apply(Bucket* bucket, const base::TimeTicks& event_time) = 0; | 187 virtual bool Apply(Bucket* bucket, const base::TimeTicks& event_time) = 0; |
188 | 188 |
189 private: | 189 private: |
190 friend class QuotaLimitHeuristicTest; | 190 friend class QuotaLimitHeuristicTest; |
191 | 191 |
192 const Config config_; | 192 const Config config_; |
193 | 193 |
194 // The mapper used in Map. Cannot be NULL. | 194 // The mapper used in Map. Cannot be NULL. |
195 scoped_ptr<BucketMapper> bucket_mapper_; | 195 std::unique_ptr<BucketMapper> bucket_mapper_; |
196 | 196 |
197 // The name of the heuristic for formatting error messages. | 197 // The name of the heuristic for formatting error messages. |
198 std::string name_; | 198 std::string name_; |
199 | 199 |
200 DISALLOW_COPY_AND_ASSIGN(QuotaLimitHeuristic); | 200 DISALLOW_COPY_AND_ASSIGN(QuotaLimitHeuristic); |
201 }; | 201 }; |
202 | 202 |
203 // A simple per-item heuristic to limit the number of events that can occur in | 203 // A simple per-item heuristic to limit the number of events that can occur in |
204 // a given period of time; e.g "no more than 100 events in an hour". | 204 // a given period of time; e.g "no more than 100 events in an hour". |
205 class QuotaService::TimedLimit : public QuotaLimitHeuristic { | 205 class QuotaService::TimedLimit : public QuotaLimitHeuristic { |
206 public: | 206 public: |
207 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) | 207 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) |
208 : QuotaLimitHeuristic(config, map, name) {} | 208 : QuotaLimitHeuristic(config, map, name) {} |
209 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; | 209 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; |
210 }; | 210 }; |
211 | 211 |
212 } // namespace extensions | 212 } // namespace extensions |
213 | 213 |
214 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 214 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
OLD | NEW |