diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 11:08:49 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 11:08:49 +0000 |
commit | 36296919c785e8c549f888996be2fc19f78a049d (patch) | |
tree | ef43b58bdf7c170cbb7fc314d9e3704a4e718eea /chrome/browser/extensions/extensions_quota_service.h | |
parent | 2e2cc84ef9fb8a3724c6387affe927845dbbccce (diff) | |
download | chromium_src-36296919c785e8c549f888996be2fc19f78a049d.zip chromium_src-36296919c785e8c549f888996be2fc19f78a049d.tar.gz chromium_src-36296919c785e8c549f888996be2fc19f78a049d.tar.bz2 |
Fix Threading of ExtensionsQuotaService
The ExtensionsQuotaService uses a RepeatingTimer that is triggered on the thread it was created. With this CL, we ensure that the ExtensionsQuotaService is created, accessed and destroyed on the same thread.
BUG=118655
TEST=no
Review URL: http://codereview.chromium.org/9722022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extensions_quota_service.h')
-rw-r--r-- | chrome/browser/extensions/extensions_quota_service.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extensions_quota_service.h b/chrome/browser/extensions/extensions_quota_service.h index 2f0cab0..6b0ce5d 100644 --- a/chrome/browser/extensions/extensions_quota_service.h +++ b/chrome/browser/extensions/extensions_quota_service.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,6 +22,7 @@ #include "base/compiler_specific.h" #include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" +#include "base/threading/non_thread_safe.h" #include "base/time.h" #include "base/timer.h" #include "base/values.h" @@ -30,7 +31,13 @@ class ExtensionFunction; class QuotaLimitHeuristic; typedef std::list<QuotaLimitHeuristic*> QuotaLimitHeuristics; -class ExtensionsQuotaService { +// The ExtensionsQuotaService takes care that calls to certain extension +// functions do not exceed predefined quotas. +// +// The ExtensionsQuotaService needs to live entirely on one thread, i.e. +// be created, called and destroyed on the same thread, due to its use +// of a RepeatingTimer. +class ExtensionsQuotaService : public base::NonThreadSafe { public: // Some concrete heuristics (declared below) that ExtensionFunctions can // use to help the service make decisions about quota violations. @@ -38,7 +45,7 @@ class ExtensionsQuotaService { class SustainedLimit; ExtensionsQuotaService(); - ~ExtensionsQuotaService(); + virtual ~ExtensionsQuotaService(); // Decide whether the invocation of |function| with argument |args| by the // extension specified by |extension_id| results in a quota limit violation. @@ -48,7 +55,10 @@ class ExtensionsQuotaService { const ListValue* args, const base::TimeTicks& event_time); private: friend class ExtensionTestQuotaResetFunction; - typedef std::map<std::string, QuotaLimitHeuristics> FunctionHeuristicsMap; + typedef std::string ExtensionId; + typedef std::string FunctionName; + // 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 @@ -65,7 +75,7 @@ class ExtensionsQuotaService { // key for the mapping. As an extension invokes functions, the map keeps // track of which functions it has invoked and the heuristics for each one. // Each heuristic will be evaluated and ANDed together to get a final answer. - std::map<std::string, FunctionHeuristicsMap> function_heuristics_; + std::map<ExtensionId, FunctionHeuristicsMap> function_heuristics_; // 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 |