| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 DISMISSED = 2, | 28 DISMISSED = 2, |
| 29 IGNORED = 3, | 29 IGNORED = 3, |
| 30 REVOKED = 4, | 30 REVOKED = 4, |
| 31 REENABLED = 5, | 31 REENABLED = 5, |
| 32 REQUESTED = 6, | 32 REQUESTED = 6, |
| 33 | 33 |
| 34 // Always keep this at the end. | 34 // Always keep this at the end. |
| 35 PERMISSION_ACTION_NUM, | 35 PERMISSION_ACTION_NUM, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 struct PermissionTypeHash { | |
| 39 std::size_t operator()(const content::PermissionType& type) const; | |
| 40 }; | |
| 41 | |
| 42 // A utility class for permissions. | 38 // A utility class for permissions. |
| 43 class PermissionUtil { | 39 class PermissionUtil { |
| 44 public: | 40 public: |
| 45 // Returns the permission string for the given PermissionType. | 41 // Returns the permission string for the given permission. |
| 46 static std::string GetPermissionString(content::PermissionType permission); | 42 static std::string GetPermissionString(ContentSettingsType); |
| 43 // TODO(timloh): Remove this content::PermissionType overload when we add MIDI |
| 44 // to ContentSettingsType. |
| 45 static std::string GetPermissionString(content::PermissionType); |
| 47 | 46 |
| 48 // Return the stringified version of the PermissionType enum that Safe | 47 // Return the stringified version of the ContentSettingsType enum that |
| 49 // Browsing uses for the API Blacklist. | 48 // Safe Browsing uses for the API Blacklist. |
| 50 static std::string ConvertPermissionTypeToSafeBrowsingName( | 49 static std::string ConvertContentSettingsTypeToSafeBrowsingName( |
| 51 const content::PermissionType& permission_type); | 50 ContentSettingsType permission); |
| 52 | 51 |
| 53 // Returns the request type corresponding to a permission type. | 52 // Returns the request type corresponding to a permission type. |
| 54 static PermissionRequestType GetRequestType(content::PermissionType type); | 53 static PermissionRequestType GetRequestType(ContentSettingsType permission); |
| 55 | 54 |
| 56 // Returns the gesture type corresponding to whether a permission request is | 55 // Returns the gesture type corresponding to whether a permission request is |
| 57 // made with or without a user gesture. | 56 // made with or without a user gesture. |
| 58 static PermissionRequestGestureType GetGestureType(bool user_gesture); | 57 static PermissionRequestGestureType GetGestureType(bool user_gesture); |
| 59 | 58 |
| 60 // Limited conversion of ContentSettingsType to PermissionType. Intended for | 59 // Limited conversion of ContentSettingsType to PermissionType. Returns true |
| 61 // recording Permission UMA metrics from areas of the codebase which have not | 60 // if the conversion was performed. |
| 62 // yet been converted to PermissionType. Returns true if the conversion was | 61 // TODO(timloh): Try to remove this function. Mainly we need to work out how |
| 63 // performed. | 62 // to remove the usage in PermissionUmaUtil, which uses PermissionType as a |
| 64 // TODO(tsergeant): Remove this function once callsites operate on | 63 // histogram value to count permission request metrics. |
| 65 // PermissionType directly. | |
| 66 static bool GetPermissionType(ContentSettingsType type, | 64 static bool GetPermissionType(ContentSettingsType type, |
| 67 content::PermissionType* out); | 65 content::PermissionType* out); |
| 68 | 66 |
| 69 static bool ShouldShowPersistenceToggle(); | 67 static bool ShouldShowPersistenceToggle(); |
| 70 | 68 |
| 71 // A scoped class that will check the current resolved content setting on | 69 // A scoped class that will check the current resolved content setting on |
| 72 // construction and report a revocation metric accordingly if the revocation | 70 // construction and report a revocation metric accordingly if the revocation |
| 73 // condition is met (from ALLOW to something else). | 71 // condition is met (from ALLOW to something else). |
| 74 class ScopedRevocationReporter { | 72 class ScopedRevocationReporter { |
| 75 public: | 73 public: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 ContentSettingsType content_type_; | 92 ContentSettingsType content_type_; |
| 95 PermissionSourceUI source_ui_; | 93 PermissionSourceUI source_ui_; |
| 96 bool is_initially_allowed_; | 94 bool is_initially_allowed_; |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 private: | 97 private: |
| 100 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); | 98 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); |
| 101 }; | 99 }; |
| 102 | 100 |
| 103 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ | 101 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ |
| OLD | NEW |