Switch TestFrameNavigationObserver to DidCommitProvisionalLoadForFrame.
[chromium-blink-merge.git] / third_party / google_input_tools / src / chrome / os / inputview / perftracker.js
blob26c9aa03b747207a981779c2e63e92d878af75d3
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
14 goog.provide('i18n.input.chrome.inputview.PerfTracker');
16 goog.require('i18n.input.chrome.Statistics');
19 goog.scope(function() {
23 /**
24 * The tracker for the performance.
26 * @param {PerfTracker.TickName} htmlLoadedTickName .
27 * @constructor
29 i18n.input.chrome.inputview.PerfTracker = function(
30 htmlLoadedTickName) {
31 /**
32 * The time when this tracker starts.
34 * @private {number}
36 this.startInMs_ = new Date().getTime();
38 this.tick(htmlLoadedTickName,
39 window['InputViewPageStartLoading'],
40 'Time elapsed before 0');
42 var PerfTracker = i18n.input.chrome.inputview.PerfTracker;
45 /** @private {boolean} */
46 PerfTracker.prototype.stopped_ = false;
49 /**
50 * The name of the tick.
52 * @enum {string}
54 PerfTracker.TickName = {
55 BACKGROUND_HTML_LOADED: 'BackgroundHtmlLoaded',
56 NACL_LOADED: 'NaclLoaded',
57 BACKGROUND_SETTINGS_FETCHED: 'BackgroundSettingsFetched',
58 HTML_LOADED: 'HtmlLoaded',
59 KEYBOARD_CREATED: 'KeyboardCreated',
60 KEYBOARD_SHOWN: 'KeyboardShown',
61 KEYSET_LOADED: 'KeysetLoaded',
62 LAYOUT_LOADED: 'LayoutLoaded'
66 /**
67 * Resets this performance tracker.
69 PerfTracker.prototype.restart = function() {
70 this.startInMs_ = new Date().getTime();
71 this.stopped_ = false;
75 /**
76 * Stops the performance tracker.
78 PerfTracker.prototype.stop = function() {
79 this.stopped_ = true;
83 /**
84 * Ticks with a custom message.
86 * @param {PerfTracker.TickName} tickName .
87 * @param {number=} opt_startInMs The timestamp used as start, if not
88 * specified, use this.startInMs_.
89 * @param {string=} opt_msg Extra log message to describe the logging in more
90 * detail.
92 PerfTracker.prototype.tick = function(tickName, opt_startInMs, opt_msg) {
93 if (this.stopped_) {
94 return;
97 var startInMs = opt_startInMs || this.startInMs_;
98 var cost = new Date().getTime() - startInMs;
99 var msg = tickName + ' - ' + cost;
100 if (opt_msg) {
101 msg += ' - ' + opt_msg;
103 console.log(msg);
104 i18n.input.chrome.Statistics.getInstance().recordLatency(
105 'InputMethod.VirtualKeyboard.InitLatency.' + tickName, cost);
108 }); // goog.scope