Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: extensions/browser/quota_service.h

Issue 2915523002: Replace deprecated base::NonThreadSafe in extensions in favor of SequenceChecker. (Closed)
Patch Set: Add TestBrowserThreadBundle Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/extension_throttle_manager.cc ('k') | extensions/browser/quota_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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/thread_checker.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 #include "extensions/common/extension_id.h"
32 32
33 class ExtensionFunction; 33 class ExtensionFunction;
34 34
35 namespace extensions { 35 namespace extensions {
36 class QuotaLimitHeuristic; 36 class QuotaLimitHeuristic;
37 37
38 using QuotaLimitHeuristics = std::list<std::unique_ptr<QuotaLimitHeuristic>>; 38 using QuotaLimitHeuristics = std::list<std::unique_ptr<QuotaLimitHeuristic>>;
39 39
40 // The QuotaService takes care that calls to certain extension 40 // The QuotaService takes care that calls to certain extension
41 // functions do not exceed predefined quotas. 41 // functions do not exceed predefined quotas.
42 // 42 //
43 // The QuotaService needs to live entirely on one thread, i.e. be created, 43 // The QuotaService needs to live entirely on one thread, i.e. be created,
44 // called and destroyed on the same thread, due to its use of a RepeatingTimer. 44 // called and destroyed on the same thread, due to its use of a RepeatingTimer.
45 // It is not a KeyedService because instances exist on both the UI 45 // It is not a KeyedService because instances exist on both the UI
46 // and IO threads. 46 // and IO threads.
47 class QuotaService : public base::NonThreadSafe { 47 class QuotaService {
48 public: 48 public:
49 // Some concrete heuristics (declared below) that ExtensionFunctions can 49 // Some concrete heuristics (declared below) that ExtensionFunctions can
50 // use to help the service make decisions about quota violations. 50 // use to help the service make decisions about quota violations.
51 class TimedLimit; 51 class TimedLimit;
52 52
53 QuotaService(); 53 QuotaService();
54 virtual ~QuotaService(); 54 virtual ~QuotaService();
55 55
56 // Decide whether the invocation of |function| with argument |args| by the 56 // Decide whether the invocation of |function| with argument |args| by the
57 // extension specified by |extension_id| results in a quota limit violation. 57 // extension specified by |extension_id| results in a quota limit violation.
(...skipping 26 matching lines...) Expand all
84 void Purge(); 84 void Purge();
85 base::RepeatingTimer purge_timer_; 85 base::RepeatingTimer purge_timer_;
86 86
87 // Our quota tracking state for extensions that have invoked quota limited 87 // Our quota tracking state for extensions that have invoked quota limited
88 // functions. Each extension is treated separately, so extension ids are the 88 // functions. Each extension is treated separately, so extension ids are the
89 // key for the mapping. As an extension invokes functions, the map keeps 89 // key for the mapping. As an extension invokes functions, the map keeps
90 // track of which functions it has invoked and the heuristics for each one. 90 // track of which functions it has invoked and the heuristics for each one.
91 // Each heuristic will be evaluated and ANDed together to get a final answer. 91 // Each heuristic will be evaluated and ANDed together to get a final answer.
92 std::map<ExtensionId, FunctionHeuristicsMap> function_heuristics_; 92 std::map<ExtensionId, FunctionHeuristicsMap> function_heuristics_;
93 93
94 THREAD_CHECKER(thread_checker_);
95
94 DISALLOW_COPY_AND_ASSIGN(QuotaService); 96 DISALLOW_COPY_AND_ASSIGN(QuotaService);
95 }; 97 };
96 98
97 // A QuotaLimitHeuristic is two things: 1, A heuristic to map extension 99 // A QuotaLimitHeuristic is two things: 1, A heuristic to map extension
98 // function arguments to corresponding Buckets for each input arg, and 2) a 100 // function arguments to corresponding Buckets for each input arg, and 2) a
99 // heuristic for determining if a new event involving a particular item 101 // heuristic for determining if a new event involving a particular item
100 // (represented by its Bucket) constitutes a quota violation. 102 // (represented by its Bucket) constitutes a quota violation.
101 class QuotaLimitHeuristic { 103 class QuotaLimitHeuristic {
102 public: 104 public:
103 // Parameters to configure the amount of tokens allotted to individual 105 // Parameters to configure the amount of tokens allotted to individual
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 class QuotaService::TimedLimit : public QuotaLimitHeuristic { 217 class QuotaService::TimedLimit : public QuotaLimitHeuristic {
216 public: 218 public:
217 TimedLimit(const Config& config, BucketMapper* map, const std::string& name) 219 TimedLimit(const Config& config, BucketMapper* map, const std::string& name)
218 : QuotaLimitHeuristic(config, map, name) {} 220 : QuotaLimitHeuristic(config, map, name) {}
219 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; 221 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override;
220 }; 222 };
221 223
222 } // namespace extensions 224 } // namespace extensions
223 225
224 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_ 226 #endif // EXTENSIONS_BROWSER_QUOTA_SERVICE_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_throttle_manager.cc ('k') | extensions/browser/quota_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698