| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_UTIL_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/content_settings/core/common/content_settings.h" | 11 #include "components/content_settings/core/common/content_settings.h" |
| 12 #include "components/content_settings/core/common/content_settings_types.h" | 12 #include "components/content_settings/core/common/content_settings_types.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 class HostContentSettingsMap; |
| 15 class Profile; | 16 class Profile; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 enum class PermissionType; | 19 enum class PermissionType; |
| 19 } // namespace content | 20 } // namespace content |
| 20 | 21 |
| 21 enum class PermissionSourceUI; | 22 enum class PermissionSourceUI; |
| 22 | 23 |
| 23 struct PermissionTypeHash { | 24 struct PermissionTypeHash { |
| 24 std::size_t operator()(const content::PermissionType& type) const; | 25 std::size_t operator()(const content::PermissionType& type) const; |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 // A utility class for permissions. | 28 // A utility class for permissions. |
| 28 class PermissionUtil { | 29 class PermissionUtil { |
| 29 public: | 30 public: |
| 30 // Returns the permission string for the given PermissionType. | 31 // Returns the permission string for the given PermissionType. |
| 31 static std::string GetPermissionString(content::PermissionType permission); | 32 static std::string GetPermissionString(content::PermissionType permission); |
| 32 | 33 |
| 33 // Limited conversion of ContentSettingsType to PermissionType. Intended for | 34 // Limited conversion of ContentSettingsType to PermissionType. Intended for |
| 34 // recording Permission UMA metrics from areas of the codebase which have not | 35 // recording Permission UMA metrics from areas of the codebase which have not |
| 35 // yet been converted to PermissionType. Returns true if the conversion was | 36 // yet been converted to PermissionType. Returns true if the conversion was |
| 36 // performed. | 37 // performed. |
| 37 // TODO(tsergeant): Remove this function once callsites operate on | 38 // TODO(tsergeant): Remove this function once callsites operate on |
| 38 // PermissionType directly. | 39 // PermissionType directly. |
| 39 static bool GetPermissionType(ContentSettingsType type, | 40 static bool GetPermissionType(ContentSettingsType type, |
| 40 content::PermissionType* out); | 41 content::PermissionType* out); |
| 41 | 42 |
| 42 // A scoped class that will check the current resolved content setting on | 43 // A scoped class that will check the current resolved content setting on |
| 43 // construction and report a revocation metric accordingly if the revocation | 44 // construction and report a revocation metric accordingly if the revocation |
| 44 // condition is met (from ALLOW to something else). | 45 // condition is met (from ALLOW to something else). By default, |
| 46 // |settings_map_| is obtained from |profile_|, but it can be changed with the |
| 47 // setter if necessary. |
| 45 class ScopedRevocationReporter { | 48 class ScopedRevocationReporter { |
| 46 public: | 49 public: |
| 47 ScopedRevocationReporter(Profile* profile, | 50 ScopedRevocationReporter(Profile* profile, |
| 48 const GURL& primary_url, | 51 const GURL& primary_url, |
| 49 const GURL& secondary_url, | 52 const GURL& secondary_url, |
| 50 ContentSettingsType content_type, | 53 ContentSettingsType content_type, |
| 51 PermissionSourceUI source_ui); | 54 PermissionSourceUI source_ui); |
| 52 | 55 |
| 56 ScopedRevocationReporter(Profile* profile, |
| 57 const ContentSettingsPattern& primary_pattern, |
| 58 const ContentSettingsPattern& secondary_pattern, |
| 59 ContentSettingsType content_type, |
| 60 PermissionSourceUI source_ui); |
| 61 |
| 62 void SetCustomSettingsMap(HostContentSettingsMap* settings_map); |
| 63 |
| 53 ~ScopedRevocationReporter(); | 64 ~ScopedRevocationReporter(); |
| 54 | 65 |
| 55 private: | 66 private: |
| 56 Profile* profile_; | 67 Profile* profile_; |
| 68 HostContentSettingsMap* settings_map_; |
| 57 const GURL primary_url_; | 69 const GURL primary_url_; |
| 58 const GURL secondary_url_; | 70 const GURL secondary_url_; |
| 59 ContentSettingsType content_type_; | 71 ContentSettingsType content_type_; |
| 60 PermissionSourceUI source_ui_; | 72 PermissionSourceUI source_ui_; |
| 61 bool is_initially_allowed_; | 73 bool is_initially_allowed_; |
| 62 }; | 74 }; |
| 63 | 75 |
| 64 private: | 76 private: |
| 65 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); | 77 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); |
| 66 }; | 78 }; |
| 67 | 79 |
| 68 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ | 80 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ |
| OLD | NEW |