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

Unified Diff: chrome/browser/extensions/extensions_quota_service.h

Issue 10871034: Make all quota-exceeding messages in the storage API explain what the failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update... the other error message Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extensions_quota_service.h
diff --git a/chrome/browser/extensions/extensions_quota_service.h b/chrome/browser/extensions/extensions_quota_service.h
index 6737044c68a98bf73f9e42b4b1535e29123762a8..5c3ce42c377b29bb9c304f15d97562551e19fd83 100644
--- a/chrome/browser/extensions/extensions_quota_service.h
+++ b/chrome/browser/extensions/extensions_quota_service.h
@@ -52,10 +52,13 @@ class ExtensionsQuotaService : public base::NonThreadSafe {
// Decide whether the invocation of |function| with argument |args| by the
// extension specified by |extension_id| results in a quota limit violation.
- // Returns true if the request is fine and can proceed, false if the request
- // should be throttled and an error returned to the extension.
- bool Assess(const std::string& extension_id, ExtensionFunction* function,
- const ListValue* args, const base::TimeTicks& event_time);
+ // Returns an error message representing the failure if quota was exceeded,
+ // or empty-string if the request is fine and can proceed.
+ std::string Assess(const std::string& extension_id,
+ ExtensionFunction* function,
+ const ListValue* args,
+ const base::TimeTicks& event_time);
+
private:
friend class extensions::TestResetQuotaFunction;
typedef std::string ExtensionId;
@@ -63,12 +66,12 @@ class ExtensionsQuotaService : public base::NonThreadSafe {
// All QuotaLimitHeuristic instances in this map are owned by us.
typedef std::map<FunctionName, QuotaLimitHeuristics> FunctionHeuristicsMap;
- // Purge resets all accumulated data (except |violators_|) as if the service
- // was just created. Called periodically so we don't consume an unbounded
- // amount of memory while tracking quota. Yes, this could mean an extension
- // gets away with murder if it is timed right, but the extensions we are
- // trying to limit are ones that consistently violate, so we'll converge
- // to the correct set.
+ // Purge resets all accumulated data (except |violation_errors_|) as if the
+ // service was just created. Called periodically so we don't consume an
+ // unbounded amount of memory while tracking quota. Yes, this could mean an
+ // extension gets away with murder if it is timed right, but the extensions
+ // we are trying to limit are ones that consistently violate, so we'll
+ // converge to the correct set.
void Purge();
void PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map);
base::RepeatingTimer<ExtensionsQuotaService> purge_timer_;
@@ -83,7 +86,8 @@ class ExtensionsQuotaService : public base::NonThreadSafe {
// For now, as soon as an extension violates quota, we don't allow it to
// make any more requests to quota limited functions. This provides a quick
// lookup for these extensions that is only stored in memory.
- base::hash_set<std::string> violators_;
+ typedef std::map<std::string, std::string> ViolationErrorMap;
+ ViolationErrorMap violation_errors_;
DISALLOW_COPY_AND_ASSIGN(ExtensionsQuotaService);
};
@@ -137,9 +141,6 @@ class QuotaLimitHeuristic {
};
typedef std::list<Bucket*> BucketList;
- // A generic error message for quota violating requests.
- static const char kGenericOverQuotaError[];
-
// A helper interface to retrieve the bucket corresponding to |args| from
// the set of buckets (which is typically stored in the BucketMapper itself)
// for this QuotaLimitHeuristic.
@@ -169,8 +170,10 @@ class QuotaLimitHeuristic {
DISALLOW_COPY_AND_ASSIGN(SingletonBucketMapper);
};
- // Ownership of |mapper| is given to the new QuotaLimitHeuristic.
- QuotaLimitHeuristic(const Config& config, BucketMapper* map);
+ // Ownership of |map| is given to the new QuotaLimitHeuristic.
+ QuotaLimitHeuristic(const Config& config,
+ BucketMapper* map,
+ const std::string& name);
virtual ~QuotaLimitHeuristic();
// Determines if sufficient quota exists (according to the Apply
@@ -179,6 +182,9 @@ class QuotaLimitHeuristic {
// is retrieved using the BucketMapper).
bool ApplyToArgs(const ListValue* args, const base::TimeTicks& event_time);
+ // Returns an error formatted according to this heuristic.
+ std::string GetError() const;
+
protected:
const Config& config() { return config_; }
@@ -191,9 +197,12 @@ class QuotaLimitHeuristic {
const Config config_;
- // The mapper used in Map. Cannot be NULL.
+ // The mapper used in Map. Cannot be NULL.
scoped_ptr<BucketMapper> bucket_mapper_;
+ // The name of the heuristic for formatting error messages.
+ std::string name_;
+
DISALLOW_COPY_AND_ASSIGN(QuotaLimitHeuristic);
};
@@ -201,8 +210,8 @@ class QuotaLimitHeuristic {
// a given period of time; e.g "no more than 100 events in an hour".
class ExtensionsQuotaService::TimedLimit : public QuotaLimitHeuristic {
public:
- TimedLimit(const Config& config, BucketMapper* map)
- : QuotaLimitHeuristic(config, map) {}
+ TimedLimit(const Config& config, BucketMapper* map, const std::string& name)
+ : QuotaLimitHeuristic(config, map, name) {}
virtual bool Apply(Bucket* bucket,
const base::TimeTicks& event_time) OVERRIDE;
};
@@ -214,7 +223,8 @@ class ExtensionsQuotaService::SustainedLimit : public QuotaLimitHeuristic {
public:
SustainedLimit(const base::TimeDelta& sustain,
const Config& config,
- BucketMapper* map);
+ BucketMapper* map,
+ const std::string& name);
virtual bool Apply(Bucket* bucket,
const base::TimeTicks& event_time) OVERRIDE;
private:
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.cc ('k') | chrome/browser/extensions/extensions_quota_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698