| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 class GURL; | 13 class GURL; |
| 14 class Profile; | 14 class Profile; |
| 15 | 15 |
| 16 class PermissionDecisionAutoBlocker { | 16 class PermissionDecisionAutoBlocker { |
| 17 public: | 17 public: |
| 18 // Removes any recorded counts for urls which match |filter| under |profile|. | 18 // Removes any recorded counts for urls which match |filter| under |profile|. |
| 19 static void RemoveCountsByUrl(Profile* profile, | 19 static void RemoveCountsByUrl(Profile* profile, |
| 20 base::Callback<bool(const GURL& url)> filter); | 20 base::Callback<bool(const GURL& url)> filter); |
| 21 | 21 |
| 22 // Returns the current number of dismisses recorded for |permission| |
| 23 // type at |url|. |
| 24 static int GetDismissCount(const GURL& url, |
| 25 content::PermissionType permission, |
| 26 Profile* profile); |
| 27 |
| 28 // Returns the current number of ignores recorded for |permission| |
| 29 // type at |url|. |
| 30 static int GetIgnoreCount(const GURL& url, |
| 31 content::PermissionType permission, |
| 32 Profile* profile); |
| 33 |
| 22 explicit PermissionDecisionAutoBlocker(Profile* profile); | 34 explicit PermissionDecisionAutoBlocker(Profile* profile); |
| 23 | 35 |
| 24 // Records that an ignore of a prompt for |permission| was made. | 36 // Records that an ignore of a prompt for |permission| was made. |
| 25 int RecordIgnore(const GURL& url, content::PermissionType permission); | 37 int RecordIgnore(const GURL& url, content::PermissionType permission); |
| 26 | 38 |
| 27 // Records that a dismissal of a prompt for |permission| was made, and returns | 39 // Records that a dismissal of a prompt for |permission| was made, and returns |
| 28 // true if this dismissal should be considered a block. False otherwise. | 40 // true if this dismissal should be considered a block. False otherwise. |
| 29 bool ShouldChangeDismissalToBlock(const GURL& url, | 41 bool ShouldChangeDismissalToBlock(const GURL& url, |
| 30 content::PermissionType permission); | 42 content::PermissionType permission); |
| 31 | 43 |
| 32 private: | 44 private: |
| 33 friend class PermissionContextBaseTests; | 45 friend class PermissionContextBaseTests; |
| 34 friend class PermissionDecisionAutoBlockerUnitTest; | |
| 35 friend class RemovePermissionPromptCountsTest; | |
| 36 | 46 |
| 37 // Keys used for storing count data in a website setting. | 47 // Keys used for storing count data in a website setting. |
| 38 static const char kPromptDismissCountKey[]; | 48 static const char kPromptDismissCountKey[]; |
| 39 static const char kPromptIgnoreCountKey[]; | 49 static const char kPromptIgnoreCountKey[]; |
| 40 | 50 |
| 41 // Returns the current number of actions recorded under |key| for |permission| | 51 // Returns the current number of actions recorded under |key| for |permission| |
| 42 // type at |url|. | 52 // type at |url|. |
| 43 int GetActionCountForTest(const GURL& url, | 53 static int GetActionCount(const GURL& url, |
| 44 content::PermissionType permission, | 54 content::PermissionType permission, |
| 45 const char* key); | 55 const char* key, |
| 56 Profile* profile); |
| 46 | 57 |
| 47 // Records that the user performed an action for a prompt of type |permission| | 58 // Records that the user performed an action for a prompt of type |permission| |
| 48 // on |url| to a website setting keyed by |key|. Returns the total number of | 59 // on |url| to a website setting keyed by |key|. Returns the total number of |
| 49 // |key| actions which have been performed for |url|. | 60 // |key| actions which have been performed for |url|. |
| 50 int RecordActionInWebsiteSettings(const GURL& url, | 61 int RecordActionInWebsiteSettings(const GURL& url, |
| 51 content::PermissionType permission, | 62 content::PermissionType permission, |
| 52 const char* key); | 63 const char* key); |
| 53 | 64 |
| 54 // Updates |prompt_dismissals_before_block_|. | 65 // Updates |prompt_dismissals_before_block_|. |
| 55 void UpdateFromVariations(); | 66 void UpdateFromVariations(); |
| 56 | 67 |
| 57 Profile *profile_; | 68 Profile *profile_; |
| 58 int prompt_dismissals_before_block_; | 69 int prompt_dismissals_before_block_; |
| 59 }; | 70 }; |
| 60 | 71 |
| 61 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 72 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| OLD | NEW |