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

Side by Side Diff: chrome/browser/resources/gpu_internals/browser_bridge.js

Issue 6712048: Implement easy GPU feature status summary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor tweak. Created 9 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
5 cr.define('gpu', function() { 4 cr.define('gpu', function() {
6 /** 5 /**
7 * This class provides a 'bridge' for communicating between javascript and 6 * This class provides a 'bridge' for communicating between javascript and the
8 * the browser. 7 * browser. When run outside of WebUI, e.g. as a regular webpage, it provides
8 * synthetic data to assist in testing.
9 * @constructor 9 * @constructor
10 */ 10 */
11 function BrowserBridge() { 11 function BrowserBridge() {
12 // If we are not running inside WebUI, output chrome.send messages 12 // If we are not running inside WebUI, output chrome.send messages
13 // to the console to help with quick-iteration debugging. 13 // to the console to help with quick-iteration debugging.
14 if (chrome.send === undefined && console.log) { 14 if (chrome.send === undefined && console.log) {
15 this.debugMode_ = true; 15 this.debugMode_ = true;
16 chrome.send = function(messageHandler, args) { 16 var browserBridgeTests = document.createElement('script');
17 console.log('chrome.send', messageHandler, args); 17 browserBridgeTests.src = './gpu_internals/browser_bridge_tests.js';
18 }; 18 document.body.appendChild(browserBridgeTests);
19 } else { 19 } else {
20 this.debugMode_ = false; 20 this.debugMode_ = false;
21 } 21 }
22 22
23 this.nextRequestId_ = 0; 23 this.nextRequestId_ = 0;
24 this.pendingCallbacks_ = []; 24 this.pendingCallbacks_ = [];
25 this.logMessages_ = [];
25 26
26 // Tell c++ code that we are ready to receive GPU Info. 27 // Tell c++ code that we are ready to receive GPU Info.
27 chrome.send('browserBridgeInitialized'); 28 if (!this.debugMode_) {
29 chrome.send('browserBridgeInitialized');
30 this.beginRequestClientInfo_();
31 this.beginRequestLogMessages_();
32 }
28 } 33 }
29 34
30 BrowserBridge.prototype = { 35 BrowserBridge.prototype = {
31 __proto__: cr.EventTarget.prototype, 36 __proto__: cr.EventTarget.prototype,
32 37
38 applySimulatedData_: function applySimulatedData(data) {
39 // set up things according to the simulated data
40 this.gpuInfo_ = data.gpuInfo;
41 this.clientInfo_ = data.clientInfo;
42 this.logMessages_ = data.logMessages;
43 cr.dispatchSimpleEvent(this, 'gpuInfoUpdate');
44 cr.dispatchSimpleEvent(this, 'clientInfoChange');
45 cr.dispatchSimpleEvent(this, 'logMessagesChange');
46 },
47
33 /** 48 /**
34 * Returns true if the page is hosted inside Chrome WebUI 49 * Returns true if the page is hosted inside Chrome WebUI
35 * Helps have behavior conditional to emulate_webui.py 50 * Helps have behavior conditional to emulate_webui.py
36 */ 51 */
37 get debugMode() { 52 get debugMode() {
38 return this.debugMode_; 53 return this.debugMode_;
39 }, 54 },
40 55
41 /** 56 /**
42 * Sends a message to the browser with specified args. The 57 * Sends a message to the browser with specified args. The
(...skipping 29 matching lines...) Expand all
72 get gpuInfo() { 87 get gpuInfo() {
73 return this.gpuInfo_; 88 return this.gpuInfo_;
74 }, 89 },
75 90
76 /** 91 /**
77 * Called from gpu c++ code when GPU Info is updated. 92 * Called from gpu c++ code when GPU Info is updated.
78 */ 93 */
79 onGpuInfoUpdate: function(gpuInfo) { 94 onGpuInfoUpdate: function(gpuInfo) {
80 this.gpuInfo_ = gpuInfo; 95 this.gpuInfo_ = gpuInfo;
81 cr.dispatchSimpleEvent(this, 'gpuInfoUpdate'); 96 cr.dispatchSimpleEvent(this, 'gpuInfoUpdate');
97 },
98
99 /**
100 * This function begins a request for the ClientInfo. If it comes back
101 * as undefined, then we will issue the request again in 250ms.
102 */
103 beginRequestClientInfo_: function() {
104 this.callAsync('requestClientInfo', undefined, (function(data) {
105 if (data === undefined) { // try again in 250 ms
106 window.setTimeout(this.beginRequestClientInfo_.bind(this), 250);
107 } else {
108 this.clientInfo_ = data;
109 cr.dispatchSimpleEvent(this, 'clientInfoChange');
110 }
111 }).bind(this));
112 },
113
114 /**
115 * Returns information about the currently runnign Chrome build.
116 */
117 get clientInfo() {
118 return this.clientInfo_;
119 },
120
121 /**
122 * This function checks for new GPU_LOG messages.
123 * If any are found, a refresh is triggered.
124 */
125 beginRequestLogMessages_: function() {
126 this.callAsync('requestLogMessages', undefined,
127 (function(messages) {
128 if (messages.length != this.logMessages_.length) {
129 this.logMessages_ = messages;
130 cr.dispatchSimpleEvent(this, 'logMessagesChange');
131 }
132 // check again in 250 ms
133 window.setTimeout(this.beginRequestLogMessages_.bind(this), 250);
134 }).bind(this));
135 },
136
137 /**
138 * Returns an array of log messages issued by the GPU process, if any.
139 */
140 get logMessages() {
141 return this.logMessages_;
82 } 142 }
143
83 }; 144 };
84 145
85 return { 146 return {
86 BrowserBridge: BrowserBridge 147 BrowserBridge: BrowserBridge
87 }; 148 };
88 }); 149 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698