| 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 10 matching lines...) Expand all Loading... |
| 21 #include <memory> | 21 #include <memory> |
| 22 #include <string> | 22 #include <string> |
| 23 | 23 |
| 24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
| 25 #include "base/containers/hash_tables.h" | 25 #include "base/containers/hash_tables.h" |
| 26 #include "base/macros.h" | 26 #include "base/macros.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 #include "extensions/common/extension_id.h" |
| 31 | 32 |
| 32 class ExtensionFunction; | 33 class ExtensionFunction; |
| 33 | 34 |
| 34 namespace extensions { | 35 namespace extensions { |
| 35 class QuotaLimitHeuristic; | 36 class QuotaLimitHeuristic; |
| 36 | 37 |
| 37 using QuotaLimitHeuristics = std::list<std::unique_ptr<QuotaLimitHeuristic>>; | 38 using QuotaLimitHeuristics = std::list<std::unique_ptr<QuotaLimitHeuristic>>; |
| 38 | 39 |
| 39 // The QuotaService takes care that calls to certain extension | 40 // The QuotaService takes care that calls to certain extension |
| 40 // functions do not exceed predefined quotas. | 41 // functions do not exceed predefined quotas. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 66 class ScopedDisablePurgeForTesting { | 67 class ScopedDisablePurgeForTesting { |
| 67 public: | 68 public: |
| 68 ScopedDisablePurgeForTesting(); | 69 ScopedDisablePurgeForTesting(); |
| 69 ~ScopedDisablePurgeForTesting(); | 70 ~ScopedDisablePurgeForTesting(); |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ScopedDisablePurgeForTesting); | 73 DISALLOW_COPY_AND_ASSIGN(ScopedDisablePurgeForTesting); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 using ExtensionId = std::string; | |
| 77 using FunctionName = std::string; | 77 using FunctionName = std::string; |
| 78 // All QuotaLimitHeuristic instances in this map are owned by us. | 78 // All QuotaLimitHeuristic instances in this map are owned by us. |
| 79 using FunctionHeuristicsMap = std::map<FunctionName, QuotaLimitHeuristics>; | 79 using FunctionHeuristicsMap = std::map<FunctionName, QuotaLimitHeuristics>; |
| 80 | 80 |
| 81 // 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. |
| 82 // 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 |
| 83 // while tracking quota. | 83 // while tracking quota. |
| 84 void Purge(); | 84 void Purge(); |
| 85 base::RepeatingTimer purge_timer_; | 85 base::RepeatingTimer purge_timer_; |
| 86 | 86 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 class QuotaService::TimedLimit : public QuotaLimitHeuristic { | 215 class QuotaService::TimedLimit : public QuotaLimitHeuristic { |
| 216 public: | 216 public: |
| 217 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) | 217 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) |
| 218 : QuotaLimitHeuristic(config, map, name) {} | 218 : QuotaLimitHeuristic(config, map, name) {} |
| 219 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; | 219 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 } // namespace extensions | 222 } // namespace extensions |
| 223 | 223 |
| 224 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ | 224 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ |
| OLD | NEW |