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 12 matching lines...) Expand all Loading... |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/threading/non_thread_safe.h" | 24 #include "base/threading/non_thread_safe.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 | 28 |
29 class ExtensionFunction; | 29 class ExtensionFunction; |
30 | 30 |
31 namespace extensions { | 31 namespace extensions { |
32 class QuotaLimitHeuristic; | 32 class QuotaLimitHeuristic; |
33 class TestResetQuotaFunction; | |
34 | 33 |
35 typedef std::list<QuotaLimitHeuristic*> QuotaLimitHeuristics; | 34 typedef std::list<QuotaLimitHeuristic*> QuotaLimitHeuristics; |
36 | 35 |
37 // The QuotaService takes care that calls to certain extension | 36 // The QuotaService takes care that calls to certain extension |
38 // functions do not exceed predefined quotas. | 37 // functions do not exceed predefined quotas. |
39 // | 38 // |
40 // The QuotaService needs to live entirely on one thread, i.e. be created, | 39 // The QuotaService needs to live entirely on one thread, i.e. be created, |
41 // called and destroyed on the same thread, due to its use of a RepeatingTimer. | 40 // called and destroyed on the same thread, due to its use of a RepeatingTimer. |
42 // It is not a KeyedService because instances exist on both the UI | 41 // It is not a KeyedService because instances exist on both the UI |
43 // and IO threads. | 42 // and IO threads. |
(...skipping 10 matching lines...) Expand all Loading... |
54 // Decide whether the invocation of |function| with argument |args| by the | 53 // Decide whether the invocation of |function| with argument |args| by the |
55 // extension specified by |extension_id| results in a quota limit violation. | 54 // extension specified by |extension_id| results in a quota limit violation. |
56 // Returns an error message representing the failure if quota was exceeded, | 55 // Returns an error message representing the failure if quota was exceeded, |
57 // or empty-string if the request is fine and can proceed. | 56 // or empty-string if the request is fine and can proceed. |
58 std::string Assess(const std::string& extension_id, | 57 std::string Assess(const std::string& extension_id, |
59 ExtensionFunction* function, | 58 ExtensionFunction* function, |
60 const base::ListValue* args, | 59 const base::ListValue* args, |
61 const base::TimeTicks& event_time); | 60 const base::TimeTicks& event_time); |
62 | 61 |
63 private: | 62 private: |
64 friend class extensions::TestResetQuotaFunction; | |
65 typedef std::string ExtensionId; | 63 typedef std::string ExtensionId; |
66 typedef std::string FunctionName; | 64 typedef std::string FunctionName; |
67 // All QuotaLimitHeuristic instances in this map are owned by us. | 65 // All QuotaLimitHeuristic instances in this map are owned by us. |
68 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; | 66 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; |
69 | 67 |
70 // Purge resets all accumulated data (except |violation_errors_|) as if the | 68 // Purge resets all accumulated data (except |violation_errors_|) as if the |
71 // service was just created. Called periodically so we don't consume an | 69 // service was just created. Called periodically so we don't consume an |
72 // unbounded amount of memory while tracking quota. Yes, this could mean an | 70 // unbounded amount of memory while tracking quota. Yes, this could mean an |
73 // extension gets away with murder if it is timed right, but the extensions | 71 // extension gets away with murder if it is timed right, but the extensions |
74 // we are trying to limit are ones that consistently violate, so we'll | 72 // we are trying to limit are ones that consistently violate, so we'll |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 private: | 232 private: |
235 // Specifies how long exhaustion of buckets is allowed to continue before | 233 // Specifies how long exhaustion of buckets is allowed to continue before |
236 // denying requests. | 234 // denying requests. |
237 const int64 repeat_exhaustion_allowance_; | 235 const int64 repeat_exhaustion_allowance_; |
238 int64 num_available_repeat_exhaustions_; | 236 int64 num_available_repeat_exhaustions_; |
239 }; | 237 }; |
240 | 238 |
241 } // namespace extensions | 239 } // namespace extensions |
242 | 240 |
243 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 241 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
OLD | NEW |