OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * SuggestAppsDialog contains a list box to select an app to be opened the file | 8 * SuggestAppsDialog contains a list box to select an app to be opened the file |
9 * with. This dialog should be used as action picker for file operations. | 9 * with. This dialog should be used as action picker for file operations. |
10 */ | 10 */ |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 * @const | 104 * @const |
105 */ | 105 */ |
106 SuggestAppsDialog.State = { | 106 SuggestAppsDialog.State = { |
107 UNINITIALIZED: 'SuggestAppsDialog.State.UNINITIALIZED', | 107 UNINITIALIZED: 'SuggestAppsDialog.State.UNINITIALIZED', |
108 INITIALIZING: 'SuggestAppsDialog.State.INITIALIZING', | 108 INITIALIZING: 'SuggestAppsDialog.State.INITIALIZING', |
109 INITIALIZE_FAILED_CLOSING: | 109 INITIALIZE_FAILED_CLOSING: |
110 'SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING', | 110 'SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING', |
111 INITIALIZED: 'SuggestAppsDialog.State.INITIALIZED', | 111 INITIALIZED: 'SuggestAppsDialog.State.INITIALIZED', |
112 INSTALLING: 'SuggestAppsDialog.State.INSTALLING', | 112 INSTALLING: 'SuggestAppsDialog.State.INSTALLING', |
113 INSTALLED_CLOSING: 'SuggestAppsDialog.State.INSTALLED_CLOSING', | 113 INSTALLED_CLOSING: 'SuggestAppsDialog.State.INSTALLED_CLOSING', |
114 OPENING_WEBSTORE_CLOSING: 'SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING', | |
114 CANCELED_CLOSING: 'SuggestAppsDialog.State.CANCELED_CLOSING' | 115 CANCELED_CLOSING: 'SuggestAppsDialog.State.CANCELED_CLOSING' |
115 }; | 116 }; |
116 Object.freeze(SuggestAppsDialog.State); | 117 Object.freeze(SuggestAppsDialog.State); |
117 | 118 |
118 /** | 119 /** |
119 * @enum {string} | 120 * @enum {string} |
120 * @const | 121 * @const |
121 */ | 122 */ |
122 SuggestAppsDialog.Result = { | 123 SuggestAppsDialog.Result = { |
123 // Install is done. The install app should be opened. | 124 // Install is done. The install app should be opened. |
124 INSTALL_SUCCESSFUL: 'SuggestAppsDialog.Result.INSTALL_SUCCESSFUL', | 125 INSTALL_SUCCESSFUL: 'SuggestAppsDialog.Result.INSTALL_SUCCESSFUL', |
125 // User cancelled the suggest app dialog. No message should be shown. | 126 // User cancelled the suggest app dialog. No message should be shown. |
126 USER_CANCELL: 'SuggestAppsDialog.Result.USER_CANCELL', | 127 USER_CANCELL: 'SuggestAppsDialog.Result.USER_CANCELL', |
128 // User clicked the link to web store so the dialog is closed. | |
129 WEBSTORE_LINK_OPENED: 'SuggestAppsDialog.Result.WEBSTORE_LINK_OPENED', | |
127 // Failed to load the widget. Error message should be shown. | 130 // Failed to load the widget. Error message should be shown. |
128 FAILED: 'SuggestAppsDialog.Result.FAILED' | 131 FAILED: 'SuggestAppsDialog.Result.FAILED' |
129 }; | 132 }; |
130 Object.freeze(SuggestAppsDialog.Result); | 133 Object.freeze(SuggestAppsDialog.Result); |
131 | 134 |
132 /** | 135 /** |
133 * @override | 136 * @override |
134 */ | 137 */ |
135 SuggestAppsDialog.prototype.onInputFocus = function() { | 138 SuggestAppsDialog.prototype.onInputFocus = function() { |
136 this.webviewContainer_.select(); | 139 this.webviewContainer_.select(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) { | 194 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) { |
192 console.error('Invalid state.'); | 195 console.error('Invalid state.'); |
193 return; | 196 return; |
194 } | 197 } |
195 | 198 |
196 this.extension_ = extension; | 199 this.extension_ = extension; |
197 this.mimeType_ = mime; | 200 this.mimeType_ = mime; |
198 this.onDialogClosed_ = onDialogClosed; | 201 this.onDialogClosed_ = onDialogClosed; |
199 this.state_ = SuggestAppsDialog.State.INITIALIZING; | 202 this.state_ = SuggestAppsDialog.State.INITIALIZING; |
200 | 203 |
204 metrics.recordUserAction('SuggestApps.ShowDialog'); | |
205 metrics.startInterval('SuggestApps.LoadTime'); | |
206 | |
201 // Makes it sure that the initialization is completed. | 207 // Makes it sure that the initialization is completed. |
202 this.initializationTask_.run(function() { | 208 this.initializationTask_.run(function() { |
203 if (!this.accessToken_) { | 209 if (!this.accessToken_) { |
204 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; | 210 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; |
205 this.onHide_(); | 211 this.onHide_(); |
206 return; | 212 return; |
207 } | 213 } |
208 | 214 |
209 var title = str('SUGGEST_DIALOG_TITLE'); | 215 var title = str('SUGGEST_DIALOG_TITLE'); |
210 | 216 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 260 |
255 /** | 261 /** |
256 * Called when the 'See more...' link is clicked to be navigated to Webstore. | 262 * Called when the 'See more...' link is clicked to be navigated to Webstore. |
257 * @param {Event} e Event. | 263 * @param {Event} e Event. |
258 * @private | 264 * @private |
259 */ | 265 */ |
260 SuggestAppsDialog.prototype.onWebstoreLinkClicked_ = function(e) { | 266 SuggestAppsDialog.prototype.onWebstoreLinkClicked_ = function(e) { |
261 var webStoreUrl = | 267 var webStoreUrl = |
262 FileTasks.createWebStoreLink(this.extension_, this.mimeType_); | 268 FileTasks.createWebStoreLink(this.extension_, this.mimeType_); |
263 chrome.windows.create({url: webStoreUrl}); | 269 chrome.windows.create({url: webStoreUrl}); |
270 this.state_ = SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING; | |
264 this.hide(); | 271 this.hide(); |
265 }; | 272 }; |
266 | 273 |
267 /** | 274 /** |
268 * Called when the widget is loaded successfully. | 275 * Called when the widget is loaded successfully. |
269 * @param {Event} event Event. | 276 * @param {Event} event Event. |
270 * @private | 277 * @private |
271 */ | 278 */ |
272 SuggestAppsDialog.prototype.onWidgetLoaded_ = function(event) { | 279 SuggestAppsDialog.prototype.onWidgetLoaded_ = function(event) { |
280 metrics.recordInterval('SuggestApps.LoadTime'); | |
281 metrics.recordEnum('SuggestApps.Load', 0, 3); // Load success. | |
282 | |
273 this.frame_.classList.remove('show-spinner'); | 283 this.frame_.classList.remove('show-spinner'); |
274 this.state_ = SuggestAppsDialog.State.INITIALIZED; | 284 this.state_ = SuggestAppsDialog.State.INITIALIZED; |
275 | 285 |
276 this.webview_.focus(); | 286 this.webview_.focus(); |
277 }; | 287 }; |
278 | 288 |
279 /** | 289 /** |
280 * Called when the widget is failed to load. | 290 * Called when the widget is failed to load. |
281 * @param {Event} event Event. | 291 * @param {Event} event Event. |
282 * @private | 292 * @private |
283 */ | 293 */ |
284 SuggestAppsDialog.prototype.onWidgetLoadFailed_ = function(event) { | 294 SuggestAppsDialog.prototype.onWidgetLoadFailed_ = function(event) { |
295 metrics.recordEnum('SuggestApps.Load', 1, 2); | |
296 metrics.recordEnum('SuggestApps.Load', 2, 3); // Load failure. | |
297 | |
285 this.frame_.classList.remove('show-spinner'); | 298 this.frame_.classList.remove('show-spinner'); |
286 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; | 299 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; |
287 | 300 |
288 this.hide(); | 301 this.hide(); |
289 }; | 302 }; |
290 | 303 |
291 /** | 304 /** |
292 * Called when the connection status is changed. | 305 * Called when the connection status is changed. |
293 * @param {util.DriveConnectionType} connectionType Current connection type. | 306 * @param {util.DriveConnectionType} connectionType Current connection type. |
294 */ | 307 */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 341 |
329 this.frame_.classList.remove('show-spinner'); | 342 this.frame_.classList.remove('show-spinner'); |
330 this.state_ = success ? | 343 this.state_ = success ? |
331 SuggestAppsDialog.State.INSTALLED_CLOSING : | 344 SuggestAppsDialog.State.INSTALLED_CLOSING : |
332 SuggestAppsDialog.State.INITIALIZED; // Back to normal state. | 345 SuggestAppsDialog.State.INITIALIZED; // Back to normal state. |
333 this.webviewClient_.onInstallCompleted(success, this.installingItemId_); | 346 this.webviewClient_.onInstallCompleted(success, this.installingItemId_); |
334 this.installingItemId_ = null; | 347 this.installingItemId_ = null; |
335 | 348 |
336 switch (result) { | 349 switch (result) { |
337 case AppInstaller.Result.SUCCESS: | 350 case AppInstaller.Result.SUCCESS: |
351 metrics.recordEnum('SuggestApps.Install', 0, 3); | |
mtomasz
2013/10/15 07:30:30
metrics.recordEnum with enums is easier to read th
yoshiki
2013/10/15 07:47:03
Done.
| |
338 this.hide(); | 352 this.hide(); |
339 break; | 353 break; |
340 case AppInstaller.Result.CANCELLED: | 354 case AppInstaller.Result.CANCELLED: |
341 // User cancelled the installation. Do nothing. | 355 // User cancelled the installation. Do nothing. |
356 metrics.recordEnum('SuggestApps.Install', 1, 3); | |
342 break; | 357 break; |
343 case AppInstaller.Result.ERROR: | 358 case AppInstaller.Result.ERROR: |
344 fileManager.error.show(str('SUGGEST_DIALOG_INSTALLATION_FAILED')); | 359 fileManager.error.show(str('SUGGEST_DIALOG_INSTALLATION_FAILED')); |
360 metrics.recordEnum('SuggestApps.Install', 2, 3); | |
345 break; | 361 break; |
346 } | 362 } |
347 }; | 363 }; |
348 | 364 |
349 /** | 365 /** |
350 * @override | 366 * @override |
351 */ | 367 */ |
352 SuggestAppsDialog.prototype.hide = function(opt_originalOnHide) { | 368 SuggestAppsDialog.prototype.hide = function(opt_originalOnHide) { |
353 switch (this.state_) { | 369 switch (this.state_) { |
354 case SuggestAppsDialog.State.INSTALLING: | 370 case SuggestAppsDialog.State.INSTALLING: |
355 // Install is being aborted. Send the failure result. | 371 // Install is being aborted. Send the failure result. |
356 // Cancels the install. | 372 // Cancels the install. |
357 if (this.webviewClient_) | 373 if (this.webviewClient_) |
358 this.webviewClient_.onInstallCompleted(false, this.installingItemId_); | 374 this.webviewClient_.onInstallCompleted(false, this.installingItemId_); |
359 this.installingItemId_ = null; | 375 this.installingItemId_ = null; |
360 | 376 |
361 // Assumes closing the dialog as canceling the install. | 377 // Assumes closing the dialog as canceling the install. |
362 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 378 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
363 break; | 379 break; |
380 case SuggestAppsDialog.State.INITIALIZING: | |
381 metrics.recordEnum('SuggestApps.Load', 1, 3); // Load cancelled. | |
mtomasz
2013/10/15 07:30:30
(like here is good)
| |
382 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | |
383 break; | |
364 case SuggestAppsDialog.State.INSTALLED_CLOSING: | 384 case SuggestAppsDialog.State.INSTALLED_CLOSING: |
365 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: | 385 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: |
386 case SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING: | |
366 // Do nothing. | 387 // Do nothing. |
367 break; | 388 break; |
368 case SuggestAppsDialog.State.INITIALIZED: | 389 case SuggestAppsDialog.State.INITIALIZED: |
369 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 390 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
370 break; | 391 break; |
371 default: | 392 default: |
372 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 393 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
373 console.error('Invalid state.'); | 394 console.error('Invalid state.'); |
374 } | 395 } |
375 | 396 |
(...skipping 18 matching lines...) Expand all Loading... | |
394 */ | 415 */ |
395 SuggestAppsDialog.prototype.onHide_ = function(opt_originalOnHide) { | 416 SuggestAppsDialog.prototype.onHide_ = function(opt_originalOnHide) { |
396 // Calls the callback after the dialog hides. | 417 // Calls the callback after the dialog hides. |
397 if (opt_originalOnHide) | 418 if (opt_originalOnHide) |
398 opt_originalOnHide(); | 419 opt_originalOnHide(); |
399 | 420 |
400 var result; | 421 var result; |
401 switch (this.state_) { | 422 switch (this.state_) { |
402 case SuggestAppsDialog.State.INSTALLED_CLOSING: | 423 case SuggestAppsDialog.State.INSTALLED_CLOSING: |
403 result = SuggestAppsDialog.Result.INSTALL_SUCCESSFUL; | 424 result = SuggestAppsDialog.Result.INSTALL_SUCCESSFUL; |
425 metrics.recordEnum('SuggestApps.CloseDialog', 1, 4); | |
404 break; | 426 break; |
405 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: | 427 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: |
406 result = SuggestAppsDialog.Result.FAILED; | 428 result = SuggestAppsDialog.Result.FAILED; |
407 break; | 429 break; |
408 case SuggestAppsDialog.State.CANCELED_CLOSING: | 430 case SuggestAppsDialog.State.CANCELED_CLOSING: |
409 result = SuggestAppsDialog.Result.USER_CANCELL; | 431 result = SuggestAppsDialog.Result.USER_CANCELL; |
432 metrics.recordEnum('SuggestApps.CloseDialog', 2, 4); | |
433 break; | |
434 case SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING: | |
435 result = SuggestAppsDialog.Result.WEBSTORE_LINK_OPENED; | |
436 metrics.recordEnum('SuggestApps.CloseDialog', 3, 4); | |
410 break; | 437 break; |
411 default: | 438 default: |
412 result = SuggestAppsDialog.Result.USER_CANCELL; | 439 result = SuggestAppsDialog.Result.USER_CANCELL; |
440 metrics.recordEnum('SuggestApps.CloseDialog', 0, 4); | |
413 console.error('Invalid state.'); | 441 console.error('Invalid state.'); |
414 } | 442 } |
415 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; | 443 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; |
416 | 444 |
417 this.onDialogClosed_(result); | 445 this.onDialogClosed_(result); |
418 }; | 446 }; |
OLD | NEW |