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

Side by Side Diff: chrome/browser/content_settings/permission_context_base.cc

Issue 371933002: Add UMA for the new generic permisison class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/content_settings/permission_context_base.h" 5 #include "chrome/browser/content_settings/permission_context_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" 11 #include "chrome/browser/content_settings/permission_bubble_request_impl.h"
11 #include "chrome/browser/content_settings/permission_queue_controller.h" 12 #include "chrome/browser/content_settings/permission_queue_controller.h"
12 #include "chrome/browser/content_settings/permission_request_id.h" 13 #include "chrome/browser/content_settings/permission_request_id.h"
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
21 22
23 namespace {
24
25 // Helper function for UMA tracking purposes.
26 static PermissionType SettingToPermission(ContentSettingsType permission) {
Bernhard Bauer 2014/07/08 14:51:05 Static is not necessary here.
Miguel Garcia 2014/07/08 15:37:44 Done.
27 switch (permission) {
28 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
29 return PERMISSION_MIDI_SYSEX;
30 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
31 return PERMISSION_PUSH_MESSAGING;
32 default:
33 NOTREACHED() << "PERMISSION " << permission << " not accounted for";
34 }
35 return PERMISSION_UNKNOWN;
36 }
37
38 } // namespace
22 39
23 PermissionContextBase::PermissionContextBase( 40 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 41 Profile* profile,
25 const ContentSettingsType permission_type) 42 const ContentSettingsType permission_type)
26 : profile_(profile), 43 : profile_(profile),
27 permission_type_(permission_type), 44 permission_type_(permission_type),
28 weak_factory_(this) { 45 weak_factory_(this) {
29 permission_queue_controller_.reset( 46 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_)); 47 new PermissionQueueController(profile_, permission_type_));
31 } 48 }
32 49
33 PermissionContextBase::~PermissionContextBase() { 50 PermissionContextBase::~PermissionContextBase() {
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 } 52 }
36 53
37 void PermissionContextBase::RequestPermission( 54 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 55 content::WebContents* web_contents,
39 const PermissionRequestID& id, 56 const PermissionRequestID& id,
40 const GURL& requesting_frame, 57 const GURL& requesting_frame,
41 bool user_gesture, 58 bool user_gesture,
42 const BrowserPermissionCallback& callback) { 59 const BrowserPermissionCallback& callback) {
43 // TODO(miguelg): Add UMA instrumentation.
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 60 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
45 61
46 DecidePermission(web_contents, 62 DecidePermission(web_contents,
47 id, 63 id,
48 requesting_frame.GetOrigin(), 64 requesting_frame.GetOrigin(),
49 web_contents->GetLastCommittedURL().GetOrigin(), 65 web_contents->GetLastCommittedURL().GetOrigin(),
50 user_gesture, 66 user_gesture,
51 callback); 67 callback);
52 } 68 }
53 69
54 void PermissionContextBase::DecidePermission( 70 void PermissionContextBase::DecidePermission(
55 content::WebContents* web_contents, 71 content::WebContents* web_contents,
56 const PermissionRequestID& id, 72 const PermissionRequestID& id,
57 const GURL& requesting_origin, 73 const GURL& requesting_origin,
58 const GURL& embedder_origin, 74 const GURL& embedder_origin,
59 bool user_gesture, 75 bool user_gesture,
60 const BrowserPermissionCallback& callback) { 76 const BrowserPermissionCallback& callback) {
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 78
63 ContentSetting content_setting = 79 ContentSetting content_setting =
64 profile_->GetHostContentSettingsMap()->GetContentSetting( 80 profile_->GetHostContentSettingsMap()->GetContentSetting(
65 requesting_origin, embedder_origin, permission_type_, std::string()); 81 requesting_origin, embedder_origin, permission_type_, std::string());
66 switch (content_setting) { 82 switch (content_setting) {
67 case CONTENT_SETTING_BLOCK: 83 case CONTENT_SETTING_BLOCK:
68 PermissionDecided( 84 NotifyPermissionSet(id, requesting_origin, embedder_origin,
69 id, requesting_origin, embedder_origin, callback, false); 85 callback, false /* persist */, false /* granted */);
70 return; 86 return;
71 case CONTENT_SETTING_ALLOW: 87 case CONTENT_SETTING_ALLOW:
72 PermissionDecided(id, requesting_origin, embedder_origin, callback, true); 88 NotifyPermissionSet(id, requesting_origin, embedder_origin,
89 callback, false /* persist */, true /* granted */);
73 return; 90 return;
74 default: 91 default:
75 break; 92 break;
76 } 93 }
77 94
95 UMA_HISTOGRAM_ENUMERATION("ContentSettings.PermissionRequested",
96 SettingToPermission(permission_type_),
97 PERMISSION_NUM);
98
78 if (PermissionBubbleManager::Enabled()) { 99 if (PermissionBubbleManager::Enabled()) {
79 PermissionBubbleManager* bubble_manager = 100 PermissionBubbleManager* bubble_manager =
80 PermissionBubbleManager::FromWebContents(web_contents); 101 PermissionBubbleManager::FromWebContents(web_contents);
81 DCHECK(bubble_manager); 102 DCHECK(bubble_manager);
82 scoped_ptr<PermissionBubbleRequest> request_ptr( 103 scoped_ptr<PermissionBubbleRequest> request_ptr(
83 new PermissionBubbleRequestImpl( 104 new PermissionBubbleRequestImpl(
84 requesting_origin, 105 requesting_origin,
85 user_gesture, 106 user_gesture,
86 permission_type_, 107 permission_type_,
87 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 108 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
88 base::Bind(&PermissionContextBase::NotifyPermissionSet, 109 base::Bind(&PermissionContextBase::PermissionDecided,
89 weak_factory_.GetWeakPtr(), 110 weak_factory_.GetWeakPtr(),
90 id, 111 id,
91 requesting_origin, 112 requesting_origin,
92 embedder_origin, 113 embedder_origin,
93 callback), 114 callback),
94 base::Bind(&PermissionContextBase::CleanUpBubble, 115 base::Bind(&PermissionContextBase::CleanUpBubble,
95 weak_factory_.GetWeakPtr(), id))); 116 weak_factory_.GetWeakPtr(), id)));
96 PermissionBubbleRequest* request = request_ptr.get(); 117 PermissionBubbleRequest* request = request_ptr.get();
97 118
98 bool inserted = pending_bubbles_.add( 119 bool inserted = pending_bubbles_.add(
99 id.ToString(), request_ptr.Pass()).second; 120 id.ToString(), request_ptr.Pass()).second;
100 DCHECK(inserted) << "Duplicate id " << id.ToString(); 121 DCHECK(inserted) << "Duplicate id " << id.ToString();
101 bubble_manager->AddRequest(request); 122 bubble_manager->AddRequest(request);
102 return; 123 return;
103 } 124 }
104 125
105 // TODO(gbillock): Delete this and the infobar delegate when 126 // TODO(gbillock): Delete this and the infobar delegate when
106 // we're using only bubbles. crbug.com/337458 127 // we're using only bubbles. crbug.com/337458
107 GetQueueController()->CreateInfoBarRequest( 128 GetQueueController()->CreateInfoBarRequest(
108 id, 129 id,
109 requesting_origin, 130 requesting_origin,
110 embedder_origin, 131 embedder_origin,
111 std::string(), 132 std::string(),
112 base::Bind(&PermissionContextBase::NotifyPermissionSet, 133 base::Bind(&PermissionContextBase::PermissionDecided,
113 weak_factory_.GetWeakPtr(), 134 weak_factory_.GetWeakPtr(),
114 id, 135 id,
115 requesting_origin, 136 requesting_origin,
116 embedder_origin, 137 embedder_origin,
117 callback, 138 callback,
118 // the queue controller takes care of persisting the 139 // the queue controller takes care of persisting the
119 // permission 140 // permission
120 false)); 141 false));
121 } 142 }
122 143
123 void PermissionContextBase::PermissionDecided( 144 void PermissionContextBase::PermissionDecided(
124 const PermissionRequestID& id, 145 const PermissionRequestID& id,
125 const GURL& requesting_origin, 146 const GURL& requesting_origin,
126 const GURL& embedder_origin, 147 const GURL& embedder_origin,
127 const BrowserPermissionCallback& callback, 148 const BrowserPermissionCallback& callback,
149 bool persist,
128 bool allowed) { 150 bool allowed) {
129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 151 if (allowed) {
152 UMA_HISTOGRAM_ENUMERATION("ContentSettings.PermissionGranted",
153 SettingToPermission(permission_type_),
154 PERMISSION_NUM);
155 } else {
156 UMA_HISTOGRAM_ENUMERATION("ContentSettings.PermissionDenied",
157 SettingToPermission(permission_type_),
158 PERMISSION_NUM);
159 }
160
130 NotifyPermissionSet( 161 NotifyPermissionSet(
131 id, requesting_origin, embedder_origin, callback, false, allowed); 162 id, requesting_origin, embedder_origin, callback, persist, allowed);
132 } 163 }
133 164
134 PermissionQueueController* PermissionContextBase::GetQueueController() { 165 PermissionQueueController* PermissionContextBase::GetQueueController() {
135 return permission_queue_controller_.get(); 166 return permission_queue_controller_.get();
136 } 167 }
137 168
138 void PermissionContextBase::NotifyPermissionSet( 169 void PermissionContextBase::NotifyPermissionSet(
139 const PermissionRequestID& id, 170 const PermissionRequestID& id,
140 const GURL& requesting_origin, 171 const GURL& requesting_origin,
141 const GURL& embedder_origin, 172 const GURL& embedder_origin,
(...skipping 21 matching lines...) Expand all
163 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin()); 194 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin());
164 ContentSetting content_setting = 195 ContentSetting content_setting =
165 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 196 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
166 profile_->GetHostContentSettingsMap()->SetContentSetting( 197 profile_->GetHostContentSettingsMap()->SetContentSetting(
167 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 198 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
168 ContentSettingsPattern::FromURLNoWildcard(embedder_origin), 199 ContentSettingsPattern::FromURLNoWildcard(embedder_origin),
169 permission_type_, 200 permission_type_,
170 std::string(), 201 std::string(),
171 content_setting); 202 content_setting);
172 } 203 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/permission_context_base.h ('k') | chrome/browser/ui/webui/options/content_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698