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

Side by Side Diff: chrome/browser/extensions/extensions_quota_service.h

Issue 10690113: Moving test_api to api/test . (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding "extensions::" one more Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 ExtensionsQuotaService uses heuristics to limit abusive requests 5 // The ExtensionsQuotaService 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 CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_ 14 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_
15 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_ 15 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_
16 #pragma once 16 #pragma once
17 17
18 #include <list> 18 #include <list>
19 #include <map> 19 #include <map>
20 #include <string> 20 #include <string>
21 21
22 #include "base/compiler_specific.h" 22 #include "base/compiler_specific.h"
23 #include "base/hash_tables.h" 23 #include "base/hash_tables.h"
24 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
25 #include "base/threading/non_thread_safe.h" 25 #include "base/threading/non_thread_safe.h"
26 #include "base/time.h" 26 #include "base/time.h"
27 #include "base/timer.h" 27 #include "base/timer.h"
28 #include "base/values.h" 28 #include "base/values.h"
29 29
30 namespace extensions {
31 class ExtensionTestQuotaResetFunction;
32 } // namespace extensions
Yoyo Zhou 2012/07/10 19:00:11 ditto
vabr (Chromium) 2012/07/11 10:01:25 Done. Also moved the forward decl. after those non
33
30 class ExtensionFunction; 34 class ExtensionFunction;
31 class QuotaLimitHeuristic; 35 class QuotaLimitHeuristic;
32 typedef std::list<QuotaLimitHeuristic*> QuotaLimitHeuristics; 36 typedef std::list<QuotaLimitHeuristic*> QuotaLimitHeuristics;
33 37
34 // The ExtensionsQuotaService takes care that calls to certain extension 38 // The ExtensionsQuotaService takes care that calls to certain extension
35 // functions do not exceed predefined quotas. 39 // functions do not exceed predefined quotas.
36 // 40 //
37 // The ExtensionsQuotaService needs to live entirely on one thread, i.e. 41 // The ExtensionsQuotaService needs to live entirely on one thread, i.e.
38 // be created, called and destroyed on the same thread, due to its use 42 // be created, called and destroyed on the same thread, due to its use
39 // of a RepeatingTimer. 43 // of a RepeatingTimer.
40 class ExtensionsQuotaService : public base::NonThreadSafe { 44 class ExtensionsQuotaService : public base::NonThreadSafe {
41 public: 45 public:
42 // Some concrete heuristics (declared below) that ExtensionFunctions can 46 // Some concrete heuristics (declared below) that ExtensionFunctions can
43 // use to help the service make decisions about quota violations. 47 // use to help the service make decisions about quota violations.
44 class TimedLimit; 48 class TimedLimit;
45 class SustainedLimit; 49 class SustainedLimit;
46 50
47 ExtensionsQuotaService(); 51 ExtensionsQuotaService();
48 virtual ~ExtensionsQuotaService(); 52 virtual ~ExtensionsQuotaService();
49 53
50 // Decide whether the invocation of |function| with argument |args| by the 54 // Decide whether the invocation of |function| with argument |args| by the
51 // extension specified by |extension_id| results in a quota limit violation. 55 // extension specified by |extension_id| results in a quota limit violation.
52 // Returns true if the request is fine and can proceed, false if the request 56 // Returns true if the request is fine and can proceed, false if the request
53 // should be throttled and an error returned to the extension. 57 // should be throttled and an error returned to the extension.
54 bool Assess(const std::string& extension_id, ExtensionFunction* function, 58 bool Assess(const std::string& extension_id, ExtensionFunction* function,
55 const ListValue* args, const base::TimeTicks& event_time); 59 const ListValue* args, const base::TimeTicks& event_time);
56 private: 60 private:
57 friend class ExtensionTestQuotaResetFunction; 61 friend class extensions::ExtensionTestQuotaResetFunction;
58 typedef std::string ExtensionId; 62 typedef std::string ExtensionId;
59 typedef std::string FunctionName; 63 typedef std::string FunctionName;
60 // All QuotaLimitHeuristic instances in this map are owned by us. 64 // All QuotaLimitHeuristic instances in this map are owned by us.
61 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap; 65 typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap;
62 66
63 // Purge resets all accumulated data (except |violators_|) as if the service 67 // Purge resets all accumulated data (except |violators_|) as if the service
64 // was just created. Called periodically so we don't consume an unbounded 68 // was just created. Called periodically so we don't consume an unbounded
65 // amount of memory while tracking quota. Yes, this could mean an extension 69 // amount of memory while tracking quota. Yes, this could mean an extension
66 // gets away with murder if it is timed right, but the extensions we are 70 // gets away with murder if it is timed right, but the extensions we are
67 // trying to limit are ones that consistently violate, so we'll converge 71 // trying to limit are ones that consistently violate, so we'll converge
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 virtual bool Apply(Bucket* bucket, 219 virtual bool Apply(Bucket* bucket,
216 const base::TimeTicks& event_time) OVERRIDE; 220 const base::TimeTicks& event_time) OVERRIDE;
217 private: 221 private:
218 // Specifies how long exhaustion of buckets is allowed to continue before 222 // Specifies how long exhaustion of buckets is allowed to continue before
219 // denying requests. 223 // denying requests.
220 const int64 repeat_exhaustion_allowance_; 224 const int64 repeat_exhaustion_allowance_;
221 int64 num_available_repeat_exhaustions_; 225 int64 num_available_repeat_exhaustions_;
222 }; 226 };
223 227
224 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_ 228 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_QUOTA_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698