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

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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 * @param {boolean} is_mine Whether or not the device is in the 'Registered' 76 * @param {boolean} is_mine Whether or not the device is in the 'Registered'
77 * section. 77 * section.
78 */ 78 */
79 deviceContainer: function() { 79 deviceContainer: function() {
80 return $('register-device-list'); 80 return $('register-device-list');
81 }, 81 },
82 /** 82 /**
83 * Register the device. 83 * Register the device.
84 */ 84 */
85 register: function() { 85 register: function() {
86 recordUmaAction('DevicesPage_RegisterClicked');
86 chrome.send('registerDevice', [this.info.service_name]); 87 chrome.send('registerDevice', [this.info.service_name]);
87 setRegisterPage('register-page-adding1'); 88 setRegisterPage('register-page-adding1');
88 } 89 }
89 }; 90 };
90 91
91 /** 92 /**
92 * Returns a textual representation of the number of printers on the network. 93 * Returns a textual representation of the number of printers on the network.
93 * @return {string} Number of printers on the network as localized string. 94 * @return {string} Number of printers on the network as localized string.
94 */ 95 */
95 function generateNumberPrintersAvailableText(numberPrinters) { 96 function generateNumberPrintersAvailableText(numberPrinters) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 deviceDescription.textContent = description; 133 deviceDescription.textContent = description;
133 deviceInfo.appendChild(deviceDescription); 134 deviceInfo.appendChild(deviceDescription);
134 135
135 var button = document.createElement('button'); 136 var button = document.createElement('button');
136 button.textContent = button_text; 137 button.textContent = button_text;
137 button.addEventListener('click', button_action); 138 button.addEventListener('click', button_action);
138 device_dom_element.appendChild(button); 139 device_dom_element.appendChild(button);
139 } 140 }
140 141
141 /** 142 /**
142 * Hide the register overlay. 143 * Show the register overlay.
143 */ 144 */
144 function showRegisterOverlay() { 145 function showRegisterOverlay() {
146 recordUmaAction('DevicesPage_AddPrintersClicked');
145 $('register-overlay').classList.add('showing'); 147 $('register-overlay').classList.add('showing');
146 $('overlay').hidden = false; 148 $('overlay').hidden = false;
147 uber.invokeMethodOnParent('beginInterceptingEvents'); 149 uber.invokeMethodOnParent('beginInterceptingEvents');
148 setRegisterPage('register-page-choose'); 150 setRegisterPage('register-page-choose');
149 } 151 }
150 152
151 /** 153 /**
152 * Show the register overlay. 154 * Hide the register overlay.
153 */ 155 */
154 function hideRegisterOverlay() { 156 function hideRegisterOverlay() {
155 $('register-overlay').classList.remove('showing'); 157 $('register-overlay').classList.remove('showing');
156 $('overlay').hidden = true; 158 $('overlay').hidden = true;
157 uber.invokeMethodOnParent('stopInterceptingEvents'); 159 uber.invokeMethodOnParent('stopInterceptingEvents');
158 chrome.send('cancelRegistration');
159 } 160 }
160 161
161 /** 162 /**
162 * Clear a DOM element of all children. 163 * Clear a DOM element of all children.
163 * @param {HTMLElement} element DOM element to clear. 164 * @param {HTMLElement} element DOM element to clear.
164 */ 165 */
165 function clearElement(element) { 166 function clearElement(element) {
166 while (element.firstChild) { 167 while (element.firstChild) {
167 element.removeChild(element.firstChild); 168 element.removeChild(element.firstChild);
168 } 169 }
169 } 170 }
170 171
171 /** 172 /**
172 * Announce that a registration failed. 173 * Announce that a registration failed.
173 */ 174 */
174 function onRegistrationFailed() { 175 function onRegistrationFailed() {
175 setRegisterPage('register-page-error'); 176 setRegisterPage('register-page-error');
177 recordUmaAction('DevicesPage_RegisterFailure');
176 } 178 }
177 179
178 /** 180 /**
179 * Update UI to reflect that registration has been confirmed on the printer. 181 * Update UI to reflect that registration has been confirmed on the printer.
180 */ 182 */
181 function onRegistrationConfirmedOnPrinter() { 183 function onRegistrationConfirmedOnPrinter() {
182 setRegisterPage('register-page-adding2'); 184 setRegisterPage('register-page-adding2');
183 } 185 }
184 186
185 /** 187 /**
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 260 }
259 } 261 }
260 262
261 263
262 /** 264 /**
263 * Announce that a registration succeeeded. 265 * Announce that a registration succeeeded.
264 */ 266 */
265 function onRegistrationSuccess() { 267 function onRegistrationSuccess() {
266 hideRegisterOverlay(); 268 hideRegisterOverlay();
267 requestPrinterList(); 269 requestPrinterList();
270 recordUmaAction('DevicesPage_RegisterSuccess');
268 } 271 }
269 272
270 /** 273 /**
271 * Update visibility status for page. 274 * Update visibility status for page.
272 */ 275 */
273 function updateVisibility() { 276 function updateVisibility() {
274 chrome.send('isVisible', [!document.webkitHidden]); 277 chrome.send('isVisible', [!document.webkitHidden]);
275 } 278 }
276 279
277 /** 280 /**
(...skipping 17 matching lines...) Expand all
295 clearElement($('cloud-devices')); 298 clearElement($('cloud-devices'));
296 $('cloud-devices-loading').hidden = false; 299 $('cloud-devices-loading').hidden = false;
297 chrome.send('requestPrinterList'); 300 chrome.send('requestPrinterList');
298 } 301 }
299 302
300 /** 303 /**
301 * Go to management page for a cloud device. 304 * Go to management page for a cloud device.
302 * @param {string} device_id ID of device. 305 * @param {string} device_id ID of device.
303 */ 306 */
304 function manageCloudDevice(device_id) { 307 function manageCloudDevice(device_id) {
308 recordUmaAction('DevicesPage_ManageClicked');
305 chrome.send('openCloudPrintURL', 309 chrome.send('openCloudPrintURL',
306 [PRINTER_MANAGEMENT_PAGE_PREFIX + device_id]); 310 [PRINTER_MANAGEMENT_PAGE_PREFIX + device_id]);
307 } 311 }
308 312
313 /**
314 * Record an action in UMA.
315 * @param {string} actionDesc The name of the action to be logged.
316 */
317 function recordUmaAction(actionDesc) {
318 chrome.send('metricsHandler:recordAction', [actionDesc]);
319 }
320
321 /**
322 * Cancel the registration.
323 */
324 function cancelRegistration() {
325 hideRegisterOverlay();
326 chrome.send('cancelRegistration');
327 recordUmaAction('DevicesPage_RegisterCancel');
328 }
309 329
310 document.addEventListener('DOMContentLoaded', function() { 330 document.addEventListener('DOMContentLoaded', function() {
311 uber.onContentFrameLoaded(); 331 uber.onContentFrameLoaded();
312 332
313 cr.ui.overlay.setupOverlay($('overlay')); 333 cr.ui.overlay.setupOverlay($('overlay'));
314 cr.ui.overlay.globalInitialization(); 334 cr.ui.overlay.globalInitialization();
315 $('overlay').addEventListener('cancelOverlay', hideRegisterOverlay); 335 $('overlay').addEventListener('cancelOverlay', cancelRegistration);
316 336
317 var cancelButtons = document.querySelectorAll('.register-cancel'); 337 var cancelButtons = document.querySelectorAll('.register-cancel');
318 var cancelButtonsLength = cancelButtons.length; 338 var cancelButtonsLength = cancelButtons.length;
319 for (var i = 0; i < cancelButtonsLength; i++) { 339 for (var i = 0; i < cancelButtonsLength; i++) {
320 cancelButtons[i].addEventListener('click', hideRegisterOverlay); 340 cancelButtons[i].addEventListener('click', cancelRegistration);
321 } 341 }
322 342
323 $('register-error-exit').addEventListener('click', hideRegisterOverlay); 343 $('register-error-exit').addEventListener('click', cancelRegistration);
324 344
325 $('add-printers-button').addEventListener('click', 345 $('add-printers-button').addEventListener('click',
326 showRegisterOverlay); 346 showRegisterOverlay);
327 347
328 updateVisibility(); 348 updateVisibility();
329 document.addEventListener('webkitvisibilitychange', updateVisibility, 349 document.addEventListener('webkitvisibilitychange', updateVisibility,
330 false); 350 false);
331 351
332 var title = loadTimeData.getString('devicesTitle'); 352 var title = loadTimeData.getString('devicesTitle');
333 uber.invokeMethodOnParent('setTitle', {title: title}); 353 uber.invokeMethodOnParent('setTitle', {title: title});
334 354
335 chrome.send('start'); 355 chrome.send('start');
356 recordUmaAction('DevicesPage_Opened');
336 requestPrinterList(); 357 requestPrinterList();
337 }); 358 });
338 359
339 return { 360 return {
340 onRegistrationSuccess: onRegistrationSuccess, 361 onRegistrationSuccess: onRegistrationSuccess,
341 onRegistrationFailed: onRegistrationFailed, 362 onRegistrationFailed: onRegistrationFailed,
342 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate, 363 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate,
343 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter, 364 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter,
344 onCloudDeviceListAvailable: onCloudDeviceListAvailable, 365 onCloudDeviceListAvailable: onCloudDeviceListAvailable,
345 onDeviceCacheFlushed: onDeviceCacheFlushed 366 onDeviceCacheFlushed: onDeviceCacheFlushed
346 }; 367 };
347 }); 368 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698