| Index: ui/file_manager/video_player/js/cast/caster.js
|
| diff --git a/ui/file_manager/video_player/js/cast/caster.js b/ui/file_manager/video_player/js/cast/caster.js
|
| index cf718e256da983d8af8aa5d4e9066e61f41f26f3..e4a0d5203ba442441cc582ed865588d09c015bd6 100644
|
| --- a/ui/file_manager/video_player/js/cast/caster.js
|
| +++ b/ui/file_manager/video_player/js/cast/caster.js
|
| @@ -26,10 +26,14 @@ function initialize() {
|
| }
|
|
|
| CastExtensionDiscoverer.findInstalledExtension(function(foundId) {
|
| - if (foundId)
|
| + if (foundId) {
|
| loadCastAPI(initializeApi);
|
| - else
|
| + } else {
|
| console.info('No Google Cast extension is installed.');
|
| +
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.SKIPPED);
|
| + }
|
| }.wrap());
|
| }
|
|
|
| @@ -39,7 +43,7 @@ function initialize() {
|
| * The given callback is executes after the cast SDK extension is initialized.
|
| *
|
| * @param {function} callback Callback (executed asynchronously).
|
| - * @param {boolean=} opt_secondTry Spericy try if it's second call after
|
| + * @param {boolean=} opt_secondTry Specify true if it's the second call after
|
| * installation of Cast API extension.
|
| */
|
| function loadCastAPI(callback, opt_secondTry) {
|
| @@ -50,6 +54,9 @@ function loadCastAPI(callback, opt_secondTry) {
|
| document.body.removeChild(script);
|
|
|
| if (opt_secondTry) {
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED);
|
| +
|
| // Shows error message and exits if it's the 2nd try.
|
| console.error('Google Cast API extension load failed.');
|
| return;
|
| @@ -61,12 +68,16 @@ function loadCastAPI(callback, opt_secondTry) {
|
| true, // Don't use installation prompt.
|
| function() {
|
| if (chrome.runtime.lastError) {
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.INSTALLATION_FAILED);
|
| +
|
| console.error('Google Cast API extension installation error.',
|
| chrome.runtime.lastError.message);
|
| return;
|
| }
|
|
|
| console.info('Google Cast API extension installed.');
|
| +
|
| // Loads API again.
|
| setTimeout(loadCastAPI.bind(null, callback, true));
|
| }.wrap());
|
| @@ -75,31 +86,54 @@ function loadCastAPI(callback, opt_secondTry) {
|
| // Trys to load the cast API extention which is defined in manifest.json.
|
| script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js';
|
| script.addEventListener('error', onError);
|
| - script.addEventListener('load', onLoadCastExtension.bind(null, callback));
|
| + script.addEventListener(
|
| + 'load', onLoadCastExtension.bind(null, callback, opt_secondTry));
|
| document.body.appendChild(script);
|
| }
|
|
|
| /**
|
| * Loads the cast sdk extension.
|
| * @param {function()} callback Callback (executed asynchronously).
|
| + * @param {boolean=} opt_installationOccured True if the extension is just
|
| + * installed in this window. False or null if it's already installed.
|
| */
|
| -function onLoadCastExtension(callback) {
|
| +function onLoadCastExtension(callback, opt_installationOccured) {
|
| + var executeCallback = function() {
|
| + if (opt_installationOccured) {
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.INSTALLED_AND_LOADED);
|
| + } else {
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.LOADED);
|
| + }
|
| +
|
| + setTimeout(callback); // Runs asynchronously.
|
| + };
|
| +
|
| if(!chrome.cast || !chrome.cast.isAvailable) {
|
| var checkTimer = setTimeout(function() {
|
| console.error('Either "Google Cast API" or "Google Cast" extension ' +
|
| 'seems not to be installed?');
|
| +
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED);
|
| }.wrap(), 5000);
|
|
|
| window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
|
| clearTimeout(checkTimer);
|
|
|
| - if (loaded)
|
| - callback();
|
| - else
|
| + if (loaded) {
|
| + executeCallback();
|
| + } else {
|
| + metrics.recordCastAPIExtensionStatus(
|
| + metrics.CAST_API_EXTENSION_STATUS.LOAD_FAILED);
|
| +
|
| console.error('Google Cast extension load failed.', errorInfo);
|
| + }
|
| }.wrap();
|
| } else {
|
| - setTimeout(callback); // Runs asynchronously.
|
| + // Just executes the callback since the API is already loaded.
|
| + executeCallback();
|
| }
|
| }
|
|
|
| @@ -140,8 +174,10 @@ function onReceiver(availability, receivers) {
|
| receivers = [];
|
| }
|
|
|
| + metrics.recordNumberOfCastDevices(receivers.length);
|
| player.setCastList(receivers);
|
| } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) {
|
| + metrics.recordNumberOfCastDevices(0);
|
| player.setCastList([]);
|
| } else {
|
| console.error('Unexpected response in onReceiver.', arguments);
|
|
|