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

Side by Side Diff: chrome/browser/resources/local_discovery/local_discovery.js

Issue 23508003: Added UMA actions to devices page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/local_discovery/local_discovery_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 * Javascript for local_discovery.html, served from chrome://devices/ 6 * Javascript for local_discovery.html, served from chrome://devices/
7 * This is used to show discoverable devices near the user as well as 7 * This is used to show discoverable devices near the user as well as
8 * cloud devices registered to them. 8 * cloud devices registered to them.
9 * 9 *
10 * The object defined in this javascript file listens for callbacks from the 10 * The object defined in this javascript file listens for callbacks from the
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 * @param {boolean} is_mine Whether or not the device is in the 'Registered' 79 * @param {boolean} is_mine Whether or not the device is in the 'Registered'
80 * section. 80 * section.
81 */ 81 */
82 deviceContainer: function() { 82 deviceContainer: function() {
83 return $('register-device-list'); 83 return $('register-device-list');
84 }, 84 },
85 /** 85 /**
86 * Register the device. 86 * Register the device.
87 */ 87 */
88 register: function() { 88 register: function() {
89 recordUmaAction('DevicesPage_RegisterClicked');
89 chrome.send('registerDevice', [this.info.service_name]); 90 chrome.send('registerDevice', [this.info.service_name]);
90 setRegisterPage('register-page-adding1'); 91 setRegisterPage('register-page-adding1');
91 } 92 }
92 }; 93 };
93 94
94 /** 95 /**
95 * Returns a textual representation of the number of printers on the network. 96 * Returns a textual representation of the number of printers on the network.
96 * @return {string} Number of printers on the network as localized string. 97 * @return {string} Number of printers on the network as localized string.
97 */ 98 */
98 function generateNumberPrintersAvailableText(numberPrinters) { 99 function generateNumberPrintersAvailableText(numberPrinters) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 deviceDescription.textContent = description; 136 deviceDescription.textContent = description;
136 deviceInfo.appendChild(deviceDescription); 137 deviceInfo.appendChild(deviceDescription);
137 138
138 var button = document.createElement('button'); 139 var button = document.createElement('button');
139 button.textContent = button_text; 140 button.textContent = button_text;
140 button.addEventListener('click', button_action); 141 button.addEventListener('click', button_action);
141 device_dom_element.appendChild(button); 142 device_dom_element.appendChild(button);
142 } 143 }
143 144
144 /** 145 /**
145 * Hide the register overlay. 146 * Show the register overlay.
146 */ 147 */
147 function showRegisterOverlay() { 148 function showRegisterOverlay() {
149 recordUmaAction('DevicesPage_AddPrintersClicked');
148 $('register-overlay').classList.add('showing'); 150 $('register-overlay').classList.add('showing');
149 $('overlay').hidden = false; 151 $('overlay').hidden = false;
150 uber.invokeMethodOnParent('beginInterceptingEvents'); 152 uber.invokeMethodOnParent('beginInterceptingEvents');
151 setRegisterPage('register-page-choose'); 153 setRegisterPage('register-page-choose');
152 } 154 }
153 155
154 /** 156 /**
155 * Show the register overlay. 157 * Hide the register overlay.
156 */ 158 */
157 function hideRegisterOverlay() { 159 function hideRegisterOverlay() {
158 $('register-overlay').classList.remove('showing'); 160 $('register-overlay').classList.remove('showing');
159 $('overlay').hidden = true; 161 $('overlay').hidden = true;
160 uber.invokeMethodOnParent('stopInterceptingEvents'); 162 uber.invokeMethodOnParent('stopInterceptingEvents');
161 chrome.send('cancelRegistration');
162 } 163 }
163 164
164 /** 165 /**
165 * Clear a DOM element of all children. 166 * Clear a DOM element of all children.
166 * @param {HTMLElement} element DOM element to clear. 167 * @param {HTMLElement} element DOM element to clear.
167 */ 168 */
168 function clearElement(element) { 169 function clearElement(element) {
169 while (element.firstChild) { 170 while (element.firstChild) {
170 element.removeChild(element.firstChild); 171 element.removeChild(element.firstChild);
171 } 172 }
172 } 173 }
173 174
174 /** 175 /**
175 * Announce that a registration failed. 176 * Announce that a registration failed.
176 */ 177 */
177 function onRegistrationFailed() { 178 function onRegistrationFailed() {
178 setRegisterPage('register-page-error'); 179 setRegisterPage('register-page-error');
180 recordUmaAction('DevicesPage_RegisterFailure');
179 } 181 }
180 182
181 /** 183 /**
182 * Update UI to reflect that registration has been confirmed on the printer. 184 * Update UI to reflect that registration has been confirmed on the printer.
183 */ 185 */
184 function onRegistrationConfirmedOnPrinter() { 186 function onRegistrationConfirmedOnPrinter() {
185 setRegisterPage('register-page-adding2'); 187 setRegisterPage('register-page-adding2');
186 } 188 }
187 189
188 /** 190 /**
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 263 }
262 } 264 }
263 265
264 266
265 /** 267 /**
266 * Announce that a registration succeeeded. 268 * Announce that a registration succeeeded.
267 */ 269 */
268 function onRegistrationSuccess() { 270 function onRegistrationSuccess() {
269 hideRegisterOverlay(); 271 hideRegisterOverlay();
270 requestPrinterList(); 272 requestPrinterList();
273 recordUmaAction('DevicesPage_RegisterSuccess');
271 } 274 }
272 275
273 /** 276 /**
274 * Update visibility status for page. 277 * Update visibility status for page.
275 */ 278 */
276 function updateVisibility() { 279 function updateVisibility() {
277 chrome.send('isVisible', [!document.webkitHidden]); 280 chrome.send('isVisible', [!document.webkitHidden]);
278 } 281 }
279 282
280 /** 283 /**
(...skipping 17 matching lines...) Expand all
298 clearElement($('cloud-devices')); 301 clearElement($('cloud-devices'));
299 $('cloud-devices-loading').hidden = false; 302 $('cloud-devices-loading').hidden = false;
300 chrome.send('requestPrinterList'); 303 chrome.send('requestPrinterList');
301 } 304 }
302 305
303 /** 306 /**
304 * Go to management page for a cloud device. 307 * Go to management page for a cloud device.
305 * @param {string} device_id ID of device. 308 * @param {string} device_id ID of device.
306 */ 309 */
307 function manageCloudDevice(device_id) { 310 function manageCloudDevice(device_id) {
311 recordUmaAction('DevicesPage_ManageClicked');
308 chrome.send('openCloudPrintURL', 312 chrome.send('openCloudPrintURL',
309 [PRINTER_MANAGEMENT_PAGE_PREFIX + device_id]); 313 [PRINTER_MANAGEMENT_PAGE_PREFIX + device_id]);
310 } 314 }
311 315
316 /**
317 * Record an action in UMA.
318 * @param {string} actionDesc The name of the action to be logged.
319 */
320 function recordUmaAction(actionDesc) {
321 chrome.send('metricsHandler:recordAction', [actionDesc]);
322 }
323
324 /**
325 * Cancel the registration.
326 */
327 function cancelRegistration() {
328 hideRegisterOverlay();
329 chrome.send('cancelRegistration');
330 recordUmaAction('DevicesPage_RegisterCancel');
331 }
312 332
313 document.addEventListener('DOMContentLoaded', function() { 333 document.addEventListener('DOMContentLoaded', function() {
314 uber.onContentFrameLoaded(); 334 uber.onContentFrameLoaded();
315 335
316 cr.ui.overlay.setupOverlay($('overlay')); 336 cr.ui.overlay.setupOverlay($('overlay'));
317 cr.ui.overlay.globalInitialization(); 337 cr.ui.overlay.globalInitialization();
318 $('overlay').addEventListener('cancelOverlay', hideRegisterOverlay); 338 $('overlay').addEventListener('cancelOverlay', cancelRegistration);
319 339
320 var cancelButtons = document.querySelectorAll('.register-cancel'); 340 var cancelButtons = document.querySelectorAll('.register-cancel');
321 var cancelButtonsLength = cancelButtons.length; 341 var cancelButtonsLength = cancelButtons.length;
322 for (var i = 0; i < cancelButtonsLength; i++) { 342 for (var i = 0; i < cancelButtonsLength; i++) {
323 cancelButtons[i].addEventListener('click', hideRegisterOverlay); 343 cancelButtons[i].addEventListener('click', cancelRegistration);
324 } 344 }
325 345
326 $('register-error-exit').addEventListener('click', hideRegisterOverlay); 346 $('register-error-exit').addEventListener('click', cancelRegistration);
327 347
328 $('add-printers-button').addEventListener('click', 348 $('add-printers-button').addEventListener('click',
329 showRegisterOverlay); 349 showRegisterOverlay);
330 350
331 updateVisibility(); 351 updateVisibility();
332 document.addEventListener('webkitvisibilitychange', updateVisibility, 352 document.addEventListener('webkitvisibilitychange', updateVisibility,
333 false); 353 false);
334 354
335 var title = loadTimeData.getString('devicesTitle'); 355 var title = loadTimeData.getString('devicesTitle');
336 uber.invokeMethodOnParent('setTitle', {title: title}); 356 uber.invokeMethodOnParent('setTitle', {title: title});
337 357
338 chrome.send('start'); 358 chrome.send('start');
359 recordUmaAction('DevicesPage_Opened');
339 requestPrinterList(); 360 requestPrinterList();
340 }); 361 });
341 362
342 return { 363 return {
343 onRegistrationSuccess: onRegistrationSuccess, 364 onRegistrationSuccess: onRegistrationSuccess,
344 onRegistrationFailed: onRegistrationFailed, 365 onRegistrationFailed: onRegistrationFailed,
345 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate, 366 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate,
346 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter, 367 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter,
347 onCloudDeviceListAvailable: onCloudDeviceListAvailable, 368 onCloudDeviceListAvailable: onCloudDeviceListAvailable,
348 onDeviceCacheFlushed: onDeviceCacheFlushed 369 onDeviceCacheFlushed: onDeviceCacheFlushed
349 }; 370 };
350 }); 371 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/local_discovery/local_discovery_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698