зеркало из https://github.com/mozilla/gecko-dev.git
Bug 820733 - B2G MMS: Don't deactivate the MMS network so often which is a burden for consecutive MMS HTTP requests. r=vicamo
This commit is contained in:
Родитель
bf032a32a6
Коммит
1a041ed851
|
@ -39,6 +39,7 @@ const CONFIG_SEND_REPORT_DEFAULT_YES = 2;
|
|||
const CONFIG_SEND_REPORT_ALWAYS = 3;
|
||||
|
||||
const TIME_TO_BUFFER_MMS_REQUESTS = 30000;
|
||||
const TIME_TO_RELEASE_MMS_CONNECTION = 30000;
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gpps",
|
||||
"@mozilla.org/network/protocol-proxy-service;1",
|
||||
|
@ -129,6 +130,9 @@ MmsService.prototype = {
|
|||
mmsRequestQueue: [],
|
||||
timerToClearQueue: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
|
||||
|
||||
timerToReleaseMmsConnection: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
|
||||
isProxyFilterRegistered: false,
|
||||
|
||||
/**
|
||||
* Calculate Whether or not should we enable X-Mms-Report-Allowed.
|
||||
*
|
||||
|
@ -147,6 +151,20 @@ MmsService.prototype = {
|
|||
return config >= CONFIG_SEND_REPORT_DEFAULT_YES;
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback when |timerToClearQueue| is timeout or cancelled by shutdown.
|
||||
*/
|
||||
timerToClearQueueCb: function timerToClearQueueCb() {
|
||||
debug("timerToClearQueueCb: clear the buffered MMS requests due to " +
|
||||
"the timeout or cancel: number: " + this.mmsRequestQueue.length);
|
||||
while (this.mmsRequestQueue.length) {
|
||||
let mmsRequest = this.mmsRequestQueue.shift();
|
||||
if (mmsRequest.callback) {
|
||||
mmsRequest.callback(0, null);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Acquire the MMS network connection.
|
||||
*
|
||||
|
@ -176,27 +194,41 @@ MmsService.prototype = {
|
|||
|
||||
// Set a timer to clear the buffered MMS requests if the
|
||||
// MMS network fails to be connected within a time period.
|
||||
this.timerToClearQueue.initWithCallback(function timerToClearQueueCb() {
|
||||
debug("timerToClearQueueCb: clear the buffered MMS requests due to " +
|
||||
"the timeout: number: " + this.mmsRequestQueue.length);
|
||||
while (this.mmsRequestQueue.length) {
|
||||
let mmsRequest = this.mmsRequestQueue.shift();
|
||||
if (mmsRequest.callback) {
|
||||
mmsRequest.callback(0, null);
|
||||
}
|
||||
}
|
||||
}.bind(this), TIME_TO_BUFFER_MMS_REQUESTS, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
this.timerToClearQueue.
|
||||
initWithCallback(this.timerToClearQueueCb.bind(this),
|
||||
TIME_TO_BUFFER_MMS_REQUESTS,
|
||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.mmsConnRefCount) {
|
||||
if (!this.mmsConnRefCount && !this.isProxyFilterRegistered) {
|
||||
debug("acquireMmsConnection: register the MMS proxy filter.");
|
||||
gpps.registerFilter(this, 0);
|
||||
this.isProxyFilterRegistered = true;
|
||||
}
|
||||
this.mmsConnRefCount++;
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback when |timerToReleaseMmsConnection| is timeout or cancelled by shutdown.
|
||||
*/
|
||||
timerToReleaseMmsConnectionCb: function timerToReleaseMmsConnectionCb() {
|
||||
if (this.mmsConnRefCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug("timerToReleaseMmsConnectionCb: " +
|
||||
"unregister the MMS proxy filter and deactivate the MMS data call.");
|
||||
if (this.isProxyFilterRegistered) {
|
||||
gpps.unregisterFilter(this);
|
||||
this.isProxyFilterRegistered = false;
|
||||
}
|
||||
if (this.mmsNetworkConnected) {
|
||||
gRIL.deactivateDataCallByType("mms");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Release the MMS network connection.
|
||||
*/
|
||||
|
@ -205,10 +237,12 @@ MmsService.prototype = {
|
|||
if (this.mmsConnRefCount <= 0) {
|
||||
this.mmsConnRefCount = 0;
|
||||
|
||||
debug("releaseMmsConnection: " +
|
||||
"unregister the MMS proxy filter and deactivate the MMS data call.");
|
||||
gpps.unregisterFilter(this);
|
||||
gRIL.deactivateDataCallByType("mms");
|
||||
// Set a timer to delay the release of MMS network connection,
|
||||
// since the MMS requests often come consecutively in a short time.
|
||||
this.timerToReleaseMmsConnection.
|
||||
initWithCallback(this.timerToReleaseMmsConnectionCb.bind(this),
|
||||
TIME_TO_RELEASE_MMS_CONNECTION,
|
||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -711,12 +745,9 @@ MmsService.prototype = {
|
|||
Services.prefs.removeObserver(name, this);
|
||||
}, this);
|
||||
this.timerToClearQueue.cancel();
|
||||
while (this.mmsRequestQueue.length) {
|
||||
let mmsRequest = this.mmsRequestQueue.shift();
|
||||
if (mmsRequest.callback) {
|
||||
mmsRequest.callback(0, null);
|
||||
}
|
||||
}
|
||||
this.timerToClearQueueCb();
|
||||
this.timerToReleaseMmsConnection.cancel();
|
||||
this.timerToReleaseMmsConnectionCb();
|
||||
break;
|
||||
}
|
||||
case kPrefenceChangedObserverTopic: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче