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 SuggestAppsDialog.Metrics.recordShowDialog(); |
| 205 SuggestAppsDialog.Metrics.startLoad(); |
| 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 SuggestAppsDialog.Metrics.finishLoad(); |
| 281 SuggestAppsDialog.Metrics.recordLoad( |
| 282 SuggestAppsDialog.Metrics.LOAD.SUCCEEDED); |
| 283 |
273 this.frame_.classList.remove('show-spinner'); | 284 this.frame_.classList.remove('show-spinner'); |
274 this.state_ = SuggestAppsDialog.State.INITIALIZED; | 285 this.state_ = SuggestAppsDialog.State.INITIALIZED; |
275 | 286 |
276 this.webview_.focus(); | 287 this.webview_.focus(); |
277 }; | 288 }; |
278 | 289 |
279 /** | 290 /** |
280 * Called when the widget is failed to load. | 291 * Called when the widget is failed to load. |
281 * @param {Event} event Event. | 292 * @param {Event} event Event. |
282 * @private | 293 * @private |
283 */ | 294 */ |
284 SuggestAppsDialog.prototype.onWidgetLoadFailed_ = function(event) { | 295 SuggestAppsDialog.prototype.onWidgetLoadFailed_ = function(event) { |
| 296 SuggestAppsDialog.Metrics.recordLoad(SuggestAppsDialog.Metrics.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 SuggestAppsDialog.Metrics.recordInstall( |
| 352 SuggestAppsDialog.Metrics.INSTALL.SUCCESS); |
338 this.hide(); | 353 this.hide(); |
339 break; | 354 break; |
340 case AppInstaller.Result.CANCELLED: | 355 case AppInstaller.Result.CANCELLED: |
| 356 SuggestAppsDialog.Metrics.recordInstall( |
| 357 SuggestAppsDialog.Metrics.INSTALL.CANCELLED); |
341 // User cancelled the installation. Do nothing. | 358 // User cancelled the installation. Do nothing. |
342 break; | 359 break; |
343 case AppInstaller.Result.ERROR: | 360 case AppInstaller.Result.ERROR: |
| 361 SuggestAppsDialog.Metrics.recordInstall( |
| 362 SuggestAppsDialog.Metrics.INSTALL.FAILED); |
344 fileManager.error.show(str('SUGGEST_DIALOG_INSTALLATION_FAILED')); | 363 fileManager.error.show(str('SUGGEST_DIALOG_INSTALLATION_FAILED')); |
345 break; | 364 break; |
346 } | 365 } |
347 }; | 366 }; |
348 | 367 |
349 /** | 368 /** |
350 * @override | 369 * @override |
351 */ | 370 */ |
352 SuggestAppsDialog.prototype.hide = function(opt_originalOnHide) { | 371 SuggestAppsDialog.prototype.hide = function(opt_originalOnHide) { |
353 switch (this.state_) { | 372 switch (this.state_) { |
354 case SuggestAppsDialog.State.INSTALLING: | 373 case SuggestAppsDialog.State.INSTALLING: |
355 // Install is being aborted. Send the failure result. | 374 // Install is being aborted. Send the failure result. |
356 // Cancels the install. | 375 // Cancels the install. |
357 if (this.webviewClient_) | 376 if (this.webviewClient_) |
358 this.webviewClient_.onInstallCompleted(false, this.installingItemId_); | 377 this.webviewClient_.onInstallCompleted(false, this.installingItemId_); |
359 this.installingItemId_ = null; | 378 this.installingItemId_ = null; |
360 | 379 |
361 // Assumes closing the dialog as canceling the install. | 380 // Assumes closing the dialog as canceling the install. |
362 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 381 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
363 break; | 382 break; |
| 383 case SuggestAppsDialog.State.INITIALIZING: |
| 384 SuggestAppsDialog.Metrics.recordLoad( |
| 385 SuggestAppsDialog.Metrics.LOAD.CANCELLED); |
| 386 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
| 387 break; |
364 case SuggestAppsDialog.State.INSTALLED_CLOSING: | 388 case SuggestAppsDialog.State.INSTALLED_CLOSING: |
365 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: | 389 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: |
| 390 case SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING: |
366 // Do nothing. | 391 // Do nothing. |
367 break; | 392 break; |
368 case SuggestAppsDialog.State.INITIALIZED: | 393 case SuggestAppsDialog.State.INITIALIZED: |
369 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 394 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
370 break; | 395 break; |
371 default: | 396 default: |
372 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; | 397 this.state_ = SuggestAppsDialog.State.CANCELED_CLOSING; |
373 console.error('Invalid state.'); | 398 console.error('Invalid state.'); |
374 } | 399 } |
375 | 400 |
(...skipping 18 matching lines...) Expand all Loading... |
394 */ | 419 */ |
395 SuggestAppsDialog.prototype.onHide_ = function(opt_originalOnHide) { | 420 SuggestAppsDialog.prototype.onHide_ = function(opt_originalOnHide) { |
396 // Calls the callback after the dialog hides. | 421 // Calls the callback after the dialog hides. |
397 if (opt_originalOnHide) | 422 if (opt_originalOnHide) |
398 opt_originalOnHide(); | 423 opt_originalOnHide(); |
399 | 424 |
400 var result; | 425 var result; |
401 switch (this.state_) { | 426 switch (this.state_) { |
402 case SuggestAppsDialog.State.INSTALLED_CLOSING: | 427 case SuggestAppsDialog.State.INSTALLED_CLOSING: |
403 result = SuggestAppsDialog.Result.INSTALL_SUCCESSFUL; | 428 result = SuggestAppsDialog.Result.INSTALL_SUCCESSFUL; |
| 429 SuggestAppsDialog.Metrics.recordCloseDialog( |
| 430 SuggestAppsDialog.Metrics.CLOSE_DIALOG.ITEM_INSTALLED); |
404 break; | 431 break; |
405 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: | 432 case SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING: |
406 result = SuggestAppsDialog.Result.FAILED; | 433 result = SuggestAppsDialog.Result.FAILED; |
407 break; | 434 break; |
408 case SuggestAppsDialog.State.CANCELED_CLOSING: | 435 case SuggestAppsDialog.State.CANCELED_CLOSING: |
409 result = SuggestAppsDialog.Result.USER_CANCELL; | 436 result = SuggestAppsDialog.Result.USER_CANCELL; |
| 437 SuggestAppsDialog.Metrics.recordCloseDialog( |
| 438 SuggestAppsDialog.Metrics.CLOSE_DIALOG.USER_CANCELL); |
| 439 break; |
| 440 case SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING: |
| 441 result = SuggestAppsDialog.Result.WEBSTORE_LINK_OPENED; |
| 442 SuggestAppsDialog.Metrics.recordCloseDialog( |
| 443 SuggestAppsDialog.Metrics.CLOSE_DIALOG.WEB_STORE_LINK); |
410 break; | 444 break; |
411 default: | 445 default: |
412 result = SuggestAppsDialog.Result.USER_CANCELL; | 446 result = SuggestAppsDialog.Result.USER_CANCELL; |
| 447 SuggestAppsDialog.Metrics.recordCloseDialog( |
| 448 SuggestAppsDialog.Metrics.CLOSE_DIALOG.UNKNOWN_ERROR); |
413 console.error('Invalid state.'); | 449 console.error('Invalid state.'); |
414 } | 450 } |
415 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; | 451 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; |
416 | 452 |
417 this.onDialogClosed_(result); | 453 this.onDialogClosed_(result); |
418 }; | 454 }; |
| 455 |
| 456 /** |
| 457 * Utility methods and constants to record histograms. |
| 458 */ |
| 459 SuggestAppsDialog.Metrics = Object.freeze({ |
| 460 LOAD: Object.freeze({ |
| 461 SUCCEEDED: 0, |
| 462 CANCELLED: 1, |
| 463 FAILED: 2, |
| 464 }), |
| 465 |
| 466 /** |
| 467 * @param {SuggestAppsDialog.Metrics.LOAD} result Result of load. |
| 468 */ |
| 469 recordLoad: function(result) { |
| 470 if (0 <= result && result < 3) |
| 471 metrics.recordEnum('SuggestApps.Load', result, 3); |
| 472 }, |
| 473 |
| 474 CLOSE_DIALOG: Object.freeze({ |
| 475 UNKOWN_ERROR: 0, |
| 476 ITEM_INSTALLED: 1, |
| 477 USER_CANCELLED: 2, |
| 478 WEBSTORE_LINK_OPENED: 3, |
| 479 }), |
| 480 |
| 481 /** |
| 482 * @param {SuggestAppsDialog.Metrics.CLOSE_DIALOG} reason Reason of closing |
| 483 * dialog. |
| 484 */ |
| 485 recordCloseDialog: function(reason) { |
| 486 if (0 <= reason && reason < 4) |
| 487 metrics.recordEnum('SuggestApps.CloseDialog', reason, 4); |
| 488 }, |
| 489 |
| 490 INSTALL: Object.freeze({ |
| 491 SUCCEEDED: 0, |
| 492 CANCELLED: 1, |
| 493 FAILED: 2, |
| 494 }), |
| 495 |
| 496 /** |
| 497 * @param {SuggestAppsDialog.Metrics.INSTALL} result Result of installation. |
| 498 */ |
| 499 recordInstall: function(result) { |
| 500 if (0 <= result && result < 3) |
| 501 metrics.recordEnum('SuggestApps.Install', result, 3); |
| 502 }, |
| 503 |
| 504 recordShowDialog: function() { |
| 505 metrics.recordUserAction('SuggestApps.ShowDialog'); |
| 506 }, |
| 507 |
| 508 startLoad: function() { |
| 509 metrics.startInterval('SuggestApps.LoadTime'); |
| 510 }, |
| 511 |
| 512 finishLoad: function() { |
| 513 metrics.recordInterval('SuggestApps.LoadTime'); |
| 514 }, |
| 515 }); |
OLD | NEW |