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

Side by Side Diff: chrome/browser/ui/toolbar/wrench_menu_model.cc

Issue 700673003: Add metrics to all items in the 'wrench' menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved comments, added histogram suffixes Created 6 years, 1 month 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 (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/ui/toolbar/wrench_menu_model.h" 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/histogram.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/defaults.h" 18 #include "chrome/browser/defaults.h"
18 #include "chrome/browser/extensions/extension_toolbar_model.h" 19 #include "chrome/browser/extensions/extension_toolbar_model.h"
19 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED); 270 AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED);
270 #endif 271 #endif
271 } 272 }
272 273
273 //////////////////////////////////////////////////////////////////////////////// 274 ////////////////////////////////////////////////////////////////////////////////
274 // WrenchMenuModel 275 // WrenchMenuModel
275 276
276 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, 277 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider,
277 Browser* browser) 278 Browser* browser)
278 : ui::SimpleMenuModel(this), 279 : ui::SimpleMenuModel(this),
280 uma_action_recorded_(false),
279 provider_(provider), 281 provider_(provider),
280 browser_(browser), 282 browser_(browser),
281 tab_strip_model_(browser_->tab_strip_model()) { 283 tab_strip_model_(browser_->tab_strip_model()) {
282 Build(); 284 Build();
283 UpdateZoomControls(); 285 UpdateZoomControls();
284 286
285 content_zoom_subscription_ = 287 content_zoom_subscription_ =
286 content::HostZoomMap::GetDefaultForBrowserContext(browser->profile()) 288 content::HostZoomMap::GetDefaultForBrowserContext(browser->profile())
287 ->AddZoomLevelChangedCallback(base::Bind( 289 ->AddZoomLevelChangedCallback(base::Bind(
288 &WrenchMenuModel::OnZoomLevelChanged, base::Unretained(this))); 290 &WrenchMenuModel::OnZoomLevelChanged, base::Unretained(this)));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN) { 399 if (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN) {
398 // If a custom error message is being shown, handle it. 400 // If a custom error message is being shown, handle it.
399 GlobalError* error = signin_ui_util::GetSignedInServiceError( 401 GlobalError* error = signin_ui_util::GetSignedInServiceError(
400 browser_->profile()->GetOriginalProfile()); 402 browser_->profile()->GetOriginalProfile());
401 if (error) { 403 if (error) {
402 error->ExecuteMenuItem(browser_); 404 error->ExecuteMenuItem(browser_);
403 return; 405 return;
404 } 406 }
405 } 407 }
406 408
407 if (command_id == IDC_HELP_PAGE_VIA_MENU) 409 LogMenuMetrics(command_id);
408 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu"));
409
410 if (command_id == IDC_FULLSCREEN) {
411 // We issue the UMA command here and not in BrowserCommandController or even
412 // FullscreenController since we want to be able to distinguish this event
413 // and a menu which is under development.
414 content::RecordAction(UserMetricsAction("EnterFullScreenWithWrenchMenu"));
415 }
416
417 chrome::ExecuteCommand(browser_, command_id); 410 chrome::ExecuteCommand(browser_, command_id);
418 } 411 }
419 412
413 void WrenchMenuModel::LogMenuMetrics(int command_id) {
414 base::TimeDelta now = timer_.Elapsed();
Alexei Svitkine (slow) 2014/11/17 18:51:18 Nit: Use a different name - |now| implies it's a t
edwardjung 2014/11/17 19:18:56 Done.
415
416 switch (command_id) {
417 case IDC_NEW_TAB:
418 if (!uma_action_recorded_)
419 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_NewTab", now);
420 LogMenuAction(MENU_ACTION_NEW_TAB);
421 break;
422 case IDC_NEW_WINDOW:
423 if (!uma_action_recorded_)
424 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_NewWindow", now);
425 LogMenuAction(MENU_ACTION_NEW_WINDOW);
426 break;
427 case IDC_NEW_INCOGNITO_WINDOW:
428 if (!uma_action_recorded_)
Alexei Svitkine (slow) 2014/11/17 18:51:18 Nit: {}'s because body is multiline. Same for othe
edwardjung 2014/11/17 19:18:56 This is actually single line. We still want to rec
Alexei Svitkine (slow) 2014/11/17 19:57:04 The style guide is not about number of statements,
edwardjung 2014/11/17 23:45:26 My bad, still getting used to the C++ style guide.
429 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_NewIncognitoWindow",
430 now);
431 LogMenuAction(MENU_ACTION_NEW_INCOGNITO_WINDOW);
432 break;
433
434 // Bookmarks sub menu.
435 case IDC_SHOW_BOOKMARK_BAR:
436 if (!uma_action_recorded_)
437 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ShowBookmarkBar",
438 now);
439 LogMenuAction(MENU_ACTION_SHOW_BOOKMARK_BAR);
440 break;
441 case IDC_SHOW_BOOKMARK_MANAGER:
442 if (!uma_action_recorded_)
443 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ShowBookmarkMgr",
444 now);
445 LogMenuAction(MENU_ACTION_SHOW_BOOKMARK_MANAGER);
446 break;
447 case IDC_IMPORT_SETTINGS:
448 if (!uma_action_recorded_)
449 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ImportSettings",
450 now);
451 LogMenuAction(MENU_ACTION_IMPORT_SETTINGS);
452 break;
453 case IDC_BOOKMARK_PAGE:
454 if (!uma_action_recorded_)
455 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_BookmarkPage", now);
456 LogMenuAction(MENU_ACTION_BOOKMARK_PAGE);
457 break;
458 case IDC_BOOKMARK_ALL_TABS:
459 if (!uma_action_recorded_)
460 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_BookmarkAllTabs",
461 now);
462 LogMenuAction(MENU_ACTION_BOOKMARK_ALL_TABS);
463 break;
464 case IDC_PIN_TO_START_SCREEN:
465 if (!uma_action_recorded_)
466 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_PinToStartScreen",
467 now);
468 LogMenuAction(MENU_ACTION_PIN_TO_START_SCREEN);
469 break;
470
471 // Recent tabs menu.
472 case IDC_RESTORE_TAB:
473 if (!uma_action_recorded_)
474 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_RestoreTab", now);
475 LogMenuAction(MENU_ACTION_RESTORE_TAB);
476 break;
477
478 // Windows.
479 case IDC_WIN_DESKTOP_RESTART:
480 if (!uma_action_recorded_)
481 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_WinDesktopRestart",
482 now);
483 LogMenuAction(MENU_ACTION_WIN_DESKTOP_RESTART);
484 break;
485 case IDC_WIN8_METRO_RESTART:
486 if (!uma_action_recorded_)
487 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Win8MetroRestart",
488 now);
489 LogMenuAction(MENU_ACTION_WIN8_METRO_RESTART);
490 break;
491
492 case IDC_WIN_CHROMEOS_RESTART:
493 if (!uma_action_recorded_)
494 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ChromeOSRestart",
495 now);
496 LogMenuAction(MENU_ACTION_WIN_CHROMEOS_RESTART);
497 break;
498 case IDC_DISTILL_PAGE:
499 if (!uma_action_recorded_)
500 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_DistillPage", now);
501 LogMenuAction(MENU_ACTION_DISTILL_PAGE);
502 break;
503 case IDC_SAVE_PAGE:
504 if (!uma_action_recorded_)
505 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_SavePage", now);
506 LogMenuAction(MENU_ACTION_SAVE_PAGE);
507 break;
508 case IDC_FIND:
509 if (!uma_action_recorded_)
510 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Find", now);
511 LogMenuAction(MENU_ACTION_FIND);
512 break;
513 case IDC_PRINT:
514 if (!uma_action_recorded_)
515 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Print", now);
516 LogMenuAction(MENU_ACTION_PRINT);
517 break;
518
519 // Edit menu.
520 case IDC_CUT:
521 if (!uma_action_recorded_)
522 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Cut", now);
523 LogMenuAction(MENU_ACTION_CUT);
524 break;
525 case IDC_COPY:
526 if (!uma_action_recorded_)
527 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Copy", now);
528 LogMenuAction(MENU_ACTION_COPY);
529 break;
530 case IDC_PASTE:
531 if (!uma_action_recorded_)
532 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Paste", now);
533 LogMenuAction(MENU_ACTION_PASTE);
534 break;
535
536 // Tools menu.
537 case IDC_CREATE_HOSTED_APP:
538 if (!uma_action_recorded_)
539 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_CreateHostedApp",
540 now);
541 LogMenuAction(MENU_ACTION_CREATE_HOSTED_APP);
542 break;
543 case IDC_CREATE_SHORTCUTS:
544 if (!uma_action_recorded_)
545 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_CreateShortcuts",
546 now);
547 LogMenuAction(MENU_ACTION_CREATE_SHORTCUTS);
548 break;
549 case IDC_MANAGE_EXTENSIONS:
550 if (!uma_action_recorded_)
551 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ManageExtensions",
552 now);
553 LogMenuAction(MENU_ACTION_MANAGE_EXTENSIONS);
554 break;
555 case IDC_TASK_MANAGER:
556 if (!uma_action_recorded_)
557 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_TaskManager", now);
558 LogMenuAction(MENU_ACTION_TASK_MANAGER);
559 break;
560 case IDC_CLEAR_BROWSING_DATA:
561 if (!uma_action_recorded_)
562 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ClearBrowsingData",
563 now);
564 LogMenuAction(MENU_ACTION_CLEAR_BROWSING_DATA);
565 break;
566 case IDC_VIEW_SOURCE:
567 if (!uma_action_recorded_)
568 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ViewSource", now);
569 LogMenuAction(MENU_ACTION_VIEW_SOURCE);
570 break;
571 case IDC_DEV_TOOLS:
572 if (!uma_action_recorded_)
573 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_DevTools", now);
574 LogMenuAction(MENU_ACTION_DEV_TOOLS);
575 break;
576 case IDC_DEV_TOOLS_CONSOLE:
577 if (!uma_action_recorded_)
578 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_DevToolsConsole",
579 now);
580 LogMenuAction(MENU_ACTION_DEV_TOOLS_CONSOLE);
581 break;
582 case IDC_DEV_TOOLS_DEVICES:
583 if (!uma_action_recorded_)
584 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_DevToolsDevices",
585 now);
586 LogMenuAction(MENU_ACTION_DEV_TOOLS_DEVICES);
587 break;
588 case IDC_PROFILING_ENABLED:
589 if (!uma_action_recorded_)
590 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ProfilingEnabled",
591 now);
592 LogMenuAction(MENU_ACTION_PROFILING_ENABLED);
593 break;
594
595 // Zoom menu
596 case IDC_ZOOM_MINUS:
597 if (!uma_action_recorded_) {
598 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ZoomMinus", now);
599 LogMenuAction(MENU_ACTION_ZOOM_MINUS);
600 }
601 break;
602 case IDC_ZOOM_PLUS:
603 if (!uma_action_recorded_) {
604 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ZoomPlus", now);
605 LogMenuAction(MENU_ACTION_ZOOM_PLUS);
606 }
607 break;
608 case IDC_FULLSCREEN:
609 content::RecordAction(UserMetricsAction("EnterFullScreenWithWrenchMenu"));
610
611 if (!uma_action_recorded_)
612 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_EnterFullScreen",
613 now);
614 LogMenuAction(MENU_ACTION_FULLSCREEN);
615 break;
616
617 case IDC_SHOW_HISTORY:
618 if (!uma_action_recorded_)
619 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ShowHistory", now);
620 LogMenuAction(MENU_ACTION_SHOW_HISTORY);
621 break;
622 case IDC_SHOW_DOWNLOADS:
623 if (!uma_action_recorded_)
624 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ShowDownloads",
625 now);
626 LogMenuAction(MENU_ACTION_SHOW_DOWNLOADS);
627 break;
628 case IDC_SHOW_SYNC_SETUP:
629 if (!uma_action_recorded_)
630 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_ShowSyncSetup",
631 now);
632 LogMenuAction(MENU_ACTION_SHOW_SYNC_SETUP);
633 break;
634 case IDC_OPTIONS:
635 if (!uma_action_recorded_)
636 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Settings", now);
637 LogMenuAction(MENU_ACTION_OPTIONS);
638 break;
639 case IDC_ABOUT:
640 if (!uma_action_recorded_)
641 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_About", now);
642 LogMenuAction(MENU_ACTION_ABOUT);
643 break;
644
645 // Help menu.
646 case IDC_HELP_PAGE_VIA_MENU:
647 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu"));
648
649 if (!uma_action_recorded_)
650 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_HelpPage", now);
651 LogMenuAction(MENU_ACTION_HELP_PAGE_VIA_MENU);
652 break;
653 #if defined(GOOGLE_CHROME_BUILD)
654 case IDC_FEEDBACK:
655 if (!uma_action_recorded_)
656 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Feedback", now);
657 LogMenuAction(MENU_ACTION_FEEDBACK);
658 break;
659 #endif
660
661 case IDC_TOGGLE_REQUEST_TABLET_SITE:
662 if (!uma_action_recorded_)
663 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_RequestTabletSite",
664 now);
665 LogMenuAction(MENU_ACTION_TOGGLE_REQUEST_TABLET_SITE);
666 break;
667 case IDC_EXIT:
668 if (!uma_action_recorded_)
669 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction_Exit", now);
670 LogMenuAction(MENU_ACTION_EXIT);
671 break;
672 }
673
674 if (!uma_action_recorded_) {
675 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction", now);
676 uma_action_recorded_ = true;
677 }
678 }
679
680 void WrenchMenuModel::LogMenuAction(int action_id) {
681 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.MenuAction", action_id,
682 LIMIT_MENU_ACTION);
Alexei Svitkine (slow) 2014/11/17 18:51:18 Nit: Align.
edwardjung 2014/11/17 19:18:56 Done.
683 }
684
420 bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { 685 bool WrenchMenuModel::IsCommandIdChecked(int command_id) const {
421 if (command_id == IDC_SHOW_BOOKMARK_BAR) { 686 if (command_id == IDC_SHOW_BOOKMARK_BAR) {
422 return browser_->profile()->GetPrefs()->GetBoolean( 687 return browser_->profile()->GetPrefs()->GetBoolean(
423 bookmarks::prefs::kShowBookmarkBar); 688 bookmarks::prefs::kShowBookmarkBar);
424 } else if (command_id == IDC_PROFILING_ENABLED) { 689 } else if (command_id == IDC_PROFILING_ENABLED) {
425 return Profiling::BeingProfiled(); 690 return Profiling::BeingProfiled();
426 } else if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) { 691 } else if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) {
427 return chrome::IsRequestingTabletSite(browser_); 692 return chrome::IsRequestingTabletSite(browser_);
428 } 693 }
429 694
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) 923 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
659 show_exit_menu = false; 924 show_exit_menu = false;
660 #endif 925 #endif
661 926
662 if (show_exit_menu) { 927 if (show_exit_menu) {
663 AddSeparator(ui::NORMAL_SEPARATOR); 928 AddSeparator(ui::NORMAL_SEPARATOR);
664 AddItemWithStringId(IDC_EXIT, IDS_EXIT); 929 AddItemWithStringId(IDC_EXIT, IDS_EXIT);
665 } 930 }
666 931
667 RemoveTrailingSeparators(); 932 RemoveTrailingSeparators();
933 uma_action_recorded_ = false;
668 } 934 }
669 935
670 void WrenchMenuModel::AddGlobalErrorMenuItems() { 936 void WrenchMenuModel::AddGlobalErrorMenuItems() {
671 // TODO(sail): Currently we only build the wrench menu once per browser 937 // TODO(sail): Currently we only build the wrench menu once per browser
672 // window. This means that if a new error is added after the menu is built 938 // window. This means that if a new error is added after the menu is built
673 // it won't show in the existing wrench menu. To fix this we need to some 939 // it won't show in the existing wrench menu. To fix this we need to some
674 // how update the menu if new errors are added. 940 // how update the menu if new errors are added.
675 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 941 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
676 // GetSignedInServiceErrors() can modify the global error list, so call it 942 // GetSignedInServiceErrors() can modify the global error list, so call it
677 // before iterating through that list below. 943 // before iterating through that list below.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ->GetZoomPercent(); 1049 ->GetZoomPercent();
784 } 1050 }
785 zoom_label_ = l10n_util::GetStringFUTF16( 1051 zoom_label_ = l10n_util::GetStringFUTF16(
786 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); 1052 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent));
787 } 1053 }
788 1054
789 void WrenchMenuModel::OnZoomLevelChanged( 1055 void WrenchMenuModel::OnZoomLevelChanged(
790 const content::HostZoomMap::ZoomLevelChange& change) { 1056 const content::HostZoomMap::ZoomLevelChange& change) {
791 UpdateZoomControls(); 1057 UpdateZoomControls();
792 } 1058 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698