mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 887699 - Part 3/4 Fix access of websocket channel and TCPSocket to NetworkStats API. r=jduell,gene
This commit is contained in:
parent
d55b453453
commit
9391a1773f
@ -167,7 +167,7 @@ TCPSocket.prototype = {
|
||||
_txBytes: 0,
|
||||
_rxBytes: 0,
|
||||
_appId: Ci.nsIScriptSecurityManager.NO_APP_ID,
|
||||
_connectionType: Ci.nsINetworkInterface.NETWORK_TYPE_UNKNOWN,
|
||||
_activeNetwork: null,
|
||||
#endif
|
||||
|
||||
// Public accessors.
|
||||
@ -347,7 +347,7 @@ TCPSocket.prototype = {
|
||||
LOG("Error: Ci.nsINetworkStatsServiceProxy service is not available.");
|
||||
return;
|
||||
}
|
||||
nssProxy.saveAppStats(this._appId, this._connectionType, Date.now(),
|
||||
nssProxy.saveAppStats(this._appId, this._activeNetwork, Date.now(),
|
||||
this._rxBytes, this._txBytes);
|
||||
|
||||
// Reset the counters once the statistics is saved to NetworkStatsServiceProxy.
|
||||
@ -527,12 +527,12 @@ TCPSocket.prototype = {
|
||||
that._initStream(that._binaryType);
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// Set _connectionType, which is only required for network statistics.
|
||||
// Set _activeNetwork, which is only required for network statistics.
|
||||
// Note that nsINetworkManager, as well as nsINetworkStatsServiceProxy, is
|
||||
// Gonk-specific.
|
||||
let networkManager = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
|
||||
if (networkManager && networkManager.active) {
|
||||
that._connectionType = networkManager.active.type;
|
||||
if (networkManager) {
|
||||
that._activeNetwork = networkManager.active;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -53,7 +53,6 @@
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "nsINetworkManager.h"
|
||||
#include "nsINetworkStatsServiceProxy.h"
|
||||
#endif
|
||||
|
||||
@ -967,7 +966,6 @@ WebSocketChannel::WebSocketChannel() :
|
||||
mCountRecv(0),
|
||||
mCountSent(0),
|
||||
mAppId(0),
|
||||
mConnectionType(NETWORK_NO_TYPE),
|
||||
mIsInBrowser(false)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread");
|
||||
@ -1082,9 +1080,9 @@ WebSocketChannel::BeginOpen()
|
||||
NS_GetAppInfo(localChannel, &mAppId, &mIsInBrowser);
|
||||
}
|
||||
|
||||
// obtain active connection type
|
||||
// obtain active network
|
||||
if (mAppId != NECKO_NO_APP_ID) {
|
||||
GetConnectionType(&mConnectionType);
|
||||
GetActiveNetwork();
|
||||
}
|
||||
|
||||
rv = localChannel->AsyncOpen(this, mHttpChannel);
|
||||
@ -3274,7 +3272,7 @@ WebSocketChannel::OnDataAvailable(nsIRequest *aRequest,
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebSocketChannel::GetConnectionType(int32_t *type)
|
||||
WebSocketChannel::GetActiveNetwork()
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -3283,15 +3281,11 @@ WebSocketChannel::GetConnectionType(int32_t *type)
|
||||
nsCOMPtr<nsINetworkManager> networkManager = do_GetService("@mozilla.org/network/manager;1", &result);
|
||||
|
||||
if (NS_FAILED(result) || !networkManager) {
|
||||
*type = NETWORK_NO_TYPE;
|
||||
mActiveNetwork = nullptr;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINetworkInterface> networkInterface;
|
||||
result = networkManager->GetActive(getter_AddRefs(networkInterface));
|
||||
|
||||
if (networkInterface) {
|
||||
result = networkInterface->GetType(type);
|
||||
}
|
||||
result = networkManager->GetActive(getter_AddRefs(mActiveNetwork));
|
||||
|
||||
return NS_OK;
|
||||
#else
|
||||
@ -3303,9 +3297,8 @@ nsresult
|
||||
WebSocketChannel::SaveNetworkStats(bool enforce)
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// Check if the connection type and app id are valid.
|
||||
if(mConnectionType == NETWORK_NO_TYPE ||
|
||||
mAppId == NECKO_NO_APP_ID) {
|
||||
// Check if the active network and app id are valid.
|
||||
if(!mActiveNetwork || mAppId == NECKO_NO_APP_ID) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -3329,7 +3322,7 @@ WebSocketChannel::SaveNetworkStats(bool enforce)
|
||||
return rv;
|
||||
}
|
||||
|
||||
mNetworkStatsServiceProxy->SaveAppStats(mAppId, mConnectionType, PR_Now() / 1000,
|
||||
mNetworkStatsServiceProxy->SaveAppStats(mAppId, mActiveNetwork, PR_Now() / 1000,
|
||||
mCountRecv, mCountSent, nullptr);
|
||||
|
||||
// Reset the counters after saving.
|
||||
|
@ -18,6 +18,10 @@
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "BaseWebSocketChannel.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "nsINetworkManager.h"
|
||||
#endif
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsDeque.h"
|
||||
@ -254,16 +258,17 @@ private:
|
||||
// These members are used for network per-app metering (bug 855949)
|
||||
// Currently, they are only available on gonk.
|
||||
public:
|
||||
const static int32_t NETWORK_NO_TYPE = -1; // default conntection type
|
||||
const static uint64_t NETWORK_STATS_THRESHOLD = 65536;
|
||||
|
||||
private:
|
||||
uint64_t mCountRecv;
|
||||
uint64_t mCountSent;
|
||||
uint32_t mAppId;
|
||||
int32_t mConnectionType;
|
||||
bool mIsInBrowser;
|
||||
nsresult GetConnectionType(int32_t *);
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
nsCOMPtr<nsINetworkInterface> mActiveNetwork;
|
||||
#endif
|
||||
nsresult GetActiveNetwork();
|
||||
nsresult SaveNetworkStats(bool);
|
||||
void CountRecvBytes(uint64_t recvBytes)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user