UserMetrics.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2011 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * @constructor
  32. */
  33. WebInspector.UserMetrics = function()
  34. {
  35. for (var actionName in WebInspector.UserMetrics._ActionCodes) {
  36. var actionCode = WebInspector.UserMetrics._ActionCodes[actionName];
  37. this[actionName] = new WebInspector.UserMetrics._Recorder(actionCode);
  38. }
  39. function settingChanged(trueCode, falseCode, event)
  40. {
  41. if (event.data)
  42. InspectorFrontendHost.recordSettingChanged(trueCode);
  43. else
  44. InspectorFrontendHost.recordSettingChanged(falseCode);
  45. }
  46. WebInspector.settings.domWordWrap.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ElementsDOMWrapOn, WebInspector.UserMetrics._SettingCodes.ElementsDOMWrapOff));
  47. WebInspector.settings.monitoringXHREnabled.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ConsoleMonitorXHROn, WebInspector.UserMetrics._SettingCodes.ConsoleMonitorXHROff));
  48. WebInspector.settings.preserveConsoleLog.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ConsolePreserveLogOn, WebInspector.UserMetrics._SettingCodes.ConsolePreserveLogOff));
  49. WebInspector.settings.resourcesLargeRows.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.NetworkShowLargeRowsOn, WebInspector.UserMetrics._SettingCodes.NetworkShowLargeRowsOff));
  50. }
  51. // Codes below are used to collect UMA histograms in the Chromium port.
  52. // Do not change the values below, additional actions are needed on the Chromium side
  53. // in order to add more codes.
  54. WebInspector.UserMetrics._ActionCodes = {
  55. WindowDocked: 1,
  56. WindowUndocked: 2,
  57. ScriptsBreakpointSet: 3,
  58. TimelineStarted: 4,
  59. ProfilesCPUProfileTaken: 5,
  60. ProfilesHeapProfileTaken: 6,
  61. AuditsStarted: 7,
  62. ConsoleEvaluated: 8
  63. }
  64. WebInspector.UserMetrics._SettingCodes = {
  65. ElementsDOMWrapOn: 1,
  66. ElementsDOMWrapOff: 2,
  67. ConsoleMonitorXHROn: 3,
  68. ConsoleMonitorXHROff: 4,
  69. ConsolePreserveLogOn: 5,
  70. ConsolePreserveLogOff: 6,
  71. NetworkShowLargeRowsOn: 7,
  72. NetworkShowLargeRowsOff: 8
  73. }
  74. WebInspector.UserMetrics._PanelCodes = {
  75. elements: 1,
  76. resources: 2,
  77. network: 3,
  78. scripts: 4,
  79. timeline: 5,
  80. profiles: 6,
  81. audits: 7,
  82. console: 8
  83. }
  84. WebInspector.UserMetrics.UserAction = "UserAction";
  85. WebInspector.UserMetrics.UserActionNames = {
  86. ForcedElementState: "forcedElementState",
  87. FileSaved: "fileSaved",
  88. RevertRevision: "revertRevision",
  89. ApplyOriginalContent: "applyOriginalContent",
  90. TogglePrettyPrint: "togglePrettyPrint",
  91. SetBreakpoint: "setBreakpoint",
  92. OpenSourceLink: "openSourceLink",
  93. NetworkSort: "networkSort",
  94. NetworkRequestSelected: "networkRequestSelected",
  95. NetworkRequestTabSelected: "networkRequestTabSelected",
  96. HeapSnapshotFilterChanged: "heapSnapshotFilterChanged"
  97. };
  98. WebInspector.UserMetrics.prototype = {
  99. panelShown: function(panelName)
  100. {
  101. InspectorFrontendHost.recordPanelShown(WebInspector.UserMetrics._PanelCodes[panelName] || 0);
  102. }
  103. }
  104. /**
  105. * @constructor
  106. */
  107. WebInspector.UserMetrics._Recorder = function(actionCode)
  108. {
  109. this._actionCode = actionCode;
  110. }
  111. WebInspector.UserMetrics._Recorder.prototype = {
  112. record: function()
  113. {
  114. InspectorFrontendHost.recordActionTaken(this._actionCode);
  115. }
  116. }
  117. WebInspector.userMetrics = new WebInspector.UserMetrics();