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