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

Unified Diff: ui/file_manager/video_player/js/cast/caster.js

Issue 760853003: Adds histograms for casting feature of Video Player (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..4e63b544747649970b4db7637c5b53ff9130c1d8 100644
--- a/ui/file_manager/video_player/js/cast/caster.js
+++ b/ui/file_manager/video_player/js/cast/caster.js
@@ -26,10 +26,15 @@ function initialize() {
}
CastExtensionDiscoverer.findInstalledExtension(function(foundId) {
- if (foundId)
+ if (foundId) {
loadCastAPI(initializeApi);
- else
+ } else {
console.info('No Google Cast extension is installed.');
+
+ metrics.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.EXTENSION_UNAVAILABLE,
+ metrics.CAST_EXTENSION.MAX_VALUE);
Ilya Sherman 2014/12/02 23:45:10 I strongly recommend creating a wrapper function f
yoshiki 2014/12/08 02:52:29 Done.
+ }
}.wrap());
}
@@ -50,6 +55,10 @@ function loadCastAPI(callback, opt_secondTry) {
document.body.removeChild(script);
if (opt_secondTry) {
+ metrics.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_INSTALLED_BUT_LOAD_FAILED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
+
// Shows error message and exits if it's the 2nd try.
console.error('Google Cast API extension load failed.');
return;
@@ -61,12 +70,17 @@ function loadCastAPI(callback, opt_secondTry) {
true, // Don't use installation prompt.
function() {
if (chrome.runtime.lastError) {
+ metrics.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_INSTALLATION_FAILED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
+
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 +89,59 @@ 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.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_INSTALLED_AND_LOADED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
+ } else {
+ metrics.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_AVAILABLE_AND_LOADED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
+ }
+
+ 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.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_LOAD_FAILED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
}.wrap(), 5000);
window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
clearTimeout(checkTimer);
- if (loaded)
- callback();
- else
+ if (loaded) {
+ executeCallback();
+ }
+ else {
+ metrics.recordEnum('CastExtensionStatus',
+ metrics.CAST_EXTENSION.API_LOAD_FAILED,
+ metrics.CAST_EXTENSION.MAX_VALUE);
+
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 +182,10 @@ function onReceiver(availability, receivers) {
receivers = [];
}
+ metrics.recordSmallCount('NumberOfCastDevices', receivers.length);
player.setCastList(receivers);
} else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) {
+ metrics.recordSmallCount('NumberOfCastDevices', 0);
player.setCastList([]);
} else {
console.error('Unexpected response in onReceiver.', arguments);

Powered by Google App Engine
This is Rietveld 408576698