| OLD | NEW |
| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.Object} | 7 * @extends {WebInspector.Object} |
| 8 */ | 8 */ |
| 9 WebInspector.PowerProfiler = function() | 9 WebInspector.PowerProfiler = function() |
| 10 { | 10 { |
| 11 WebInspector.Object.call(this); | 11 WebInspector.Object.call(this); |
| 12 this._dispatcher = new WebInspector.PowerDispatcher(this); | 12 this._dispatcher = new WebInspector.PowerDispatcher(this); |
| 13 PowerAgent.getAccuracyLevel(this._onAccuracyLevel.bind(this)); |
| 13 } | 14 } |
| 14 | 15 |
| 15 WebInspector.PowerProfiler.EventTypes = { | 16 WebInspector.PowerProfiler.EventTypes = { |
| 16 PowerEventRecorded: "PowerEventRecorded" | 17 PowerEventRecorded: "PowerEventRecorded" |
| 17 } | 18 } |
| 18 | 19 |
| 19 WebInspector.PowerProfiler.prototype = { | 20 WebInspector.PowerProfiler.prototype = { |
| 20 | 21 |
| 21 startProfile: function () | 22 startProfile: function () |
| 22 { | 23 { |
| 23 PowerAgent.start(); | 24 PowerAgent.start(); |
| 24 }, | 25 }, |
| 25 | 26 |
| 26 stopProfile: function () | 27 stopProfile: function () |
| 27 { | 28 { |
| 28 PowerAgent.end(); | 29 PowerAgent.end(); |
| 29 }, | 30 }, |
| 30 | 31 |
| 32 getAccuracyLevel: function() |
| 33 { |
| 34 return this._accuracyLevel; |
| 35 }, |
| 36 |
| 37 _onAccuracyLevel: function(error, result) { |
| 38 this._accuracyLevel = ""; |
| 39 if (error) { |
| 40 console.log("Unable to retrieve PowerProfiler accuracy level: " + er
ror); |
| 41 return; |
| 42 } |
| 43 this._accuracyLevel = result; |
| 44 }, |
| 45 |
| 31 __proto__: WebInspector.Object.prototype | 46 __proto__: WebInspector.Object.prototype |
| 32 } | 47 } |
| 33 | 48 |
| 34 /** | 49 /** |
| 35 * @constructor | 50 * @constructor |
| 36 * @implements {PowerAgent.Dispatcher} | 51 * @implements {PowerAgent.Dispatcher} |
| 37 */ | 52 */ |
| 38 WebInspector.PowerDispatcher = function(profiler) | 53 WebInspector.PowerDispatcher = function(profiler) |
| 39 { | 54 { |
| 40 this._profiler = profiler; | 55 this._profiler = profiler; |
| 41 InspectorBackend.registerPowerDispatcher(this); | 56 InspectorBackend.registerPowerDispatcher(this); |
| 42 } | 57 } |
| 43 | 58 |
| 44 WebInspector.PowerDispatcher.prototype = { | 59 WebInspector.PowerDispatcher.prototype = { |
| 45 dataAvailable: function(events) | 60 dataAvailable: function(events) |
| 46 { | 61 { |
| 47 for (var i = 0; i < events.length; ++i) | 62 for (var i = 0; i < events.length; ++i) |
| 48 this._profiler.dispatchEventToListeners(WebInspector.PowerProfiler.E
ventTypes.PowerEventRecorded, events[i]); | 63 this._profiler.dispatchEventToListeners(WebInspector.PowerProfiler.E
ventTypes.PowerEventRecorded, events[i]); |
| 49 } | 64 } |
| 50 } | 65 } |
| 51 | 66 |
| 52 /** | 67 /** |
| 53 * @type {!WebInspector.PowerProfiler} | 68 * @type {!WebInspector.PowerProfiler} |
| 54 */ | 69 */ |
| 55 WebInspector.powerProfiler; | 70 WebInspector.powerProfiler; |
| OLD | NEW |