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

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/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" 10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h"
11 #include "chrome/browser/content_settings/permission_context_uma_util.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
22
23 PermissionContextBase::PermissionContextBase( 23 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 24 Profile* profile,
25 const ContentSettingsType permission_type) 25 const ContentSettingsType permission_type)
26 : profile_(profile), 26 : profile_(profile),
27 permission_type_(permission_type), 27 permission_type_(permission_type),
28 weak_factory_(this) { 28 weak_factory_(this) {
29 permission_queue_controller_.reset( 29 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_)); 30 new PermissionQueueController(profile_, permission_type_));
31 } 31 }
32 32
33 PermissionContextBase::~PermissionContextBase() { 33 PermissionContextBase::~PermissionContextBase() {
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
35 } 35 }
36 36
37 void PermissionContextBase::RequestPermission( 37 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 38 content::WebContents* web_contents,
39 const PermissionRequestID& id, 39 const PermissionRequestID& id,
40 const GURL& requesting_frame, 40 const GURL& requesting_frame,
41 bool user_gesture, 41 bool user_gesture,
42 const BrowserPermissionCallback& callback) { 42 const BrowserPermissionCallback& callback) {
43 // TODO(miguelg): Add UMA instrumentation.
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
45 44
46 DecidePermission(web_contents, 45 DecidePermission(web_contents,
47 id, 46 id,
48 requesting_frame.GetOrigin(), 47 requesting_frame.GetOrigin(),
49 web_contents->GetLastCommittedURL().GetOrigin(), 48 web_contents->GetLastCommittedURL().GetOrigin(),
50 user_gesture, 49 user_gesture,
51 callback); 50 callback);
52 } 51 }
53 52
54 void PermissionContextBase::DecidePermission( 53 void PermissionContextBase::DecidePermission(
55 content::WebContents* web_contents, 54 content::WebContents* web_contents,
56 const PermissionRequestID& id, 55 const PermissionRequestID& id,
57 const GURL& requesting_origin, 56 const GURL& requesting_origin,
58 const GURL& embedder_origin, 57 const GURL& embedder_origin,
59 bool user_gesture, 58 bool user_gesture,
60 const BrowserPermissionCallback& callback) { 59 const BrowserPermissionCallback& callback) {
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 60 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 61
63 ContentSetting content_setting = 62 ContentSetting content_setting =
64 profile_->GetHostContentSettingsMap()->GetContentSetting( 63 profile_->GetHostContentSettingsMap()->GetContentSetting(
65 requesting_origin, embedder_origin, permission_type_, std::string()); 64 requesting_origin, embedder_origin, permission_type_, std::string());
66 switch (content_setting) { 65 switch (content_setting) {
67 case CONTENT_SETTING_BLOCK: 66 case CONTENT_SETTING_BLOCK:
68 PermissionDecided( 67 NotifyPermissionSet(id, requesting_origin, embedder_origin,
69 id, requesting_origin, embedder_origin, callback, false); 68 callback, false /* persist */, false /* granted */);
70 return; 69 return;
71 case CONTENT_SETTING_ALLOW: 70 case CONTENT_SETTING_ALLOW:
72 PermissionDecided(id, requesting_origin, embedder_origin, callback, true); 71 NotifyPermissionSet(id, requesting_origin, embedder_origin,
72 callback, false /* persist */, true /* granted */);
73 return; 73 return;
74 default: 74 default:
75 break; 75 break;
76 } 76 }
77 77
78 PermissionContextUmaUtil::PermissionRequested(permission_type_);
79
78 if (PermissionBubbleManager::Enabled()) { 80 if (PermissionBubbleManager::Enabled()) {
79 PermissionBubbleManager* bubble_manager = 81 PermissionBubbleManager* bubble_manager =
80 PermissionBubbleManager::FromWebContents(web_contents); 82 PermissionBubbleManager::FromWebContents(web_contents);
81 DCHECK(bubble_manager); 83 DCHECK(bubble_manager);
82 scoped_ptr<PermissionBubbleRequest> request_ptr( 84 scoped_ptr<PermissionBubbleRequest> request_ptr(
83 new PermissionBubbleRequestImpl( 85 new PermissionBubbleRequestImpl(
84 requesting_origin, 86 requesting_origin,
85 user_gesture, 87 user_gesture,
86 permission_type_, 88 permission_type_,
87 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 89 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
88 base::Bind(&PermissionContextBase::NotifyPermissionSet, 90 base::Bind(&PermissionContextBase::PermissionDecided,
89 weak_factory_.GetWeakPtr(), 91 weak_factory_.GetWeakPtr(),
90 id, 92 id,
91 requesting_origin, 93 requesting_origin,
92 embedder_origin, 94 embedder_origin,
93 callback), 95 callback),
94 base::Bind(&PermissionContextBase::CleanUpBubble, 96 base::Bind(&PermissionContextBase::CleanUpBubble,
95 weak_factory_.GetWeakPtr(), id))); 97 weak_factory_.GetWeakPtr(), id)));
96 PermissionBubbleRequest* request = request_ptr.get(); 98 PermissionBubbleRequest* request = request_ptr.get();
97 99
98 bool inserted = pending_bubbles_.add( 100 bool inserted = pending_bubbles_.add(
99 id.ToString(), request_ptr.Pass()).second; 101 id.ToString(), request_ptr.Pass()).second;
100 DCHECK(inserted) << "Duplicate id " << id.ToString(); 102 DCHECK(inserted) << "Duplicate id " << id.ToString();
101 bubble_manager->AddRequest(request); 103 bubble_manager->AddRequest(request);
102 return; 104 return;
103 } 105 }
104 106
105 // TODO(gbillock): Delete this and the infobar delegate when 107 // TODO(gbillock): Delete this and the infobar delegate when
106 // we're using only bubbles. crbug.com/337458 108 // we're using only bubbles. crbug.com/337458
107 GetQueueController()->CreateInfoBarRequest( 109 GetQueueController()->CreateInfoBarRequest(
108 id, 110 id,
109 requesting_origin, 111 requesting_origin,
110 embedder_origin, 112 embedder_origin,
111 std::string(), 113 std::string(),
112 base::Bind(&PermissionContextBase::NotifyPermissionSet, 114 base::Bind(&PermissionContextBase::PermissionDecided,
113 weak_factory_.GetWeakPtr(), 115 weak_factory_.GetWeakPtr(),
114 id, 116 id,
115 requesting_origin, 117 requesting_origin,
116 embedder_origin, 118 embedder_origin,
117 callback, 119 callback,
118 // the queue controller takes care of persisting the 120 // the queue controller takes care of persisting the
119 // permission 121 // permission
120 false)); 122 false));
121 } 123 }
122 124
123 void PermissionContextBase::PermissionDecided( 125 void PermissionContextBase::PermissionDecided(
124 const PermissionRequestID& id, 126 const PermissionRequestID& id,
125 const GURL& requesting_origin, 127 const GURL& requesting_origin,
126 const GURL& embedder_origin, 128 const GURL& embedder_origin,
127 const BrowserPermissionCallback& callback, 129 const BrowserPermissionCallback& callback,
130 bool persist,
128 bool allowed) { 131 bool allowed) {
129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 132
133 // Infobar persistance and its related UMA is tracked on the infobar
134 // controller directly.
135 if (PermissionBubbleManager::Enabled()) {
136 if (persist) {
137 if (allowed)
138 PermissionContextUmaUtil::PermissionGranted(permission_type_);
139 else
140 PermissionContextUmaUtil::PermissionDenied(permission_type_);
141 } else {
142 PermissionContextUmaUtil::PermissionDismissed(permission_type_);
143 }
144 }
145
130 NotifyPermissionSet( 146 NotifyPermissionSet(
131 id, requesting_origin, embedder_origin, callback, false, allowed); 147 id, requesting_origin, embedder_origin, callback, persist, allowed);
132 } 148 }
133 149
134 PermissionQueueController* PermissionContextBase::GetQueueController() { 150 PermissionQueueController* PermissionContextBase::GetQueueController() {
135 return permission_queue_controller_.get(); 151 return permission_queue_controller_.get();
136 } 152 }
137 153
138 void PermissionContextBase::NotifyPermissionSet( 154 void PermissionContextBase::NotifyPermissionSet(
139 const PermissionRequestID& id, 155 const PermissionRequestID& id,
140 const GURL& requesting_origin, 156 const GURL& requesting_origin,
141 const GURL& embedder_origin, 157 const GURL& embedder_origin,
(...skipping 21 matching lines...) Expand all
163 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin()); 179 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin());
164 ContentSetting content_setting = 180 ContentSetting content_setting =
165 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 181 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
166 profile_->GetHostContentSettingsMap()->SetContentSetting( 182 profile_->GetHostContentSettingsMap()->SetContentSetting(
167 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 183 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
168 ContentSettingsPattern::FromURLNoWildcard(embedder_origin), 184 ContentSettingsPattern::FromURLNoWildcard(embedder_origin),
169 permission_type_, 185 permission_type_,
170 std::string(), 186 std::string(),
171 content_setting); 187 content_setting);
172 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698