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 | 14 |
14 class GURL; | |
15 class Profile; | 15 class Profile; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 enum class PermissionType; | 18 enum class PermissionType; |
19 } // namespace content | 19 } // namespace content |
20 | 20 |
| 21 enum class PermissionSourceUI; |
| 22 |
21 struct PermissionTypeHash { | 23 struct PermissionTypeHash { |
22 std::size_t operator()(const content::PermissionType& type) const; | 24 std::size_t operator()(const content::PermissionType& type) const; |
23 }; | 25 }; |
24 | 26 |
25 // A utility class for permissions. | 27 // A utility class for permissions. |
26 class PermissionUtil { | 28 class PermissionUtil { |
27 public: | 29 public: |
28 // Returns the permission string for the given PermissionType. | 30 // Returns the permission string for the given PermissionType. |
29 static std::string GetPermissionString(content::PermissionType permission); | 31 static std::string GetPermissionString(content::PermissionType permission); |
30 | 32 |
31 // Limited conversion of ContentSettingsType to PermissionType. Intended for | 33 // Limited conversion of ContentSettingsType to PermissionType. Intended for |
32 // recording Permission UMA metrics from areas of the codebase which have not | 34 // recording Permission UMA metrics from areas of the codebase which have not |
33 // yet been converted to PermissionType. Returns true if the conversion was | 35 // yet been converted to PermissionType. Returns true if the conversion was |
34 // performed. | 36 // performed. |
35 // TODO(tsergeant): Remove this function once callsites operate on | 37 // TODO(tsergeant): Remove this function once callsites operate on |
36 // PermissionType directly. | 38 // PermissionType directly. |
37 static bool GetPermissionType(ContentSettingsType type, | 39 static bool GetPermissionType(ContentSettingsType type, |
38 content::PermissionType* out); | 40 content::PermissionType* out); |
39 | 41 |
40 // Helper method which proxies | 42 // A scoped class that will check the current resolved content setting on |
41 // HostContentSettingsMap::SetContentSettingDefaultScope(). Checks the content | 43 // construction and report a revocation metric accordingly if the revocation |
42 // setting value before and after the change to determine whether it has gone | 44 // condition is met (from ALLOW to something else). |
43 // from ALLOW to BLOCK or ASK, and records metrics accordingly. Should be | 45 class ScopedRevocationReporter { |
44 // called from UI code when a user changes permissions for a particular origin | 46 public: |
45 // pair. | 47 ScopedRevocationReporter(Profile* profile, |
46 // TODO(tsergeant): This is a temporary solution to begin gathering metrics. | 48 const GURL& primary_url, |
47 // We should integrate this better with the permissions layer. See | 49 const GURL& secondary_url, |
48 // crbug.com/469221. | 50 ContentSettingsType content_type, |
49 static void SetContentSettingAndRecordRevocation( | 51 PermissionSourceUI source_ui); |
50 Profile* profile, | 52 |
51 const GURL& primary_url, | 53 ~ScopedRevocationReporter(); |
52 const GURL& secondary_url, | 54 |
53 ContentSettingsType content_type, | 55 private: |
54 std::string resource_identifier, | 56 Profile* profile_; |
55 ContentSetting setting); | 57 const GURL primary_url_; |
| 58 const GURL secondary_url_; |
| 59 ContentSettingsType content_type_; |
| 60 PermissionSourceUI source_ui_; |
| 61 bool is_initially_allowed_; |
| 62 }; |
56 | 63 |
57 private: | 64 private: |
58 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); | 65 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); |
59 }; | 66 }; |
60 | 67 |
61 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ | 68 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ |
OLD | NEW |