From 7f01ae5f4d8de625766523fbf730f646e0dff05a Mon Sep 17 00:00:00 2001 From: Shih-Chiang Chien Date: Fri, 25 Oct 2013 20:04:57 -0400 Subject: [PATCH] Bug 926289 - Part 4, Separate recording status for each process. r=vingtetun,jesup. --- b2g/chrome/content/shell.js | 65 ++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 610e2fea5bf..e80e828aa7f 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -1259,49 +1259,69 @@ window.addEventListener('ContentStart', function update_onContentStart() { })(); (function recordingStatusTracker() { - let gRecordingActiveCount = 0; + // Recording status is tracked per process with following data structure: + // {: {count: , + // requestURL: , + // isApp: , + // audioCount: , + // videoCount: }} let gRecordingActiveProcesses = {}; let recordingHandler = function(aSubject, aTopic, aData) { - let oldCount = gRecordingActiveCount; - - let processId = (!aSubject) ? 'main' - : aSubject.QueryInterface(Ci.nsIPropertyBag2).get('childID'); + let props = aSubject.QueryInterface(Ci.nsIPropertyBag2); + let processId = (props.hasKey('childID')) ? props.get('childID') + : 'main'; if (processId && !gRecordingActiveProcesses.hasOwnProperty(processId)) { - gRecordingActiveProcesses[processId] = 0; + gRecordingActiveProcesses[processId] = {count: 0, + requestURL: props.get('requestURL'), + isApp: props.get('isApp'), + audioCount: 0, + videoCount: 0 }; } let currentActive = gRecordingActiveProcesses[processId]; + let wasActive = (currentActive['count'] > 0); + let wasAudioActive = (currentActive['audioCount'] > 0); + let wasVideoActive = (currentActive['videoCount'] > 0); + switch (aData) { case 'starting': - gRecordingActiveCount++; - currentActive++; + currentActive['count']++; + currentActive['audioCount'] += (props.get('isAudio')) ? 1 : 0; + currentActive['videoCount'] += (props.get('isVideo')) ? 1 : 0; break; case 'shutdown': - // Bug 928206 will make shutdown be sent even if no starting. - if (currentActive > 0) { - gRecordingActiveCount--; - currentActive--; - } + currentActive['count']--; + currentActive['audioCount'] -= (props.get('isAudio')) ? 1 : 0; + currentActive['videoCount'] -= (props.get('isVideo')) ? 1 : 0; break; case 'content-shutdown': - gRecordingActiveCount -= currentActive; - currentActive = 0; + currentActive['count'] = 0; + currentActive['audioCount'] = 0; + currentActive['videoCount'] = 0; break; } - if (currentActive > 0) { + if (currentActive['count'] > 0) { gRecordingActiveProcesses[processId] = currentActive; } else { delete gRecordingActiveProcesses[processId]; } - // We need to track changes from N <-> 0 - if ((oldCount === 0 && gRecordingActiveCount > 0) || - (gRecordingActiveCount === 0 && oldCount > 0)) { + // We need to track changes if any active state is changed. + let isActive = (currentActive['count'] > 0); + let isAudioActive = (currentActive['audioCount'] > 0); + let isVideoActive = (currentActive['videoCount'] > 0); + if ((isActive != wasActive) || + (isAudioActive != wasAudioActive) || + (isVideoActive != wasVideoActive)) { shell.sendChromeEvent({ type: 'recording-status', - active: (gRecordingActiveCount > 0) + active: isActive, + requestURL: currentActive['requestURL'], + isApp: currentActive['isApp'], + isAudio: isAudioActive, + isVideo: isVideoActive }); } }; @@ -1310,9 +1330,8 @@ window.addEventListener('ContentStart', function update_onContentStart() { Services.obs.addObserver(function(aSubject, aTopic, aData) { // send additional recording events if content process is being killed - let props = aSubject.QueryInterface(Ci.nsIPropertyBag2); - let childId = aSubject.get('childID'); - if (gRecordingActiveProcesses.hasOwnProperty(childId) >= 0) { + let processId = aSubject.QueryInterface(Ci.nsIPropertyBag2).get('childID'); + if (gRecordingActiveProcesses.hasOwnProperty(processId)) { Services.obs.notifyObservers(aSubject, 'recording-device-ipc-events', 'content-shutdown'); } }, 'ipc:content-shutdown', false);