Bug 922924 - Centralize the code for network per-app metering. r=jduell

This commit is contained in:
John Shih
2013-10-30 18:00:17 +08:00
parent 3372de5c3f
commit 7b09955c1b
7 changed files with 48 additions and 85 deletions

View File

@@ -965,8 +965,7 @@ WebSocketChannel::WebSocketChannel() :
mConnectionLogService(nullptr),
mCountRecv(0),
mCountSent(0),
mAppId(0),
mIsInBrowser(false)
mAppId(NECKO_NO_APP_ID)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread");
@@ -1075,15 +1074,16 @@ WebSocketChannel::BeginOpen()
return;
}
// obtain app info
if (localChannel) {
NS_GetAppInfo(localChannel, &mAppId, &mIsInBrowser);
bool isInBrowser;
NS_GetAppInfo(localChannel, &mAppId, &isInBrowser);
}
// obtain active network
#ifdef MOZ_WIDGET_GONK
if (mAppId != NECKO_NO_APP_ID) {
GetActiveNetwork();
NS_GetActiveNetworkInterface(mActiveNetwork);
}
#endif
rv = localChannel->AsyncOpen(this, mHttpChannel);
if (NS_FAILED(rv)) {
@@ -3271,28 +3271,6 @@ WebSocketChannel::OnDataAvailable(nsIRequest *aRequest,
return NS_OK;
}
nsresult
WebSocketChannel::GetActiveNetwork()
{
#ifdef MOZ_WIDGET_GONK
MOZ_ASSERT(NS_IsMainThread());
nsresult result;
nsCOMPtr<nsINetworkManager> networkManager = do_GetService("@mozilla.org/network/manager;1", &result);
if (NS_FAILED(result) || !networkManager) {
mActiveNetwork = nullptr;
return NS_ERROR_UNEXPECTED;
}
result = networkManager->GetActive(getter_AddRefs(mActiveNetwork));
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
nsresult
WebSocketChannel::SaveNetworkStats(bool enforce)
{