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

Unified Diff: chrome/browser/permissions/permission_decision_auto_blocker.h

Issue 2640033006: Convert AutoBlocker static class to KeyedService. (Closed)
Patch Set: Nits and incognito browser context Created 3 years, 11 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/permissions/permission_decision_auto_blocker.h
diff --git a/chrome/browser/permissions/permission_decision_auto_blocker.h b/chrome/browser/permissions/permission_decision_auto_blocker.h
index a84a5f90d73f79dabc553c18afa44b16b0c171f4..f282b10a3e9d414afecb2579a0771c6d576b0d03 100644
--- a/chrome/browser/permissions/permission_decision_auto_blocker.h
+++ b/chrome/browser/permissions/permission_decision_auto_blocker.h
@@ -8,6 +8,9 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/singleton.h"
+#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/permission_type.h"
#include "url/gurl.h"
@@ -36,69 +39,58 @@ class HostContentSettingsMap;
// result in it being placed under embargo again. Currently, an origin can be
// placed under embargo if it appears on Safe Browsing's API blacklist, or if it
// has a number of prior dismissals greater than a threshold.
-class PermissionDecisionAutoBlocker {
+class PermissionDecisionAutoBlocker : public KeyedService {
public:
- // Removes any recorded counts for urls which match |filter| under |profile|.
- static void RemoveCountsByUrl(Profile* profile,
- base::Callback<bool(const GURL& url)> filter);
+ explicit PermissionDecisionAutoBlocker(Profile* profile);
+ ~PermissionDecisionAutoBlocker() override;
raymes 2017/01/23 06:14:23 You should be able to make the constructor/destrut
meredithl 2017/01/24 01:20:46 Done.
+
+ static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile);
+
+ // Removes any recorded counts for urls which match |filter|.
+ void RemoveCountsByUrl(base::Callback<bool(const GURL& url)> filter);
// Returns the current number of dismisses recorded for |permission| type at
// |url|.
- static int GetDismissCount(const GURL& url,
- content::PermissionType permission,
- Profile* profile);
+ int GetDismissCount(const GURL& url, content::PermissionType permission);
// Returns the current number of ignores recorded for |permission|
// type at |url|.
- static int GetIgnoreCount(const GURL& url,
- content::PermissionType permission,
- Profile* profile);
+ int GetIgnoreCount(const GURL& url, content::PermissionType permission);
// Records that a dismissal of a prompt for |permission| was made. If the
// total number of dismissals exceeds a threshhold and
// features::kBlockPromptsIfDismissedOften is enabled it will place |url|
// under embargo for |permission|.
- static bool RecordDismissAndEmbargo(const GURL& url,
- content::PermissionType permission,
- Profile* profile,
- base::Time current_time);
+ bool RecordDismissAndEmbargo(const GURL& url,
+ content::PermissionType permission,
+ base::Time current_time);
// Records that an ignore of a prompt for |permission| was made.
- static int RecordIgnore(const GURL& url,
- content::PermissionType permission,
- Profile* profile);
-
- // Records that a dismissal of a prompt for |permission| was made, and returns
- // true if this dismissal should be considered a block. False otherwise.
- // TODO(meredithl): Remove in favour of embargoing on repeated dismissals.
- static bool ShouldChangeDismissalToBlock(const GURL& url,
- content::PermissionType permission,
- Profile* profile);
+ int RecordIgnore(const GURL& url, content::PermissionType permission);
// Updates the threshold to start blocking prompts from the field trial.
static void UpdateFromVariations();
// Checks if |request_origin| is under embargo for |permission|. Internally,
// this will make a call to IsUnderEmbargo to check the content setting first,
- // but may also make a call to Safe Browsing to check if |request_origin| is
- // blacklisted for |permission|, which is performed asynchronously.
- static void UpdateEmbargoedStatus(
- scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
- content::PermissionType permission,
- const GURL& request_origin,
- content::WebContents* web_contents,
- int timeout,
- Profile* profile,
- base::Time current_time,
- base::Callback<void(bool)> callback);
+ // but may also make a call to Safe Browsing to check their API blacklist,
raymes 2017/01/23 06:14:23 their->the
meredithl 2017/01/24 01:20:46 Done.
+ // which is performed asynchronously.
+ void UpdateEmbargoedStatus(content::PermissionType permission,
+ const GURL& request_origin,
+ content::WebContents* web_contents,
+ base::Time current_time,
+ base::Callback<void(bool)> callback);
// Checks the status of the content setting to determine if |request_origin|
// is under embargo for |permission|. This checks both embargo for Permissions
// Blacklisting and repeated dismissals.
- static bool IsUnderEmbargo(content::PermissionType permission,
- Profile* profile,
- const GURL& request_origin,
- base::Time current_time);
+ bool IsUnderEmbargo(content::PermissionType permission,
+ const GURL& request_origin,
+ base::Time current_time);
+
+ void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(
+ scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
+ int timeout);
raymes 2017/01/23 06:14:23 nit: this should be private
meredithl 2017/01/24 01:20:46 Done.
private:
friend class PermissionContextBaseTests;
@@ -123,7 +115,31 @@ class PermissionDecisionAutoBlocker {
static const char kPermissionDismissalEmbargoKey[];
static const char kPermissionBlacklistEmbargoKey[];
+ Profile* profile_;
+ int safe_browsing_timeout_;
raymes 2017/01/23 06:14:23 nit: please document the units that the timeout is
meredithl 2017/01/24 01:20:46 Done.
+ scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker);
};
+class PermissionDecisionAutoBlockerFactory
+ : public BrowserContextKeyedServiceFactory {
+ public:
+ static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile);
+ static PermissionDecisionAutoBlockerFactory* GetInstance();
+
+ private:
+ friend struct base::DefaultSingletonTraits<
+ PermissionDecisionAutoBlockerFactory>;
+
+ PermissionDecisionAutoBlockerFactory();
+ ~PermissionDecisionAutoBlockerFactory() override;
+
+ // BrowserContextKeyedServiceFactory
+ KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* context) const override;
+
+ content::BrowserContext* GetBrowserContextToUse(
+ content::BrowserContext* context) const override;
+};
#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_

Powered by Google App Engine
This is Rietveld 408576698