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

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 13981002: Added UMA_HISTOGRAM_ENUMERATION for RenderViewContextMenu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tab_contents/render_view_context_menu.h" 5 #include "chrome/browser/tab_contents/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 using content::RenderViewHost; 110 using content::RenderViewHost;
111 using content::SSLStatus; 111 using content::SSLStatus;
112 using content::UserMetricsAction; 112 using content::UserMetricsAction;
113 using content::WebContents; 113 using content::WebContents;
114 using extensions::Extension; 114 using extensions::Extension;
115 using extensions::MenuItem; 115 using extensions::MenuItem;
116 using extensions::MenuManager; 116 using extensions::MenuManager;
117 117
118 namespace { 118 namespace {
119 119
120 // Maps UMA enumeration to IDC. IDC could be changed so we can't use
121 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|.
122 static const struct {
Ilya Sherman 2013/04/10 02:22:42 nit: No need for static. You're already in an ano
Vitaly Buka (NO REVIEWS) 2013/04/10 03:34:55 Done.
123 int enum_id;
124 int command_id;
125 } kUmaEnumToCommand[] = {
126 { 0, IDC_CONTENT_CONTEXT_CUSTOM_FIRST },
127 { 1, IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST },
128 { 2, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST },
129 { 3, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB },
130 { 4, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW },
131 { 5, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD },
132 { 6, IDC_CONTENT_CONTEXT_SAVELINKAS },
133 { 7, IDC_CONTENT_CONTEXT_SAVEAVAS },
134 { 8, IDC_CONTENT_CONTEXT_SAVEIMAGEAS },
135 { 9, IDC_CONTENT_CONTEXT_COPYLINKLOCATION },
136 { 10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION },
137 { 11, IDC_CONTENT_CONTEXT_COPYAVLOCATION },
138 { 12, IDC_CONTENT_CONTEXT_COPYIMAGE },
139 { 13, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB },
140 { 14, IDC_CONTENT_CONTEXT_OPENAVNEWTAB },
141 { 15, IDC_CONTENT_CONTEXT_PLAYPAUSE },
142 { 16, IDC_CONTENT_CONTEXT_MUTE },
143 { 17, IDC_CONTENT_CONTEXT_LOOP },
144 { 18, IDC_CONTENT_CONTEXT_CONTROLS },
145 { 19, IDC_CONTENT_CONTEXT_ROTATECW },
146 { 20, IDC_CONTENT_CONTEXT_ROTATECCW },
147 { 21, IDC_BACK },
148 { 22, IDC_FORWARD },
149 { 23, IDC_SAVE_PAGE },
150 { 24, IDC_RELOAD },
151 { 25, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP },
152 { 26, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP },
153 { 27, IDC_PRINT },
154 { 28, IDC_VIEW_SOURCE },
155 { 29, IDC_CONTENT_CONTEXT_INSPECTELEMENT },
156 { 30, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE },
157 { 31, IDC_CONTENT_CONTEXT_VIEWPAGEINFO },
158 { 32, IDC_CONTENT_CONTEXT_TRANSLATE },
159 { 33, IDC_CONTENT_CONTEXT_RELOADFRAME },
160 { 34, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE },
161 { 35, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO },
162 { 36, IDC_CONTENT_CONTEXT_UNDO },
163 { 37, IDC_CONTENT_CONTEXT_REDO },
164 { 38, IDC_CONTENT_CONTEXT_CUT },
165 { 39, IDC_CONTENT_CONTEXT_COPY },
166 { 40, IDC_CONTENT_CONTEXT_PASTE },
Vitaly Buka (NO REVIEWS) 2013/04/10 02:50:00 Ilya, I assume it's OK to extend enum in new versi
Ilya Sherman 2013/04/10 02:51:43 Yes, it's safe to extend the enum in new versions
167 { 41, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE },
168 { 42, IDC_CONTENT_CONTEXT_DELETE },
169 { 43, IDC_CONTENT_CONTEXT_SELECTALL },
170 { 44, IDC_CONTENT_CONTEXT_SEARCHWEBFOR },
171 { 45, IDC_CONTENT_CONTEXT_GOTOURL },
172 { 46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS },
173 { 47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS },
174 { 48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE },
175 { 49, IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES },
176 { 50, IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT },
177 };
178
179 int GetEnumerationBoundaryValue() {
Ilya Sherman 2013/04/10 02:22:42 nit: Docs.
Lei Zhang 2013/04/10 02:49:57 If you never delete from |kUmaEnumToCommand|, then
Vitaly Buka (NO REVIEWS) 2013/04/10 03:34:55 IDC_ constants can be deleted in future. Otherwise
180 int bounadary_value = 0;
181 for (size_t i = 0; i < arraysize(kUmaEnumToCommand); ++i) {
182 bounadary_value = std::max(bounadary_value, kUmaEnumToCommand[i].enum_id);
183 }
184 return bounadary_value + 1;
185 }
186
187 void RecordExecutedContextItem(int id) {
Ilya Sherman 2013/04/10 02:22:42 nit: Docs.
Vitaly Buka (NO REVIEWS) 2013/04/10 03:34:55 Done.
188 // Collapse large ranges of ids.
189 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
190 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) {
191 id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST;
192 } else if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
193 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
194 id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
195 } else if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
196 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
197 id = IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
198 }
199
200 for (size_t i = 0; i < arraysize(kUmaEnumToCommand); ++i) {
201 if (kUmaEnumToCommand[i].command_id == id) {
202 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.ExecuteCommand",
203 kUmaEnumToCommand[i].enum_id,
204 GetEnumerationBoundaryValue());
205 return;
206 }
207 }
208 NOTREACHED();
209 }
210
120 // Usually a new tab is expected where this function is used, 211 // Usually a new tab is expected where this function is used,
121 // however users should be able to open a tab in background 212 // however users should be able to open a tab in background
122 // or in a new window. 213 // or in a new window.
123 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( 214 WindowOpenDisposition ForceNewTabDispositionFromEventFlags(
124 int event_flags) { 215 int event_flags) {
125 WindowOpenDisposition disposition = 216 WindowOpenDisposition disposition =
126 ui::DispositionFromEventFlags(event_flags); 217 ui::DispositionFromEventFlags(event_flags);
127 return disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition; 218 return disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition;
128 } 219 }
129 220
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { 1421 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
1331 // If this command is is added by one of our observers, we dispatch it to the 1422 // If this command is is added by one of our observers, we dispatch it to the
1332 // observer. 1423 // observer.
1333 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); 1424 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_);
1334 RenderViewContextMenuObserver* observer; 1425 RenderViewContextMenuObserver* observer;
1335 while ((observer = it.GetNext()) != NULL) { 1426 while ((observer = it.GetNext()) != NULL) {
1336 if (observer->IsCommandIdSupported(id)) 1427 if (observer->IsCommandIdSupported(id))
1337 return observer->ExecuteCommand(id); 1428 return observer->ExecuteCommand(id);
1338 } 1429 }
1339 1430
1431 RecordExecutedContextItem(id);
1432
1340 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); 1433 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost();
1341 1434
1342 // Process custom actions range. 1435 // Process custom actions range.
1343 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && 1436 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
1344 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { 1437 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) {
1345 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; 1438 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST;
1346 const content::CustomContextMenuContext& context = params_.custom_context; 1439 const content::CustomContextMenuContext& context = params_.custom_context;
1347 #if defined(ENABLE_PLUGINS) 1440 #if defined(ENABLE_PLUGINS)
1348 if (context.request_id && !context.is_pepper_menu) { 1441 if (context.request_id && !context.is_pepper_menu) {
1349 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( 1442 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 source_web_contents_->GetRenderViewHost()-> 1985 source_web_contents_->GetRenderViewHost()->
1893 ExecuteMediaPlayerActionAtLocation(location, action); 1986 ExecuteMediaPlayerActionAtLocation(location, action);
1894 } 1987 }
1895 1988
1896 void RenderViewContextMenu::PluginActionAt( 1989 void RenderViewContextMenu::PluginActionAt(
1897 const gfx::Point& location, 1990 const gfx::Point& location,
1898 const WebPluginAction& action) { 1991 const WebPluginAction& action) {
1899 source_web_contents_->GetRenderViewHost()-> 1992 source_web_contents_->GetRenderViewHost()->
1900 ExecutePluginActionAtLocation(location, action); 1993 ExecutePluginActionAtLocation(location, action);
1901 } 1994 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698