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

Side by Side Diff: chrome/browser/permissions/permission_util.h

Issue 2165733003: Add revocation reporter to permission util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add-source-ui-to-permission-report
Patch Set: merge Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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 13
14 class GURL; 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 RevocationReporter {
44 // called from UI code when a user changes permissions for a particular origin 46 public:
45 // pair. 47 RevocationReporter(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 std::string resource_identifier,
raymes 2016/07/21 23:08:01 nit: do we need to pass this in?
50 Profile* profile, 52 PermissionSourceUI source_ui);
51 const GURL& primary_url, 53
52 const GURL& secondary_url, 54 RevocationReporter(Profile* profile,
53 ContentSettingsType content_type, 55 const ContentSettingsPattern& primary_pattern,
54 std::string resource_identifier, 56 const ContentSettingsPattern& secondary_pattern,
55 ContentSetting setting); 57 ContentSettingsType content_type,
58 std::string resource_identifier,
59 PermissionSourceUI source_ui);
60
61 ~RevocationReporter();
62
63 private:
64 Profile* profile_;
65 const GURL& primary_url_;
66 const GURL& secondary_url_;
67 ContentSettingsType content_type_;
68 const std::string resource_identifier_;
69 PermissionSourceUI source_ui_;
70 bool is_initially_allowed_;
71 };
56 72
57 private: 73 private:
58 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil); 74 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionUtil);
59 }; 75 };
60 76
61 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_ 77 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698