diff options
Diffstat (limited to 'netwerk')
96 files changed, 802 insertions, 2397 deletions
diff --git a/netwerk/base/BackgroundFileSaver.cpp b/netwerk/base/BackgroundFileSaver.cpp index e4bc05826..b338c2a08 100644 --- a/netwerk/base/BackgroundFileSaver.cpp +++ b/netwerk/base/BackgroundFileSaver.cpp @@ -9,7 +9,6 @@ #include "ScopedNSSTypes.h" #include "mozilla/Casting.h" #include "mozilla/Logging.h" -#include "mozilla/Telemetry.h" #include "nsCOMArray.h" #include "nsIAsyncInputStream.h" #include "nsIFile.h" @@ -85,7 +84,6 @@ private: //// BackgroundFileSaver uint32_t BackgroundFileSaver::sThreadCount = 0; -uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0; BackgroundFileSaver::BackgroundFileSaver() : mControlThread(nullptr) @@ -156,9 +154,6 @@ BackgroundFileSaver::Init() NS_ENSURE_SUCCESS(rv, rv); sThreadCount++; - if (sThreadCount > sTelemetryMaxThreadCount) { - sTelemetryMaxThreadCount = sThreadCount; - } return NS_OK; } @@ -793,16 +788,6 @@ BackgroundFileSaver::NotifySaveComplete() sThreadCount--; - // When there are no more active downloads, we consider the download session - // finished. We record the maximum number of concurrent downloads reached - // during the session in a telemetry histogram, and we reset the maximum - // thread counter for the next download session - if (sThreadCount == 0) { - Telemetry::Accumulate(Telemetry::BACKGROUNDFILESAVER_THREAD_COUNT, - sTelemetryMaxThreadCount); - sTelemetryMaxThreadCount = 0; - } - return NS_OK; } diff --git a/netwerk/base/BackgroundFileSaver.h b/netwerk/base/BackgroundFileSaver.h index 1fa9268f8..86d3a1ba7 100644 --- a/netwerk/base/BackgroundFileSaver.h +++ b/netwerk/base/BackgroundFileSaver.h @@ -61,15 +61,6 @@ public: */ static uint32_t sThreadCount; - /** - * Maximum number of worker threads reached during the current download session, - * used for telemetry. - * - * When there are no more worker threads running, we consider the download - * session finished, and this counter is reset. - */ - static uint32_t sTelemetryMaxThreadCount; - protected: virtual ~BackgroundFileSaver(); diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index ebe9d4703..d57f644df 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -67,6 +67,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, , mForcePreflight(false) , mIsPreflight(false) , mLoadTriggeredFromExternal(false) + , mIsFromProcessingFrameAttributes(false) { MOZ_ASSERT(mLoadingPrincipal); MOZ_ASSERT(mTriggeringPrincipal); @@ -241,6 +242,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow, , mForcePreflight(false) , mIsPreflight(false) , mLoadTriggeredFromExternal(false) + , mIsFromProcessingFrameAttributes(false) { // Top-level loads are never third-party // Grab the information we can out of the window. @@ -304,6 +306,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs) , mForcePreflight(rhs.mForcePreflight) , mIsPreflight(rhs.mIsPreflight) , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal) + , mIsFromProcessingFrameAttributes(rhs.mIsFromProcessingFrameAttributes) { } @@ -355,6 +358,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, , mForcePreflight(aForcePreflight) , mIsPreflight(aIsPreflight) , mLoadTriggeredFromExternal(aLoadTriggeredFromExternal) + , mIsFromProcessingFrameAttributes(false) { // Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal MOZ_ASSERT(mLoadingPrincipal || aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT); @@ -970,5 +974,19 @@ LoadInfo::GetIsTopLevelLoad(bool *aResult) return NS_OK; } +void +LoadInfo::SetIsFromProcessingFrameAttributes() +{ + mIsFromProcessingFrameAttributes = true; +} + +NS_IMETHODIMP +LoadInfo::GetIsFromProcessingFrameAttributes(bool *aIsFromProcessingFrameAttributes) +{ + MOZ_ASSERT(aIsFromProcessingFrameAttributes); + *aIsFromProcessingFrameAttributes = mIsFromProcessingFrameAttributes; + return NS_OK; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 2b1e8c9e8..a4ec25a9d 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -81,6 +81,7 @@ public: void SetIsPreflight(); void SetUpgradeInsecureRequests(); + void SetIsFromProcessingFrameAttributes(); private: // private constructor that is only allowed to be called from within @@ -157,6 +158,11 @@ private: bool mForcePreflight; bool mIsPreflight; bool mLoadTriggeredFromExternal; + + // Is true if this load was triggered by processing the attributes of the + // browsing context container. + // See nsILoadInfo.isFromProcessingFrameAttributes + bool mIsFromProcessingFrameAttributes; }; } // namespace net diff --git a/netwerk/base/Predictor.cpp b/netwerk/base/Predictor.cpp index e97b11d16..12e4eb415 100644 --- a/netwerk/base/Predictor.cpp +++ b/netwerk/base/Predictor.cpp @@ -294,26 +294,9 @@ Predictor::Action::OnCacheEntryAvailable(nsICacheEntry *entry, bool isNew, "Aborting.", this, result)); return NS_OK; } - Telemetry::AccumulateTimeDelta(Telemetry::PREDICTOR_WAIT_TIME, - mStartTime); - if (mPredict) { - bool predicted = mPredictor->PredictInternal(mPredictReason, entry, isNew, - mFullUri, mTargetURI, - mVerifier, mStackCount); - Telemetry::AccumulateTimeDelta( - Telemetry::PREDICTOR_PREDICT_WORK_TIME, mStartTime); - if (predicted) { - Telemetry::AccumulateTimeDelta( - Telemetry::PREDICTOR_PREDICT_TIME_TO_ACTION, mStartTime); - } else { - Telemetry::AccumulateTimeDelta( - Telemetry::PREDICTOR_PREDICT_TIME_TO_INACTION, mStartTime); - } - } else { + if (!mPredict) { mPredictor->LearnInternal(mLearnReason, entry, isNew, mFullUri, mTargetURI, mSourceURI); - Telemetry::AccumulateTimeDelta( - Telemetry::PREDICTOR_LEARN_WORK_TIME, mStartTime); } return NS_OK; @@ -1073,8 +1056,6 @@ Predictor::CalculateGlobalDegradation(uint32_t lastLoad) globalDegradation = mPageDegradationMax; } - Telemetry::Accumulate(Telemetry::PREDICTOR_GLOBAL_DEGRADATION, - globalDegradation); return globalDegradation; } @@ -1139,10 +1120,6 @@ Predictor::CalculateConfidence(uint32_t hitCount, uint32_t hitsPossible, confidence = std::max(confidence, 0); confidence = std::min(confidence, maxConfidence); - Telemetry::Accumulate(Telemetry::PREDICTOR_BASE_CONFIDENCE, baseConfidence); - Telemetry::Accumulate(Telemetry::PREDICTOR_SUBRESOURCE_DEGRADATION, - confidenceDegradation); - Telemetry::Accumulate(Telemetry::PREDICTOR_CONFIDENCE, confidence); return confidence; } @@ -2335,7 +2312,6 @@ Predictor::PrefetchListener::OnStopRequest(nsIRequest *aRequest, if (NS_FAILED(aStatusCode)) { return aStatusCode; } - Telemetry::AccumulateTimeDelta(Telemetry::PREDICTOR_PREFETCH_TIME, mStartTime); nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest); if (!httpChannel) { diff --git a/netwerk/base/TLSServerSocket.cpp b/netwerk/base/TLSServerSocket.cpp index 257a7f5da..97c7f5423 100644 --- a/netwerk/base/TLSServerSocket.cpp +++ b/netwerk/base/TLSServerSocket.cpp @@ -52,12 +52,12 @@ TLSServerSocket::SetSocketDefaults() SSL_OptionSet(mFD, SSL_SECURITY, true); SSL_OptionSet(mFD, SSL_HANDSHAKE_AS_CLIENT, false); SSL_OptionSet(mFD, SSL_HANDSHAKE_AS_SERVER, true); - + SSL_OptionSet(mFD, SSL_NO_CACHE, true); + // We don't currently notify the server API consumer of renegotiation events // (to revalidate peer certs, etc.), so disable it for now. SSL_OptionSet(mFD, SSL_ENABLE_RENEGOTIATION, SSL_RENEGOTIATE_NEVER); - SetSessionCache(true); SetSessionTickets(true); SetRequestClientCertificate(REQUEST_NEVER); @@ -172,18 +172,6 @@ TLSServerSocket::SetServerCert(nsIX509Cert* aCert) } NS_IMETHODIMP -TLSServerSocket::SetSessionCache(bool aEnabled) -{ - // If AsyncListen was already called (and set mListener), it's too late to set - // this. - if (NS_WARN_IF(mListener)) { - return NS_ERROR_IN_PROGRESS; - } - SSL_OptionSet(mFD, SSL_NO_CACHE, !aEnabled); - return NS_OK; -} - -NS_IMETHODIMP TLSServerSocket::SetSessionTickets(bool aEnabled) { // If AsyncListen was already called (and set mListener), it's too late to set diff --git a/netwerk/base/nsFileStreams.cpp b/netwerk/base/nsFileStreams.cpp index 6508b33b9..5a82dea1b 100644 --- a/netwerk/base/nsFileStreams.cpp +++ b/netwerk/base/nsFileStreams.cpp @@ -5,7 +5,7 @@ #include "ipc/IPCMessageUtils.h" -#if defined(XP_UNIX) || defined(XP_BEOS) +#if defined(XP_UNIX) #include <unistd.h> #elif defined(XP_WIN) #include <windows.h> @@ -97,14 +97,14 @@ nsFileStreamBase::SetEOF() if (mFD == nullptr) return NS_BASE_STREAM_CLOSED; -#if defined(XP_UNIX) || defined(XP_BEOS) +#if defined(XP_UNIX) // Some system calls require an EOF offset. int64_t offset; rv = Tell(&offset); if (NS_FAILED(rv)) return rv; #endif -#if defined(XP_UNIX) || defined(XP_BEOS) +#if defined(XP_UNIX) if (ftruncate(PR_FileDesc2NativeHandle(mFD), offset) != 0) { NS_ERROR("ftruncate failed"); return NS_ERROR_FAILURE; diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index bc609c317..fc1aadd93 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -740,4 +740,11 @@ interface nsILoadInfo : nsISupports * Note that the load for a sub-frame's document will return false here. */ [infallible] readonly attribute boolean isTopLevelLoad; + + /** + * This attribute will be true if this is a load triggered by + * https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes + * or https://html.spec.whatwg.org/multipage/obsolete.html#process-the-frame-attributes + */ + [infallible] readonly attribute boolean isFromProcessingFrameAttributes; }; diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index e13541acf..e0dc7d8e8 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -48,7 +48,6 @@ #include "mozilla/LoadInfo.h" #include "mozilla/net/NeckoCommon.h" #include "mozilla/Services.h" -#include "mozilla/Telemetry.h" #include "mozilla/net/DNS.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/net/NeckoChild.h" @@ -166,8 +165,6 @@ static const char kProfileDoChange[] = "profile-do-change"; uint32_t nsIOService::gDefaultSegmentSize = 4096; uint32_t nsIOService::gDefaultSegmentCount = 24; -bool nsIOService::sTelemetryEnabled = false; - bool nsIOService::sBlockToplevelDataUriNavigations = false; //////////////////////////////////////////////////////////////////////////////// @@ -185,9 +182,6 @@ nsIOService::nsIOService() , mNetworkLinkServiceInitialized(false) , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY) , mNetworkNotifyChanged(true) - , mLastOfflineStateChange(PR_IntervalNow()) - , mLastConnectivityChange(PR_IntervalNow()) - , mLastNetworkLinkChange(PR_IntervalNow()) , mNetTearingDownStarted(0) { } @@ -247,7 +241,6 @@ nsIOService::Init() else NS_WARNING("failed to get observer service"); - Preferences::AddBoolVarCache(&sTelemetryEnabled, "toolkit.telemetry.enabled", false); Preferences::AddBoolVarCache(&sBlockToplevelDataUriNavigations, "security.data_uri.block_toplevel_data_uri_navigations", false); Preferences::AddBoolVarCache(&mOfflineMirrorsConnectivity, OFFLINE_MIRRORS_CONNECTIVITY, true); @@ -789,7 +782,9 @@ nsIOService::NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI, // creating a new channel by calling NewChannel(). if (NS_FAILED(rv)) { rv = handler->NewChannel(aURI, getter_AddRefs(channel)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + return rv; + } // The protocol handler does not implement NewChannel2, so // maybe we need to wrap the channel (see comment in MaybeWrap // function). @@ -1066,7 +1061,6 @@ nsIOService::SetOffline(bool offline) if (mSocketTransportService) mSocketTransportService->SetOffline(true); - mLastOfflineStateChange = PR_IntervalNow(); if (observerService) observerService->NotifyObservers(subject, NS_IOSERVICE_OFFLINE_STATUS_TOPIC, @@ -1086,7 +1080,6 @@ nsIOService::SetOffline(bool offline) if (mProxyService) mProxyService->ReloadPAC(); - mLastOfflineStateChange = PR_IntervalNow(); // don't care if notification fails // Only send the ONLINE notification if there is connectivity if (observerService && mConnectivity) { @@ -1145,10 +1138,6 @@ nsIOService::SetConnectivityInternal(bool aConnectivity) } mConnectivity = aConnectivity; - // This is used for PR_Connect PR_Close telemetry so it is important that - // we have statistic about network change event even if we are offline. - mLastConnectivityChange = PR_IntervalNow(); - if (mCaptivePortalService) { if (aConnectivity && !xpc::AreNonLocalConnectionsDisabled()) { // This will also trigger a captive portal check for the new network @@ -1619,7 +1608,6 @@ nsIOService::OnNetworkLinkEvent(const char *data) bool isUp = true; if (!strcmp(data, NS_NETWORK_LINK_DATA_CHANGED)) { - mLastNetworkLinkChange = PR_IntervalNow(); // CHANGED means UP/DOWN didn't change // but the status of the captive portal may have changed. RecheckCaptivePortal(); diff --git a/netwerk/base/nsIOService.h b/netwerk/base/nsIOService.h index e592c4d1c..19eed743a 100644 --- a/netwerk/base/nsIOService.h +++ b/netwerk/base/nsIOService.h @@ -79,9 +79,6 @@ public: nsAsyncRedirectVerifyHelper *helper); bool IsOffline() { return mOffline; } - PRIntervalTime LastOfflineStateChange() { return mLastOfflineStateChange; } - PRIntervalTime LastConnectivityChange() { return mLastConnectivityChange; } - PRIntervalTime LastNetworkLinkChange() { return mLastNetworkLinkChange; } bool IsNetTearingDown() { return mShutdown || mOfflineForProfileChange || mHttpHandlerAlreadyShutingDown; } PRIntervalTime NetTearingDownStarted() { return mNetTearingDownStarted; } @@ -176,18 +173,8 @@ private: bool mNetworkNotifyChanged; - static bool sTelemetryEnabled; - static bool sBlockToplevelDataUriNavigations; - // These timestamps are needed for collecting telemetry on PR_Connect, - // PR_ConnectContinue and PR_Close blocking time. If we spend very long - // time in any of these functions we want to know if and what network - // change has happened shortly before. - mozilla::Atomic<PRIntervalTime> mLastOfflineStateChange; - mozilla::Atomic<PRIntervalTime> mLastConnectivityChange; - mozilla::Atomic<PRIntervalTime> mLastNetworkLinkChange; - // Time a network tearing down started. mozilla::Atomic<PRIntervalTime> mNetTearingDownStarted; public: diff --git a/netwerk/base/nsITLSServerSocket.idl b/netwerk/base/nsITLSServerSocket.idl index 57485357f..dce54ffe7 100644 --- a/netwerk/base/nsITLSServerSocket.idl +++ b/netwerk/base/nsITLSServerSocket.idl @@ -20,15 +20,6 @@ interface nsITLSServerSocket : nsIServerSocket attribute nsIX509Cert serverCert; /** - * setSessionCache - * - * Whether the server should use a session cache. Defaults to true. This - * should be set before calling |asyncListen| if you wish to change the - * default. - */ - void setSessionCache(in boolean aSessionCache); - - /** * setSessionTickets * * Whether the server should support session tickets. Defaults to true. This diff --git a/netwerk/base/nsLoadGroup.cpp b/netwerk/base/nsLoadGroup.cpp index 51d5a9ca7..48d9a6621 100644 --- a/netwerk/base/nsLoadGroup.cpp +++ b/netwerk/base/nsLoadGroup.cpp @@ -14,7 +14,6 @@ #include "mozilla/Logging.h" #include "nsString.h" #include "nsTArray.h" -#include "mozilla/Telemetry.h" #include "nsITimedChannel.h" #include "nsIInterfaceRequestor.h" #include "nsIRequestObserver.h" @@ -109,9 +108,6 @@ nsLoadGroup::nsLoadGroup(nsISupports* outer) , mStatus(NS_OK) , mPriority(PRIORITY_NORMAL) , mIsCanceling(false) - , mDefaultLoadIsTimed(false) - , mTimedRequests(0) - , mCachedRequests(0) , mTimedNonCachedRequestsUntilOnEndPageLoad(0) { NS_INIT_AGGREGATED(outer); @@ -432,13 +428,6 @@ nsLoadGroup::SetDefaultLoadRequest(nsIRequest *aRequest) // in particular, nsIChannel::LOAD_DOCUMENT_URI... // mLoadFlags &= nsIRequest::LOAD_REQUESTMASK; - - nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(aRequest); - mDefaultLoadIsTimed = timedChannel != nullptr; - if (mDefaultLoadIsTimed) { - timedChannel->GetChannelCreation(&mDefaultRequestCreationTime); - timedChannel->SetTimingEnabled(true); - } } // Else, do not change the group's load flags (see bug 95981) return NS_OK; @@ -493,10 +482,6 @@ nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt) if (mPriority != 0) RescheduleRequest(request, mPriority); - nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(request); - if (timedChannel) - timedChannel->SetTimingEnabled(true); - if (!(flags & nsIRequest::LOAD_BACKGROUND)) { // Update the count of foreground URIs.. mForegroundCount += 1; @@ -574,44 +559,6 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt, mRequests.RemoveEntry(entry); - // Collect telemetry stats only when default request is a timed channel. - // Don't include failed requests in the timing statistics. - if (mDefaultLoadIsTimed && NS_SUCCEEDED(aStatus)) { - nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(request); - if (timedChannel) { - // Figure out if this request was served from the cache - ++mTimedRequests; - TimeStamp timeStamp; - rv = timedChannel->GetCacheReadStart(&timeStamp); - if (NS_SUCCEEDED(rv) && !timeStamp.IsNull()) { - ++mCachedRequests; - } - else { - mTimedNonCachedRequestsUntilOnEndPageLoad++; - } - - rv = timedChannel->GetAsyncOpen(&timeStamp); - if (NS_SUCCEEDED(rv) && !timeStamp.IsNull()) { - Telemetry::AccumulateTimeDelta( - Telemetry::HTTP_SUBITEM_OPEN_LATENCY_TIME, - mDefaultRequestCreationTime, timeStamp); - } - - rv = timedChannel->GetResponseStart(&timeStamp); - if (NS_SUCCEEDED(rv) && !timeStamp.IsNull()) { - Telemetry::AccumulateTimeDelta( - Telemetry::HTTP_SUBITEM_FIRST_BYTE_LATENCY_TIME, - mDefaultRequestCreationTime, timeStamp); - } - - TelemetryReportChannel(timedChannel, false); - } - } - - if (mRequests.EntryCount() == 0) { - TelemetryReport(); - } - // Undo any group priority delta... if (mPriority != 0) RescheduleRequest(request, -mPriority); @@ -812,204 +759,6 @@ nsLoadGroup::SetDefaultLoadFlags(uint32_t aFlags) //////////////////////////////////////////////////////////////////////////////// -void -nsLoadGroup::TelemetryReport() -{ - if (mDefaultLoadIsTimed) { - Telemetry::Accumulate(Telemetry::HTTP_REQUEST_PER_PAGE, mTimedRequests); - if (mTimedRequests) { - Telemetry::Accumulate(Telemetry::HTTP_REQUEST_PER_PAGE_FROM_CACHE, - mCachedRequests * 100 / mTimedRequests); - } - - nsCOMPtr<nsITimedChannel> timedChannel = - do_QueryInterface(mDefaultLoadRequest); - if (timedChannel) - TelemetryReportChannel(timedChannel, true); - } - - mTimedRequests = 0; - mCachedRequests = 0; - mDefaultLoadIsTimed = false; -} - -void -nsLoadGroup::TelemetryReportChannel(nsITimedChannel *aTimedChannel, - bool aDefaultRequest) -{ - nsresult rv; - bool timingEnabled; - rv = aTimedChannel->GetTimingEnabled(&timingEnabled); - if (NS_FAILED(rv) || !timingEnabled) - return; - - TimeStamp asyncOpen; - rv = aTimedChannel->GetAsyncOpen(&asyncOpen); - // We do not check !asyncOpen.IsNull() bellow, prevent ASSERTIONs this way - if (NS_FAILED(rv) || asyncOpen.IsNull()) - return; - - TimeStamp cacheReadStart; - rv = aTimedChannel->GetCacheReadStart(&cacheReadStart); - if (NS_FAILED(rv)) - return; - - TimeStamp cacheReadEnd; - rv = aTimedChannel->GetCacheReadEnd(&cacheReadEnd); - if (NS_FAILED(rv)) - return; - - TimeStamp domainLookupStart; - rv = aTimedChannel->GetDomainLookupStart(&domainLookupStart); - if (NS_FAILED(rv)) - return; - - TimeStamp domainLookupEnd; - rv = aTimedChannel->GetDomainLookupEnd(&domainLookupEnd); - if (NS_FAILED(rv)) - return; - - TimeStamp connectStart; - rv = aTimedChannel->GetConnectStart(&connectStart); - if (NS_FAILED(rv)) - return; - - TimeStamp secureConnectionStart; - rv = aTimedChannel->GetSecureConnectionStart(&secureConnectionStart); - if (NS_FAILED(rv)) - return; - - TimeStamp connectEnd; - rv = aTimedChannel->GetConnectEnd(&connectEnd); - if (NS_FAILED(rv)) - return; - - TimeStamp requestStart; - rv = aTimedChannel->GetRequestStart(&requestStart); - if (NS_FAILED(rv)) - return; - - TimeStamp responseStart; - rv = aTimedChannel->GetResponseStart(&responseStart); - if (NS_FAILED(rv)) - return; - - TimeStamp responseEnd; - rv = aTimedChannel->GetResponseEnd(&responseEnd); - if (NS_FAILED(rv)) - return; - -#define HTTP_REQUEST_HISTOGRAMS(prefix) \ - if (!domainLookupStart.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_DNS_ISSUE_TIME, \ - asyncOpen, domainLookupStart); \ - } \ - \ - if (!domainLookupStart.IsNull() && !domainLookupEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_DNS_LOOKUP_TIME, \ - domainLookupStart, domainLookupEnd); \ - } \ - \ - if (!secureConnectionStart.IsNull() && !connectEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_TLS_HANDSHAKE, \ - secureConnectionStart, connectEnd); \ - } \ - \ - if (!connectStart.IsNull() && !connectEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_TCP_CONNECTION_2, \ - connectStart, connectEnd); \ - } \ - \ - \ - if (!requestStart.IsNull() && !responseEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_OPEN_TO_FIRST_SENT, \ - asyncOpen, requestStart); \ - \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_FIRST_SENT_TO_LAST_RECEIVED, \ - requestStart, responseEnd); \ - \ - if (cacheReadStart.IsNull() && !responseStart.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_OPEN_TO_FIRST_RECEIVED, \ - asyncOpen, responseStart); \ - } \ - } \ - \ - if (!cacheReadStart.IsNull() && !cacheReadEnd.IsNull()) { \ - if (!CacheObserver::UseNewCache()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_OPEN_TO_FIRST_FROM_CACHE, \ - asyncOpen, cacheReadStart); \ - } else { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_OPEN_TO_FIRST_FROM_CACHE_V2, \ - asyncOpen, cacheReadStart); \ - } \ - \ - if (!CacheObserver::UseNewCache()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_CACHE_READ_TIME, \ - cacheReadStart, cacheReadEnd); \ - } else { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_CACHE_READ_TIME_V2, \ - cacheReadStart, cacheReadEnd); \ - } \ - \ - if (!requestStart.IsNull() && !responseEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_REVALIDATION, \ - requestStart, responseEnd); \ - } \ - } \ - \ - if (!cacheReadEnd.IsNull()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD, \ - asyncOpen, cacheReadEnd); \ - \ - if (!CacheObserver::UseNewCache()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD_CACHED, \ - asyncOpen, cacheReadEnd); \ - } else { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD_CACHED_V2, \ - asyncOpen, cacheReadEnd); \ - } \ - } \ - else if (!responseEnd.IsNull()) { \ - if (!CacheObserver::UseNewCache()) { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD, \ - asyncOpen, responseEnd); \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD_NET, \ - asyncOpen, responseEnd); \ - } else { \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD_V2, \ - asyncOpen, responseEnd); \ - Telemetry::AccumulateTimeDelta( \ - Telemetry::HTTP_##prefix##_COMPLETE_LOAD_NET_V2, \ - asyncOpen, responseEnd); \ - } \ - } - - if (aDefaultRequest) { - HTTP_REQUEST_HISTOGRAMS(PAGE) - } else { - HTTP_REQUEST_HISTOGRAMS(SUB) - } -#undef HTTP_REQUEST_HISTOGRAMS -} - nsresult nsLoadGroup::MergeLoadFlags(nsIRequest *aRequest, nsLoadFlags& outFlags) { diff --git a/netwerk/base/nsLoadGroup.h b/netwerk/base/nsLoadGroup.h index 20dd94cf9..9b5e70868 100644 --- a/netwerk/base/nsLoadGroup.h +++ b/netwerk/base/nsLoadGroup.h @@ -62,11 +62,6 @@ protected: nsresult MergeLoadFlags(nsIRequest *aRequest, nsLoadFlags& flags); nsresult MergeDefaultLoadFlags(nsIRequest *aRequest, nsLoadFlags& flags); -private: - void TelemetryReport(); - void TelemetryReportChannel(nsITimedChannel *timedChannel, - bool defaultRequest); - protected: uint32_t mForegroundCount; uint32_t mLoadFlags; @@ -87,12 +82,6 @@ protected: int32_t mPriority; bool mIsCanceling; - /* Telemetry */ - mozilla::TimeStamp mDefaultRequestCreationTime; - bool mDefaultLoadIsTimed; - uint32_t mTimedRequests; - uint32_t mCachedRequests; - /* For nsPILoadGroupInternal */ uint32_t mTimedNonCachedRequestsUntilOnEndPageLoad; }; diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index d60c909c5..653a9003e 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -2262,7 +2262,6 @@ NS_ShouldSecureUpgrade(nsIURI* aURI, nsIScriptError::warningFlag, "CSP", innerWindowId); - Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 4); aShouldUpgrade = true; return NS_OK; } @@ -2285,17 +2284,10 @@ NS_ShouldSecureUpgrade(nsIURI* aURI, if (isStsHost) { LOG(("nsHttpChannel::Connect() STS permissions found\n")); if (aAllowSTS) { - Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 3); aShouldUpgrade = true; return NS_OK; - } else { - Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 2); } - } else { - Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 1); } - } else { - Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 0); } aShouldUpgrade = false; return NS_OK; diff --git a/netwerk/base/nsNetUtilInlines.h b/netwerk/base/nsNetUtilInlines.h index 7003814d5..b831ec2e7 100644 --- a/netwerk/base/nsNetUtilInlines.h +++ b/netwerk/base/nsNetUtilInlines.h @@ -224,7 +224,9 @@ NS_NewChannelInternal(nsIChannel **outChannel, aUri, aLoadInfo, getter_AddRefs(channel)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + return rv; + } if (aLoadGroup) { rv = channel->SetLoadGroup(aLoadGroup); diff --git a/netwerk/base/nsProtocolProxyService.cpp b/netwerk/base/nsProtocolProxyService.cpp index 26eca0e88..237a2a3bd 100644 --- a/netwerk/base/nsProtocolProxyService.cpp +++ b/netwerk/base/nsProtocolProxyService.cpp @@ -1841,6 +1841,13 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel, if (mPACMan && mPACMan->IsPACURI(uri)) return NS_OK; + // If proxies are enabled and this host:port combo is supposed to use a
+ // proxy, check for a proxy.
+ if ((mProxyConfig == PROXYCONFIG_DIRECT) ||
+ !CanUseProxy(uri, info.defaultPort)) {
+ return NS_OK;
+ }
+ bool mainThreadOnly; if (mSystemProxySettings && mProxyConfig == PROXYCONFIG_SYSTEM && diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp index 184757d33..0c8434813 100644 --- a/netwerk/base/nsSocketTransport2.cpp +++ b/netwerk/base/nsSocketTransport2.cpp @@ -7,7 +7,6 @@ #include "nsSocketTransport2.h" #include "mozilla/Attributes.h" -#include "mozilla/Telemetry.h" #include "nsIOService.h" #include "nsStreamUtils.h" #include "nsNetSegmentUtils.h" @@ -1226,8 +1225,7 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, bool &proxyTransparent, bool &us if (NS_FAILED(rv)) { SOCKET_LOG((" error pushing io layer [%u:%s rv=%x]\n", i, mTypes[i], rv)); if (fd) { - CloseSocket(fd, - mSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()); + CloseSocket(fd); } } } @@ -1395,8 +1393,7 @@ nsSocketTransport::InitiateSocket() // inform socket transport about this newly created socket... rv = mSocketTransportService->AttachSocket(fd, this); if (NS_FAILED(rv)) { - CloseSocket(fd, - mSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()); + CloseSocket(fd); return rv; } mAttached = true; @@ -1453,26 +1450,8 @@ nsSocketTransport::InitiateSocket() } #endif - // We use PRIntervalTime here because we need - // nsIOService::LastOfflineStateChange time and - // nsIOService::LastConectivityChange time to be atomic. - PRIntervalTime connectStarted = 0; - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - connectStarted = PR_IntervalNow(); - } - status = PR_Connect(fd, &prAddr, NS_SOCKET_CONNECT_TIMEOUT); - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase() && - connectStarted) { - SendPRBlockingTelemetry(connectStarted, - Telemetry::PRCONNECT_BLOCKING_TIME_NORMAL, - Telemetry::PRCONNECT_BLOCKING_TIME_SHUTDOWN, - Telemetry::PRCONNECT_BLOCKING_TIME_CONNECTIVITY_CHANGE, - Telemetry::PRCONNECT_BLOCKING_TIME_LINK_CHANGE, - Telemetry::PRCONNECT_BLOCKING_TIME_OFFLINE); - } - if (status == PR_SUCCESS) { // // we are connected! @@ -1531,16 +1510,6 @@ nsSocketTransport::InitiateSocket() // The connection was refused... // else { - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase() && - connectStarted) { - SendPRBlockingTelemetry(connectStarted, - Telemetry::PRCONNECT_FAIL_BLOCKING_TIME_NORMAL, - Telemetry::PRCONNECT_FAIL_BLOCKING_TIME_SHUTDOWN, - Telemetry::PRCONNECT_FAIL_BLOCKING_TIME_CONNECTIVITY_CHANGE, - Telemetry::PRCONNECT_FAIL_BLOCKING_TIME_LINK_CHANGE, - Telemetry::PRCONNECT_FAIL_BLOCKING_TIME_OFFLINE); - } - rv = ErrorAccordingToNSPR(code); if ((rv == NS_ERROR_CONNECTION_REFUSED) && !mProxyHost.IsEmpty()) rv = NS_ERROR_PROXY_CONNECTION_REFUSED; @@ -1596,17 +1565,6 @@ nsSocketTransport::RecoverFromError() bool tryAgain = false; - if ((mState == STATE_CONNECTING) && mDNSRecord && - mSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - if (mNetAddr.raw.family == AF_INET) { - Telemetry::Accumulate(Telemetry::IPV4_AND_IPV6_ADDRESS_CONNECTIVITY, - UNSUCCESSFUL_CONNECTING_TO_IPV4_ADDRESS); - } else if (mNetAddr.raw.family == AF_INET6) { - Telemetry::Accumulate(Telemetry::IPV4_AND_IPV6_ADDRESS_CONNECTIVITY, - UNSUCCESSFUL_CONNECTING_TO_IPV6_ADDRESS); - } - } - if (mConnectionFlags & (DISABLE_IPV6 | DISABLE_IPV4) && mCondition == NS_ERROR_UNKNOWN_HOST && mState == STATE_RESOLVING && @@ -1774,8 +1732,7 @@ public: NS_IMETHOD Run() override { - nsSocketTransport::CloseSocket(mFD, - gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()); + nsSocketTransport::CloseSocket(mFD); return NS_OK; } private: @@ -1812,8 +1769,7 @@ nsSocketTransport::ReleaseFD_Locked(PRFileDesc *fd) SOCKET_LOG(("Intentional leak")); } else if (PR_GetCurrentThread() == gSocketThread) { SOCKET_LOG(("nsSocketTransport: calling PR_Close [this=%p]\n", this)); - CloseSocket(mFD, - mSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()); + CloseSocket(mFD); } else { // Can't PR_Close() a socket off STS thread. Thunk it to STS to die STS_PRCloseOnSocketTransport(mFD); @@ -1971,43 +1927,12 @@ nsSocketTransport::OnSocketReady(PRFileDesc *fd, int16_t outFlags) // We do not need to do PR_ConnectContinue when we are already // shutting down. - // We use PRIntervalTime here because we need - // nsIOService::LastOfflineStateChange time and - // nsIOService::LastConectivityChange time to be atomic. - PRIntervalTime connectStarted = 0; - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - connectStarted = PR_IntervalNow(); - } - PRStatus status = PR_ConnectContinue(fd, outFlags); - - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase() && - connectStarted) { - SendPRBlockingTelemetry(connectStarted, - Telemetry::PRCONNECTCONTINUE_BLOCKING_TIME_NORMAL, - Telemetry::PRCONNECTCONTINUE_BLOCKING_TIME_SHUTDOWN, - Telemetry::PRCONNECTCONTINUE_BLOCKING_TIME_CONNECTIVITY_CHANGE, - Telemetry::PRCONNECTCONTINUE_BLOCKING_TIME_LINK_CHANGE, - Telemetry::PRCONNECTCONTINUE_BLOCKING_TIME_OFFLINE); - } - if (status == PR_SUCCESS) { // // we are connected! // OnSocketConnected(); - - if (mSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - if (mNetAddr.raw.family == AF_INET) { - Telemetry::Accumulate( - Telemetry::IPV4_AND_IPV6_ADDRESS_CONNECTIVITY, - SUCCESSFUL_CONNECTING_TO_IPV4_ADDRESS); - } else if (mNetAddr.raw.family == AF_INET6) { - Telemetry::Accumulate( - Telemetry::IPV4_AND_IPV6_ADDRESS_CONNECTIVITY, - SUCCESSFUL_CONNECTING_TO_IPV6_ADDRESS); - } - } } else { PRErrorCode code = PR_GetError(); @@ -3167,62 +3092,13 @@ nsSocketTransport::PRFileDescAutoLock::SetKeepaliveVals(bool aEnabled, } void -nsSocketTransport::CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled) +nsSocketTransport::CloseSocket(PRFileDesc *aFd) { #if defined(XP_WIN) AttachShutdownLayer(aFd); #endif - // We use PRIntervalTime here because we need - // nsIOService::LastOfflineStateChange time and - // nsIOService::LastConectivityChange time to be atomic. - PRIntervalTime closeStarted; - if (aTelemetryEnabled) { - closeStarted = PR_IntervalNow(); - } - PR_Close(aFd); - - if (aTelemetryEnabled) { - SendPRBlockingTelemetry(closeStarted, - Telemetry::PRCLOSE_TCP_BLOCKING_TIME_NORMAL, - Telemetry::PRCLOSE_TCP_BLOCKING_TIME_SHUTDOWN, - Telemetry::PRCLOSE_TCP_BLOCKING_TIME_CONNECTIVITY_CHANGE, - Telemetry::PRCLOSE_TCP_BLOCKING_TIME_LINK_CHANGE, - Telemetry::PRCLOSE_TCP_BLOCKING_TIME_OFFLINE); - } -} - -void -nsSocketTransport::SendPRBlockingTelemetry(PRIntervalTime aStart, - Telemetry::ID aIDNormal, - Telemetry::ID aIDShutdown, - Telemetry::ID aIDConnectivityChange, - Telemetry::ID aIDLinkChange, - Telemetry::ID aIDOffline) -{ - PRIntervalTime now = PR_IntervalNow(); - if (gIOService->IsNetTearingDown()) { - Telemetry::Accumulate(aIDShutdown, - PR_IntervalToMilliseconds(now - aStart)); - - } else if (PR_IntervalToSeconds(now - gIOService->LastConnectivityChange()) - < 60) { - Telemetry::Accumulate(aIDConnectivityChange, - PR_IntervalToMilliseconds(now - aStart)); - } else if (PR_IntervalToSeconds(now - gIOService->LastNetworkLinkChange()) - < 60) { - Telemetry::Accumulate(aIDLinkChange, - PR_IntervalToMilliseconds(now - aStart)); - - } else if (PR_IntervalToSeconds(now - gIOService->LastOfflineStateChange()) - < 60) { - Telemetry::Accumulate(aIDOffline, - PR_IntervalToMilliseconds(now - aStart)); - } else { - Telemetry::Accumulate(aIDNormal, - PR_IntervalToMilliseconds(now - aStart)); - } } } // namespace net diff --git a/netwerk/base/nsSocketTransport2.h b/netwerk/base/nsSocketTransport2.h index 7c85ccdc4..310cc58d3 100644 --- a/netwerk/base/nsSocketTransport2.h +++ b/netwerk/base/nsSocketTransport2.h @@ -22,7 +22,6 @@ #include "nsIClassInfo.h" #include "mozilla/net/DNS.h" #include "nsASocketHandler.h" -#include "mozilla/Telemetry.h" #include "prerror.h" #include "nsAutoPtr.h" @@ -169,13 +168,7 @@ public: uint64_t ByteCountReceived() override { return mInput.ByteCount(); } uint64_t ByteCountSent() override { return mOutput.ByteCount(); } - static void CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled); - static void SendPRBlockingTelemetry(PRIntervalTime aStart, - Telemetry::ID aIDNormal, - Telemetry::ID aIDShutdown, - Telemetry::ID aIDConnectivityChange, - Telemetry::ID aIDLinkChange, - Telemetry::ID aIDOffline); + static void CloseSocket(PRFileDesc *aFd); protected: virtual ~nsSocketTransport(); diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 068bf0eca..af5742564 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -22,7 +22,6 @@ #include "mozilla/PublicSSL.h" #include "mozilla/ChaosMode.h" #include "mozilla/PodOperations.h" -#include "mozilla/Telemetry.h" #include "nsThreadUtils.h" #include "nsIFile.h" #include "nsIWidget.h" @@ -47,7 +46,6 @@ Atomic<PRThread*, Relaxed> gSocketThread; #define SOCKET_LIMIT_MIN 50U #define BLIP_INTERVAL_PREF "network.activity.blipIntervalMilliseconds" #define MAX_TIME_BETWEEN_TWO_POLLS "network.sts.max_time_for_events_between_two_polls" -#define TELEMETRY_PREF "toolkit.telemetry.enabled" #define MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN "network.sts.max_time_for_pr_close_during_shutdown" #define REPAIR_POLLABLE_EVENT_TIME 10 @@ -79,9 +77,7 @@ nsSocketTransportService::nsSocketTransportService() , mKeepaliveEnabledPref(false) , mServingPendingQueue(false) , mMaxTimePerPollIter(100) - , mTelemetryEnabledPref(false) , mMaxTimeForPrClosePref(PR_SecondsToInterval(5)) - , mSleepPhase(false) , mProbedMaxCount(false) #if defined(XP_WIN) , mPolling(false) @@ -211,17 +207,9 @@ nsSocketTransportService::AttachSocket(PRFileDesc *fd, nsASocketHandler *handler bool nsSocketTransportService::CanAttachSocket() { - static bool reported900FDLimit = false; - uint32_t total = mActiveCount + mIdleCount; bool rv = total < gMaxCount; - if (mTelemetryEnabledPref && - (((total >= 900) || !rv) && !reported900FDLimit)) { - reported900FDLimit = true; - Telemetry::Accumulate(Telemetry::NETWORK_SESSION_AT_900FD, true); - } - return rv; } @@ -439,13 +427,11 @@ nsSocketTransportService::PollTimeout() } int32_t -nsSocketTransportService::Poll(uint32_t *interval, - TimeDuration *pollDuration) +nsSocketTransportService::Poll(uint32_t *interval) { PRPollDesc *pollList; uint32_t pollCount; PRIntervalTime pollTimeout; - *pollDuration = 0; // If there are pending events for this thread then // DoPollIteration() should service the network without blocking. @@ -471,21 +457,12 @@ nsSocketTransportService::Poll(uint32_t *interval, PRIntervalTime ts = PR_IntervalNow(); - TimeStamp pollStart; - if (mTelemetryEnabledPref) { - pollStart = TimeStamp::NowLoRes(); - } - SOCKET_LOG((" timeout = %i milliseconds\n", PR_IntervalToMilliseconds(pollTimeout))); int32_t rv = PR_Poll(pollList, pollCount, pollTimeout); PRIntervalTime passedInterval = PR_IntervalNow() - ts; - if (mTelemetryEnabledPref && !pollStart.IsNull()) { - *pollDuration = TimeStamp::NowLoRes() - pollStart; - } - SOCKET_LOG((" ...returned after %i milliseconds\n", PR_IntervalToMilliseconds(passedInterval))); @@ -538,7 +515,6 @@ nsSocketTransportService::Init() tmpPrefService->AddObserver(KEEPALIVE_RETRY_INTERVAL_PREF, this, false); tmpPrefService->AddObserver(KEEPALIVE_PROBE_COUNT_PREF, this, false); tmpPrefService->AddObserver(MAX_TIME_BETWEEN_TWO_POLLS, this, false); - tmpPrefService->AddObserver(TELEMETRY_PREF, this, false); tmpPrefService->AddObserver(MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN, this, false); } UpdatePrefs(); @@ -547,8 +523,6 @@ nsSocketTransportService::Init() if (obsSvc) { obsSvc->AddObserver(this, "profile-initial-state", false); obsSvc->AddObserver(this, "last-pb-context-exited", false); - obsSvc->AddObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC, true); - obsSvc->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true); obsSvc->AddObserver(this, "xpcom-shutdown-threads", false); } @@ -615,16 +589,9 @@ nsSocketTransportService::ShutdownThread() if (obsSvc) { obsSvc->RemoveObserver(this, "profile-initial-state"); obsSvc->RemoveObserver(this, "last-pb-context-exited"); - obsSvc->RemoveObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC); - obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC); obsSvc->RemoveObserver(this, "xpcom-shutdown-threads"); } - if (mAfterWakeUpTimer) { - mAfterWakeUpTimer->Cancel(); - mAfterWakeUpTimer = nullptr; - } - NetworkActivityMonitor::Shutdown(); mInitialized = false; @@ -859,54 +826,16 @@ nsSocketTransportService::Run() // make sure the pseudo random number generator is seeded on this thread srand(static_cast<unsigned>(PR_Now())); - // For the calculation of the duration of the last cycle (i.e. the last for-loop - // iteration before shutdown). - TimeStamp startOfCycleForLastCycleCalc; - int numberOfPendingEventsLastCycle; - - // For measuring of the poll iteration duration without time spent blocked - // in poll(). - TimeStamp pollCycleStart; - // Time blocked in poll(). - TimeDuration singlePollDuration; - - // For calculating the time needed for a new element to run. - TimeStamp startOfIteration; - TimeStamp startOfNextIteration; int numberOfPendingEvents; // If there is too many pending events queued, we will run some poll() - // between them and the following variable is cumulative time spent - // blocking in poll(). - TimeDuration pollDuration; - + // between them. for (;;) { bool pendingEvents = false; - numberOfPendingEvents = 0; - numberOfPendingEventsLastCycle = 0; - if (mTelemetryEnabledPref) { - startOfCycleForLastCycleCalc = TimeStamp::NowLoRes(); - startOfNextIteration = TimeStamp::NowLoRes(); - } - pollDuration = 0; do { - if (mTelemetryEnabledPref) { - pollCycleStart = TimeStamp::NowLoRes(); - } - - DoPollIteration(&singlePollDuration); - - if (mTelemetryEnabledPref && !pollCycleStart.IsNull()) { - Telemetry::Accumulate(Telemetry::STS_POLL_BLOCK_TIME, - singlePollDuration.ToMilliseconds()); - Telemetry::AccumulateTimeDelta( - Telemetry::STS_POLL_CYCLE, - pollCycleStart + singlePollDuration, - TimeStamp::NowLoRes()); - pollDuration += singlePollDuration; - } + DoPollIteration(); mRawThread->HasPendingEvents(&pendingEvents); if (pendingEvents) { @@ -920,15 +849,6 @@ nsSocketTransportService::Run() } else { mServingPendingQueue = true; } - - if (mTelemetryEnabledPref) { - startOfIteration = startOfNextIteration; - // Everything that comes after this point will - // be served in the next iteration. If no even - // arrives, startOfNextIteration will be reset at the - // beginning of each for-loop. - startOfNextIteration = TimeStamp::NowLoRes(); - } } TimeStamp eventQueueStart = TimeStamp::NowLoRes(); do { @@ -940,22 +860,6 @@ nsSocketTransportService::Run() ((TimeStamp::NowLoRes() - eventQueueStart).ToMilliseconds() < mMaxTimePerPollIter)); - - if (mTelemetryEnabledPref && !mServingPendingQueue && - !startOfIteration.IsNull()) { - Telemetry::AccumulateTimeDelta( - Telemetry::STS_POLL_AND_EVENTS_CYCLE, - startOfIteration + pollDuration, - TimeStamp::NowLoRes()); - - Telemetry::Accumulate( - Telemetry::STS_NUMBER_OF_PENDING_EVENTS, - numberOfPendingEvents); - - numberOfPendingEventsLastCycle += numberOfPendingEvents; - numberOfPendingEvents = 0; - pollDuration = 0; - } } } while (pendingEvents); @@ -964,16 +868,6 @@ nsSocketTransportService::Run() { MutexAutoLock lock(mLock); if (mShuttingDown) { - if (mTelemetryEnabledPref && - !startOfCycleForLastCycleCalc.IsNull()) { - Telemetry::Accumulate( - Telemetry::STS_NUMBER_OF_PENDING_EVENTS_IN_THE_LAST_CYCLE, - numberOfPendingEventsLastCycle); - Telemetry::AccumulateTimeDelta( - Telemetry::STS_POLL_AND_EVENT_THE_LAST_CYCLE, - startOfCycleForLastCycleCalc, - TimeStamp::NowLoRes()); - } break; } if (mGoingOffline) { @@ -1032,7 +926,7 @@ nsSocketTransportService::Reset(bool aGuardLocals) } nsresult -nsSocketTransportService::DoPollIteration(TimeDuration *pollDuration) +nsSocketTransportService::DoPollIteration() { SOCKET_LOG(("STS poll iter\n")); @@ -1092,13 +986,12 @@ nsSocketTransportService::DoPollIteration(TimeDuration *pollDuration) // Measures seconds spent while blocked on PR_Poll uint32_t pollInterval = 0; int32_t n = 0; - *pollDuration = 0; if (!gIOService->IsNetTearingDown()) { // Let's not do polling during shutdown. #if defined(XP_WIN) StartPolling(); #endif - n = Poll(&pollInterval, pollDuration); + n = Poll(&pollInterval); #if defined(XP_WIN) EndPolling(); #endif @@ -1142,11 +1035,6 @@ nsSocketTransportService::DoPollIteration(TimeDuration *pollDuration) } } } - if (mTelemetryEnabledPref) { - Telemetry::Accumulate( - Telemetry::STS_NUMBER_OF_ONSOCKETREADY_CALLS, - numberOfOnSocketReadyCalls); - } // // check for "dead" sockets and remove them (need to do this in @@ -1249,13 +1137,6 @@ nsSocketTransportService::UpdatePrefs() mMaxTimePerPollIter = maxTimePref; } - bool telemetryPref = false; - rv = tmpPrefService->GetBoolPref(TELEMETRY_PREF, - &telemetryPref); - if (NS_SUCCEEDED(rv)) { - mTelemetryEnabledPref = telemetryPref; - } - int32_t maxTimeForPrClosePref; rv = tmpPrefService->GetIntPref(MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN, &maxTimeForPrClosePref); @@ -1333,10 +1214,6 @@ nsSocketTransportService::Observe(nsISupports *subject, if (!strcmp(topic, NS_TIMER_CALLBACK_TOPIC)) { nsCOMPtr<nsITimer> timer = do_QueryInterface(subject); - if (timer == mAfterWakeUpTimer) { - mAfterWakeUpTimer = nullptr; - mSleepPhase = false; - } #if defined(XP_WIN) if (timer == mPollRepairTimer) { @@ -1344,19 +1221,6 @@ nsSocketTransportService::Observe(nsISupports *subject, } #endif - } else if (!strcmp(topic, NS_WIDGET_SLEEP_OBSERVER_TOPIC)) { - mSleepPhase = true; - if (mAfterWakeUpTimer) { - mAfterWakeUpTimer->Cancel(); - mAfterWakeUpTimer = nullptr; - } - } else if (!strcmp(topic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) { - if (mSleepPhase && !mAfterWakeUpTimer) { - mAfterWakeUpTimer = do_CreateInstance("@mozilla.org/timer;1"); - if (mAfterWakeUpTimer) { - mAfterWakeUpTimer->Init(this, 2000, nsITimer::TYPE_ONE_SHOT); - } - } } else if (!strcmp(topic, "xpcom-shutdown-threads")) { ShutdownThread(); } @@ -1465,7 +1329,6 @@ nsSocketTransportService::ProbeMaxCount() if (pfd[index].fd) PR_Close(pfd[index].fd); - Telemetry::Accumulate(Telemetry::NETWORK_PROBE_MAXCOUNT, gMaxCount); SOCKET_LOG(("Socket Limit Test max was confirmed at %d\n", gMaxCount)); } #endif // windows diff --git a/netwerk/base/nsSocketTransportService2.h b/netwerk/base/nsSocketTransportService2.h index 81c806793..0b88a6535 100644 --- a/netwerk/base/nsSocketTransportService2.h +++ b/netwerk/base/nsSocketTransportService2.h @@ -118,8 +118,6 @@ public: // Returns true if keepalives are enabled in prefs. bool IsKeepaliveEnabled() { return mKeepaliveEnabledPref; } - bool IsTelemetryEnabledAndNotSleepPhase() { return mTelemetryEnabledPref && - !mSleepPhase; } PRIntervalTime MaxTimeForPrClosePref() {return mMaxTimeForPrClosePref; } protected: @@ -191,7 +189,7 @@ private: bool GrowActiveList(); bool GrowIdleList(); - void InitMaxCount(); + void InitMaxCount(); // Total bytes number transfered through all the sockets except active ones uint64_t mSentBytesCount; @@ -206,15 +204,12 @@ private: PRPollDesc *mPollList; /* mListSize + 1 entries */ PRIntervalTime PollTimeout(); // computes ideal poll timeout - nsresult DoPollIteration(TimeDuration *pollDuration); + nsresult DoPollIteration(); // perfoms a single poll iteration - int32_t Poll(uint32_t *interval, - TimeDuration *pollDuration); + int32_t Poll(uint32_t *interval); // calls PR_Poll. the out param // interval indicates the poll // duration in seconds. - // pollDuration is used only for - // telemetry //------------------------------------------------------------------------- // pending socket queue - see NotifyWhenCanAttachSocket @@ -236,14 +231,8 @@ private: Atomic<bool> mServingPendingQueue; Atomic<int32_t, Relaxed> mMaxTimePerPollIter; - Atomic<bool, Relaxed> mTelemetryEnabledPref; Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref; - // Between a computer going to sleep and waking up the PR_*** telemetry - // will be corrupted - so do not record it. - Atomic<bool, Relaxed> mSleepPhase; - nsCOMPtr<nsITimer> mAfterWakeUpTimer; - void OnKeepaliveEnabledPrefChange(); void NotifyKeepaliveEnabledPrefChange(SocketContext *sock); diff --git a/netwerk/base/nsStandardURL.h b/netwerk/base/nsStandardURL.h index 0ca345572..eba85528c 100644 --- a/netwerk/base/nsStandardURL.h +++ b/netwerk/base/nsStandardURL.h @@ -72,7 +72,6 @@ public: static void InitGlobalObjects(); static void ShutdownGlobalObjects(); -public: /* internal -- HPUX compiler can't handle this being private */ // // location and length of an url segment relative to mSpec // diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 5973a205d..8b6a81bf5 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -7,7 +7,6 @@ #include "mozilla/EndianUtils.h" #include "mozilla/dom/TypedArray.h" #include "mozilla/HoldDropJSObjects.h" -#include "mozilla/Telemetry.h" #include "nsSocketTransport2.h" #include "nsUDPSocket.h" @@ -173,7 +172,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsUDPMessage) NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsUDPMessage) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsUDPMessage) @@ -275,7 +273,6 @@ void nsUDPSocket::AddOutputBytes(uint64_t aBytes) { mByteWriteCount += aBytes; - SaveNetworkStats(false); } void @@ -465,7 +462,6 @@ nsUDPSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags) return; } mByteReadCount += count; - SaveNetworkStats(false); FallibleTArray<uint8_t> data; if (!data.AppendElements(buff, count, fallible)) { @@ -512,7 +508,6 @@ nsUDPSocket::OnSocketDetached(PRFileDesc *fd) NS_ASSERTION(mFD == fd, "wrong file descriptor"); CloseSocket(); } - SaveNetworkStats(true); if (mListener) { @@ -726,7 +721,6 @@ nsUDPSocket::Close() // expects this happen synchronously. CloseSocket(); - SaveNetworkStats(true); return NS_OK; } } @@ -755,12 +749,6 @@ nsUDPSocket::GetLocalAddr(nsINetAddr * *aResult) } void -nsUDPSocket::SaveNetworkStats(bool aEnforce) -{ - /*** STUB ***/ -} - -void nsUDPSocket::CloseSocket() { if (mFD) { @@ -770,40 +758,7 @@ nsUDPSocket::CloseSocket() // If shutdown last to long, let the socket leak and do not close it. UDPSOCKET_LOG(("Intentional leak")); } else { - - PRIntervalTime closeStarted = 0; - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - closeStarted = PR_IntervalNow(); - } - PR_Close(mFD); - - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - PRIntervalTime now = PR_IntervalNow(); - if (gIOService->IsNetTearingDown()) { - Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_SHUTDOWN, - PR_IntervalToMilliseconds(now - closeStarted)); - - } else if (PR_IntervalToSeconds(now - gIOService->LastConnectivityChange()) - < 60) { - Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_CONNECTIVITY_CHANGE, - PR_IntervalToMilliseconds(now - closeStarted)); - - } else if (PR_IntervalToSeconds(now - gIOService->LastNetworkLinkChange()) - < 60) { - Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_LINK_CHANGE, - PR_IntervalToMilliseconds(now - closeStarted)); - - } else if (PR_IntervalToSeconds(now - gIOService->LastOfflineStateChange()) - < 60) { - Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_OFFLINE, - PR_IntervalToMilliseconds(now - closeStarted)); - - } else { - Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_NORMAL, - PR_IntervalToMilliseconds(now - closeStarted)); - } - } } mFD = nullptr; } diff --git a/netwerk/base/nsUDPSocket.h b/netwerk/base/nsUDPSocket.h index f8ae87cee..2910a49dd 100644 --- a/netwerk/base/nsUDPSocket.h +++ b/netwerk/base/nsUDPSocket.h @@ -53,8 +53,6 @@ private: const PRNetAddr& aIface); nsresult SetMulticastInterfaceInternal(const PRNetAddr& aIface); - void SaveNetworkStats(bool aEnforce); - void CloseSocket(); // lock protects access to mListener; diff --git a/netwerk/base/security-prefs.js b/netwerk/base/security-prefs.js index cfbbf4a45..ef78ddccb 100644 --- a/netwerk/base/security-prefs.js +++ b/netwerk/base/security-prefs.js @@ -17,6 +17,11 @@ pref("security.ssl.false_start.require-npn", false); pref("security.ssl.enable_npn", true); pref("security.ssl.enable_alpn", true); +// TLS 1.3 cipher suites +pref("security.tls13.aes_128_gcm_sha256", true); +pref("security.tls13.chacha20_poly1305_sha256", true); +pref("security.tls13.aes_256_gcm_sha384", true); + // TLS 1.0-1.2 cipher suites pref("security.ssl3.ecdhe_rsa_aes_128_gcm_sha256", true); pref("security.ssl3.ecdhe_ecdsa_aes_128_gcm_sha256", true); @@ -36,12 +41,17 @@ pref("security.ssl3.rsa_camellia_128_sha", true); pref("security.ssl3.rsa_camellia_256_sha", true); pref("security.ssl3.rsa_aes_128_sha", true); pref("security.ssl3.rsa_aes_256_sha", true); -// Weak / deprecated + +// Deprecated pref("security.ssl3.dhe_rsa_aes_256_sha", false); pref("security.ssl3.dhe_rsa_aes_128_sha", false); pref("security.ssl3.rsa_aes_128_gcm_sha256", false); pref("security.ssl3.rsa_aes_128_sha256", false); + +// Weak/broken (requires fallback_hosts) pref("security.ssl3.rsa_des_ede3_sha", false); +pref("security.ssl3.rsa_rc4_128_sha", false); +pref("security.ssl3.rsa_rc4_128_md5", false); pref("security.content.signature.root_hash", "97:E8:BA:9C:F1:2F:B3:DE:53:CC:42:A4:E6:57:7E:D6:4D:F4:93:C2:47:B4:14:FE:A0:36:81:8D:38:23:56:0E"); @@ -107,10 +117,6 @@ pref("security.webauth.u2f", false); pref("security.webauth.u2f_enable_softtoken", false); pref("security.webauth.u2f_enable_usbtoken", false); -pref("security.ssl.errorReporting.enabled", true); -pref("security.ssl.errorReporting.url", "https://incoming.telemetry.mozilla.org/submit/sslreports/"); -pref("security.ssl.errorReporting.automatic", false); - // OCSP must-staple pref("security.ssl.enable_ocsp_must_staple", true); diff --git a/netwerk/cache/nsCacheEntryDescriptor.cpp b/netwerk/cache/nsCacheEntryDescriptor.cpp index 64765f8aa..35ea22d55 100644 --- a/netwerk/cache/nsCacheEntryDescriptor.cpp +++ b/netwerk/cache/nsCacheEntryDescriptor.cpp @@ -43,7 +43,7 @@ public: nsresult status = NS_OK; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSASYNCDOOMEVENT_RUN)); + nsCacheServiceAutoLock lock; if (mDescriptor->mCacheEntry) { status = nsCacheService::gService->DoomEntry_Internal( @@ -113,7 +113,7 @@ nsCacheEntryDescriptor::GetClientID(char ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return ClientIDFromCacheKey(*(mCacheEntry->Key()), result); @@ -124,7 +124,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID) { NS_ENSURE_ARG_POINTER(aDeviceID); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDEVICEID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; const char* deviceID = mCacheEntry->GetDeviceID(); @@ -141,7 +141,7 @@ nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID) NS_IMETHODIMP nsCacheEntryDescriptor::GetKey(nsACString &result) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETKEY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result); @@ -152,7 +152,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetFetchCount(int32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFETCHCOUNT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->FetchCount(); @@ -164,7 +164,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetLastFetched(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTFETCHED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->LastFetched(); @@ -176,7 +176,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetLastModified(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTMODIFIED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->LastModified(); @@ -188,7 +188,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetExpirationTime(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETEXPIRATIONTIME)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->ExpirationTime(); @@ -199,7 +199,7 @@ nsCacheEntryDescriptor::GetExpirationTime(uint32_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetExpirationTime(uint32_t expirationTime) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETEXPIRATIONTIME)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetExpirationTime(expirationTime); @@ -211,7 +211,7 @@ nsCacheEntryDescriptor::SetExpirationTime(uint32_t expirationTime) NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_ISSTREAMBASED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->IsStreamData(); @@ -221,7 +221,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result) NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(int64_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETPREDICTEDDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->PredictedDataSize(); @@ -231,7 +231,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(int64_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(int64_t predictedSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETPREDICTEDDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetPredictedDataSize(predictedSize); @@ -241,7 +241,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(int64_t NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; const char* val = mCacheEntry->GetMetaDataElement("uncompressed-len"); @@ -258,7 +258,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(uint32_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->DataSize(); @@ -270,7 +270,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(uint32_t *result) nsresult nsCacheEntryDescriptor::RequestDataSizeChange(int32_t deltaSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_REQUESTDATASIZECHANGE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; nsresult rv; @@ -288,7 +288,7 @@ nsCacheEntryDescriptor::RequestDataSizeChange(int32_t deltaSize) NS_IMETHODIMP nsCacheEntryDescriptor::SetDataSize(uint32_t dataSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX review for signed/unsigned math errors @@ -317,7 +317,7 @@ nsCacheEntryDescriptor::OpenInputStream(uint32_t offset, nsIInputStream ** resul nsInputStreamWrapper* cacheInput = nullptr; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENINPUTSTREAM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM; @@ -352,7 +352,7 @@ nsCacheEntryDescriptor::OpenOutputStream(uint32_t offset, nsIOutputStream ** res nsOutputStreamWrapper* cacheOutput = nullptr; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENOUTPUTSTREAM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM; @@ -390,7 +390,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCACHEELEMENT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM; @@ -402,7 +402,7 @@ nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result) NS_IMETHODIMP nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETCACHEELEMENT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM; @@ -423,7 +423,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEPOLICY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->StoragePolicy(); @@ -434,7 +434,7 @@ nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSTORAGEPOLICY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX validate policy against session? @@ -461,7 +461,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetFile(nsIFile ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFILE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return nsCacheService::GetFileForEntry(mCacheEntry, result); @@ -472,7 +472,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSECURITYINFO)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->SecurityInfo(); @@ -484,7 +484,7 @@ nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result) NS_IMETHODIMP nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSECURITYINFO)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetSecurityInfo(securityInfo); @@ -496,7 +496,7 @@ nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo) NS_IMETHODIMP nsCacheEntryDescriptor::Doom() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return nsCacheService::DoomEntry(mCacheEntry); @@ -506,7 +506,7 @@ nsCacheEntryDescriptor::Doom() NS_IMETHODIMP nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_IMPLEMENTED; @@ -544,7 +544,7 @@ nsCacheEntryDescriptor::AsyncDoom(nsICacheListener *listener) NS_IMETHODIMP nsCacheEntryDescriptor::MarkValid() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_MARKVALID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; nsresult rv = nsCacheService::ValidateEntry(mCacheEntry); @@ -559,7 +559,7 @@ nsCacheEntryDescriptor::Close() nsTArray<RefPtr<nsInputStreamWrapper> > inputWrappers; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // Make sure no other stream can be opened @@ -585,7 +585,7 @@ nsCacheEntryDescriptor::Close() inputWrappers.Clear(); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX perhaps closing descriptors should clear/sever transports @@ -604,7 +604,7 @@ nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char **result) NS_ENSURE_ARG_POINTER(key); *result = nullptr; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETMETADATAELEMENT)); + nsCacheServiceAutoLock lock; NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE); const char *value; @@ -624,7 +624,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value) { NS_ENSURE_ARG_POINTER(key); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETMETADATAELEMENT)); + nsCacheServiceAutoLock lock; NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE); // XXX allow null value, for clearing key? @@ -639,7 +639,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value) NS_IMETHODIMP nsCacheEntryDescriptor::VisitMetaData(nsICacheMetaDataVisitor * visitor) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_VISITMETADATA)); + nsCacheServiceAutoLock lock; // XXX check callers, we're calling out of module NS_ENSURE_ARG_POINTER(visitor); if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; @@ -667,7 +667,7 @@ nsCacheEntryDescriptor::nsInputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -709,7 +709,7 @@ nsInputStreamWrapper::LazyInit() if (!mDescriptor) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_LAZYINIT)); + nsCacheServiceAutoLock lock; nsCacheAccessMode mode; nsresult rv = mDescriptor->GetAccessGranted(&mode); @@ -755,7 +755,7 @@ nsInputStreamWrapper::CloseInternal() return; } - nsCacheServiceAutoLock lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_CLOSEINTERNAL)); + nsCacheServiceAutoLock lock; if (mDescriptor) { mDescriptor->mInputWrappers.RemoveElement(this); @@ -859,8 +859,7 @@ nsCacheEntryDescriptor::nsDecompressInputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM( - NSDECOMPRESSINPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -1049,7 +1048,7 @@ nsCacheEntryDescriptor::nsOutputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -1089,7 +1088,7 @@ nsOutputStreamWrapper::LazyInit() if (!mDescriptor) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_LAZYINIT)); + nsCacheServiceAutoLock lock; nsCacheAccessMode mode; nsresult rv = mDescriptor->GetAccessGranted(&mode); @@ -1163,7 +1162,7 @@ nsOutputStreamWrapper::CloseInternal() return; } - nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_CLOSEINTERNAL)); + nsCacheServiceAutoLock lock; if (mDescriptor) { mDescriptor->mOutputWrapper = nullptr; @@ -1279,7 +1278,7 @@ nsCacheEntryDescriptor::nsCompressOutputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSCOMPRESSOUTPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); diff --git a/netwerk/cache/nsCacheService.cpp b/netwerk/cache/nsCacheService.cpp index bab67e104..4b08614b8 100644 --- a/netwerk/cache/nsCacheService.cpp +++ b/netwerk/cache/nsCacheService.cpp @@ -211,7 +211,7 @@ public: NS_IMETHOD Notify(nsITimer* aTimer) override { if (nsCacheService::gService) { - nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSSETDISKSMARTSIZECALLBACK_NOTIFY)); + nsCacheServiceAutoLock autoLock; nsCacheService::gService->SetDiskSmartSize_Locked(); nsCacheService::gService->mSmartSizeTimer = nullptr; } @@ -295,7 +295,7 @@ public: } NS_IMETHOD Run() override { - nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSBLOCKONCACHETHREADEVENT_RUN)); + nsCacheServiceAutoLock autoLock; CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this)); nsCacheService::gService->mNotified = true; nsCacheService::gService->mCondVar.Notify(); @@ -988,7 +988,7 @@ public: NS_ASSERTION(mRequest->mListener, "Sync OpenCacheEntry() posted to background thread!"); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSPROCESSREQUESTEVENT_RUN)); + nsCacheServiceAutoLock lock; rv = nsCacheService::gService->ProcessRequest(mRequest, false, nullptr); @@ -1184,13 +1184,12 @@ nsCacheService::Shutdown() } nsCOMPtr<nsIThread> cacheIOThread; - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN> totalTimer; bool shouldSanitize = false; nsCOMPtr<nsIFile> parentDir; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN)); + nsCacheServiceAutoLock lock; NS_ASSERTION(mInitialized, "can't shutdown nsCacheService unless it has been initialized."); if (!mInitialized) @@ -1205,7 +1204,7 @@ nsCacheService::Shutdown() UnregisterWeakMemoryReporter(this); { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN)); + nsCacheServiceAutoLock lock; NS_ASSERTION(mInitialized, "Bad state"); mInitialized = false; @@ -1261,10 +1260,8 @@ nsCacheService::Shutdown() if (NS_SUCCEEDED(parentDir->Exists(&exists)) && exists) nsDeleteDir::DeleteDir(parentDir, false); } - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN_CLEAR_PRIVATE> timer; nsDeleteDir::Shutdown(shouldSanitize); } else { - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_DELETEDIR_SHUTDOWN> timer; nsDeleteDir::Shutdown(shouldSanitize); } } @@ -1366,7 +1363,7 @@ nsCacheService::EvictEntriesForClient(const char * clientID, new EvictionNotifierRunnable(NS_ISUPPORTS_CAST(nsICacheService*, this)); NS_DispatchToMainThread(r); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_EVICTENTRIESFORCLIENT)); + nsCacheServiceAutoLock lock; nsresult res = NS_OK; if (storagePolicy == nsICache::STORE_ANYWHERE || @@ -1415,7 +1412,7 @@ nsCacheService::IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy, bool * result) { if (gService == nullptr) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ISSTORAGEENABLEDFORPOLICY)); + nsCacheServiceAutoLock lock; *result = gService->IsStorageEnabledForPolicy_Locked(storagePolicy); return NS_OK; @@ -1469,7 +1466,7 @@ nsresult nsCacheService::VisitEntriesInternal(nsICacheVisitor *visitor) { NS_ENSURE_ARG_POINTER(visitor); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_VISITENTRIES)); + nsCacheServiceAutoLock lock; if (!(mEnableDiskDevice || mEnableMemoryDevice)) return NS_ERROR_NOT_AVAILABLE; @@ -1551,7 +1548,7 @@ NS_IMETHODIMP nsCacheService::GetCacheIOTarget(nsIEventTarget * *aCacheIOTarget) // read from the main thread without the lock. This is useful to prevent // blocking the main thread on other cache operations. if (!NS_IsMainThread()) { - Lock(LOCK_TELEM(NSCACHESERVICE_GETCACHEIOTARGET)); + Lock(); } nsresult rv; @@ -1943,7 +1940,7 @@ nsCacheService::ProcessRequest(nsCacheRequest * request, // XXX this is probably wrong... Unlock(); rv = request->WaitForValidation(); - Lock(LOCK_TELEM(NSCACHESERVICE_PROCESSREQUEST)); + Lock(); } PR_REMOVE_AND_INIT_LINK(request); @@ -2055,7 +2052,7 @@ nsCacheService::OpenCacheEntry(nsCacheSession * session, } else { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_OPENCACHEENTRY)); + nsCacheServiceAutoLock lock; rv = gService->ProcessRequest(request, true, result); // delete requests that have completed @@ -2175,7 +2172,6 @@ nsCacheService::ActivateEntry(nsCacheRequest * request, nsCacheEntry * nsCacheService::SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy, bool *collision) { - Telemetry::AutoTimer<Telemetry::CACHE_DEVICE_SEARCH_2> timer; nsCacheEntry * entry = nullptr; CACHE_LOG_DEBUG(("mMemoryDevice: 0x%p\n", mMemoryDevice)); @@ -2357,14 +2353,14 @@ nsCacheService::OnProfileShutdown() } { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN)); + nsCacheServiceAutoLock lock; gService->mClearingEntries = true; gService->DoomActiveEntries(nullptr); } gService->CloseAllStreams(); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN)); + nsCacheServiceAutoLock lock; gService->ClearDoomList(); // Make sure to wait for any pending cache-operations before @@ -2403,7 +2399,7 @@ nsCacheService::OnProfileChanged() CACHE_LOG_DEBUG(("nsCacheService::OnProfileChanged")); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILECHANGED)); + nsCacheServiceAutoLock lock; gService->mEnableDiskDevice = gService->mObserver->DiskCacheEnabled(); gService->mEnableOfflineDevice = gService->mObserver->OfflineCacheEnabled(); @@ -2457,7 +2453,7 @@ void nsCacheService::SetDiskCacheEnabled(bool enabled) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEENABLED)); + nsCacheServiceAutoLock lock; gService->mEnableDiskDevice = enabled; } @@ -2466,7 +2462,7 @@ void nsCacheService::SetDiskCacheCapacity(int32_t capacity) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHECAPACITY)); + nsCacheServiceAutoLock lock; if (gService->mDiskDevice) { gService->mDiskDevice->SetCapacity(capacity); @@ -2479,7 +2475,7 @@ void nsCacheService::SetDiskCacheMaxEntrySize(int32_t maxSize) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEMAXENTRYSIZE)); + nsCacheServiceAutoLock lock; if (gService->mDiskDevice) { gService->mDiskDevice->SetMaxEntrySize(maxSize); @@ -2490,7 +2486,7 @@ void nsCacheService::SetMemoryCacheMaxEntrySize(int32_t maxSize) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHEMAXENTRYSIZE)); + nsCacheServiceAutoLock lock; if (gService->mMemoryDevice) { gService->mMemoryDevice->SetMaxEntrySize(maxSize); @@ -2501,7 +2497,7 @@ void nsCacheService::SetOfflineCacheEnabled(bool enabled) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHEENABLED)); + nsCacheServiceAutoLock lock; gService->mEnableOfflineDevice = enabled; } @@ -2509,7 +2505,7 @@ void nsCacheService::SetOfflineCacheCapacity(int32_t capacity) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHECAPACITY)); + nsCacheServiceAutoLock lock; if (gService->mOfflineDevice) { gService->mOfflineDevice->SetCapacity(capacity); @@ -2526,7 +2522,7 @@ nsCacheService::SetMemoryCache() CACHE_LOG_DEBUG(("nsCacheService::SetMemoryCache")); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHE)); + nsCacheServiceAutoLock lock; gService->mEnableMemoryDevice = gService->mObserver->MemoryCacheEnabled(); @@ -2642,34 +2638,6 @@ nsCacheService::Lock() } void -nsCacheService::Lock(mozilla::Telemetry::ID mainThreadLockerID) -{ - mozilla::Telemetry::ID lockerID; - mozilla::Telemetry::ID generalID; - - if (NS_IsMainThread()) { - lockerID = mainThreadLockerID; - generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_2; - } else { - lockerID = mozilla::Telemetry::HistogramCount; - generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_2; - } - - TimeStamp start(TimeStamp::Now()); - - nsCacheService::Lock(); - - TimeStamp stop(TimeStamp::Now()); - - // Telemetry isn't thread safe on its own, but this is OK because we're - // protecting it with the cache lock. - if (lockerID != mozilla::Telemetry::HistogramCount) { - mozilla::Telemetry::AccumulateTimeDelta(lockerID, start, stop); - } - mozilla::Telemetry::AccumulateTimeDelta(generalID, start, stop); -} - -void nsCacheService::Unlock() { gService->mLock.AssertCurrentThreadOwns(); @@ -2948,7 +2916,7 @@ nsCacheService::CloseAllStreams() nsTArray<RefPtr<nsCacheEntryDescriptor::nsOutputStreamWrapper> > outputs; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_CLOSEALLSTREAMS)); + nsCacheServiceAutoLock lock; nsTArray<nsCacheEntry*> entries; @@ -3071,7 +3039,7 @@ nsCacheService::LogCacheStatistics() nsresult nsCacheService::SetDiskSmartSize() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKSMARTSIZE)); + nsCacheServiceAutoLock lock; if (!gService) return NS_ERROR_NOT_AVAILABLE; @@ -3190,8 +3158,7 @@ nsCacheService::CollectReports(nsIHandleReportCallback* aHandleReport, { size_t disk = 0; if (mDiskDevice) { - nsCacheServiceAutoLock - lock(LOCK_TELEM(NSCACHESERVICE_DISKDEVICEHEAPSIZE)); + nsCacheServiceAutoLock lock; disk = mDiskDevice->SizeOfIncludingThis(DiskCacheDeviceMallocSizeOf); } diff --git a/netwerk/cache/nsCacheService.h b/netwerk/cache/nsCacheService.h index 1751d4875..95816cfe5 100644 --- a/netwerk/cache/nsCacheService.h +++ b/netwerk/cache/nsCacheService.h @@ -371,9 +371,6 @@ private: * nsCacheServiceAutoLock ******************************************************************************/ -#define LOCK_TELEM(x) \ - (::mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_##x) - // Instantiate this class to acquire the cache service lock for a particular // execution scope. class nsCacheServiceAutoLock { @@ -381,9 +378,6 @@ public: nsCacheServiceAutoLock() { nsCacheService::Lock(); } - explicit nsCacheServiceAutoLock(mozilla::Telemetry::ID mainThreadLockerID) { - nsCacheService::Lock(mainThreadLockerID); - } ~nsCacheServiceAutoLock() { nsCacheService::Unlock(); } diff --git a/netwerk/cache/nsDeleteDir.cpp b/netwerk/cache/nsDeleteDir.cpp index 1f3f3934e..8c4edf812 100644 --- a/netwerk/cache/nsDeleteDir.cpp +++ b/netwerk/cache/nsDeleteDir.cpp @@ -155,7 +155,6 @@ nsDeleteDir::DestroyThread() void nsDeleteDir::TimerCallback(nsITimer *aTimer, void *arg) { - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_DELETEDIR> timer; { MutexAutoLock lock(gInstance->mLock); @@ -193,8 +192,6 @@ nsDeleteDir::TimerCallback(nsITimer *aTimer, void *arg) nsresult nsDeleteDir::DeleteDir(nsIFile *dirIn, bool moveToTrash, uint32_t delay) { - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_TRASHRENAME> timer; - if (!gInstance) return NS_ERROR_NOT_INITIALIZED; diff --git a/netwerk/cache/nsDiskCacheDevice.cpp b/netwerk/cache/nsDiskCacheDevice.cpp index ac91534ff..09089bfb6 100644 --- a/netwerk/cache/nsDiskCacheDevice.cpp +++ b/netwerk/cache/nsDiskCacheDevice.cpp @@ -457,7 +457,6 @@ nsDiskCacheDevice::GetDeviceID() nsCacheEntry * nsDiskCacheDevice::FindEntry(nsCString * key, bool *collision) { - Telemetry::AutoTimer<Telemetry::CACHE_DISK_SEARCH_2> timer; if (!Initialized()) return nullptr; // NS_ERROR_NOT_INITIALIZED if (mClearingDiskCache) return nullptr; nsDiskCacheRecord record; @@ -955,7 +954,6 @@ nsDiskCacheDevice::EvictEntries(const char * clientID) nsresult nsDiskCacheDevice::OpenDiskCache() { - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_OPEN> timer; // if we don't have a cache directory, create one and open it bool exists; nsresult rv = mCacheDirectory->Exists(&exists); diff --git a/netwerk/cache/nsDiskCacheDeviceSQL.cpp b/netwerk/cache/nsDiskCacheDeviceSQL.cpp index 56ece5887..f4b1d72c9 100644 --- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp +++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp @@ -1523,7 +1523,6 @@ nsOfflineCacheDevice::FindEntry(nsCString *fullKey, bool *collision) { NS_ENSURE_TRUE(Initialized(), nullptr); - mozilla::Telemetry::AutoTimer<mozilla::Telemetry::CACHE_OFFLINE_SEARCH_2> timer; LOG(("nsOfflineCacheDevice::FindEntry [key=%s]\n", fullKey->get())); // SELECT * FROM moz_cache WHERE key = ? diff --git a/netwerk/cache/nsDiskCacheMap.cpp b/netwerk/cache/nsDiskCacheMap.cpp index d7ce13a35..d3ec1e714 100644 --- a/netwerk/cache/nsDiskCacheMap.cpp +++ b/netwerk/cache/nsDiskCacheMap.cpp @@ -19,7 +19,6 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/Sprintf.h" -#include "mozilla/Telemetry.h" #include <algorithm> using namespace mozilla; @@ -181,9 +180,6 @@ nsDiskCacheMap::Open(nsIFile * cacheDirectory, goto error_exit; } - Telemetry::Accumulate(Telemetry::HTTP_DISK_CACHE_OVERHEAD, - (uint32_t)SizeOfExcludingThis(moz_malloc_size_of)); - *corruptInfo = nsDiskCache::kNotCorrupt; return NS_OK; diff --git a/netwerk/cache/nsMemoryCacheDevice.cpp b/netwerk/cache/nsMemoryCacheDevice.cpp index 042e86022..eb69e8ea8 100644 --- a/netwerk/cache/nsMemoryCacheDevice.cpp +++ b/netwerk/cache/nsMemoryCacheDevice.cpp @@ -113,7 +113,6 @@ nsMemoryCacheDevice::GetDeviceID() nsCacheEntry * nsMemoryCacheDevice::FindEntry(nsCString * key, bool *collision) { - mozilla::Telemetry::AutoTimer<mozilla::Telemetry::CACHE_MEMORY_SEARCH_2> timer; nsCacheEntry * entry = mMemCacheEntries.GetEntry(key); if (!entry) return nullptr; diff --git a/netwerk/cache2/CacheEntry.cpp b/netwerk/cache2/CacheEntry.cpp index b79bf7373..51e441aa7 100644 --- a/netwerk/cache2/CacheEntry.cpp +++ b/netwerk/cache2/CacheEntry.cpp @@ -419,11 +419,6 @@ bool CacheEntry::Load(bool aTruncate, bool aPriority) { mozilla::MutexAutoUnlock unlock(mLock); - if (reportMiss) { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::MISS, mLoadStart); - } - LOG((" performing load, file=%p", mFile.get())); if (NS_SUCCEEDED(rv)) { rv = mFile->Init(fileKey, @@ -458,16 +453,6 @@ NS_IMETHODIMP CacheEntry::OnFileReady(nsresult aResult, bool aIsNew) MOZ_ASSERT(!mLoadStart.IsNull()); - if (NS_SUCCEEDED(aResult)) { - if (aIsNew) { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::MISS, mLoadStart); - } else { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::HIT, mLoadStart); - } - } - // OnFileReady, that is the only code that can transit from LOADING // to any follow-on state and can only be invoked ones on an entry. // Until this moment there is no consumer that could manipulate diff --git a/netwerk/cache2/CacheFile.cpp b/netwerk/cache2/CacheFile.cpp index fa0a89382..69fc3d33c 100644 --- a/netwerk/cache2/CacheFile.cpp +++ b/netwerk/cache2/CacheFile.cpp @@ -14,7 +14,6 @@ #include <algorithm> #include "nsComponentManagerUtils.h" #include "nsProxyRelease.h" -#include "mozilla/Telemetry.h" // When CACHE_CHUNKS is defined we always cache unused chunks in mCacheChunks. // When it is not defined, we always release the chunks ASAP, i.e. we cache @@ -1866,33 +1865,6 @@ CacheFile::Truncate(int64_t aOffset) return NS_OK; } -static uint32_t -StatusToTelemetryEnum(nsresult aStatus) -{ - if (NS_SUCCEEDED(aStatus)) { - return 0; - } - - switch (aStatus) { - case NS_BASE_STREAM_CLOSED: - return 0; // Log this as a success - case NS_ERROR_OUT_OF_MEMORY: - return 2; - case NS_ERROR_FILE_DISK_FULL: - return 3; - case NS_ERROR_FILE_CORRUPTED: - return 4; - case NS_ERROR_FILE_NOT_FOUND: - return 5; - case NS_BINDING_ABORTED: - return 6; - default: - return 1; // other error - } - - NS_NOTREACHED("We should never get here"); -} - nsresult CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus) { @@ -1914,9 +1886,6 @@ CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus) // chunks that won't be used anymore. CleanUpCachedChunks(); - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_V2_INPUT_STREAM_STATUS, - StatusToTelemetryEnum(aStatus)); - return NS_OK; } @@ -1952,9 +1921,6 @@ CacheFile::RemoveOutput(CacheFileOutputStream *aOutput, nsresult aStatus) // Notify close listener as the last action aOutput->NotifyCloseListener(); - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_V2_OUTPUT_STREAM_STATUS, - StatusToTelemetryEnum(aStatus)); - return NS_OK; } diff --git a/netwerk/cache2/CacheFileIOManager.cpp b/netwerk/cache2/CacheFileIOManager.cpp index 1d0d57635..25e621d12 100644 --- a/netwerk/cache2/CacheFileIOManager.cpp +++ b/netwerk/cache2/CacheFileIOManager.cpp @@ -21,7 +21,6 @@ #include "nsIObserverService.h" #include "nsICacheStorageVisitor.h" #include "nsISizeOf.h" -#include "mozilla/Telemetry.h" #include "mozilla/DebugOnly.h" #include "mozilla/Services.h" #include "nsDirectoryServiceUtils.h" @@ -1173,8 +1172,6 @@ CacheFileIOManager::Shutdown() return NS_ERROR_NOT_INITIALIZED; } - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN_V2> shutdownTimer; - CacheIndex::PreShutdown(); ShutdownMetadataWriteScheduling(); @@ -1192,7 +1189,6 @@ CacheFileIOManager::Shutdown() CacheIndex::Shutdown(); if (CacheObserver::ClearCacheOnShutdown()) { - Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE2_SHUTDOWN_CLEAR_PRIVATE> totalTimer; gInstance->SyncRemoveAllCacheFiles(); } @@ -3826,45 +3822,6 @@ CacheFileIOManager::CreateCacheTree() StartRemovingTrash(); - if (!CacheObserver::CacheFSReported()) { - uint32_t fsType = 4; // Other OS - -#ifdef XP_WIN - nsAutoString target; - nsresult rv = mCacheDirectory->GetTarget(target); - if (NS_FAILED(rv)) { - return NS_OK; - } - - wchar_t volume_path[MAX_PATH + 1] = { 0 }; - if (!::GetVolumePathNameW(target.get(), - volume_path, - mozilla::ArrayLength(volume_path))) { - return NS_OK; - } - - wchar_t fsName[6] = { 0 }; - if (!::GetVolumeInformationW(volume_path, nullptr, 0, nullptr, nullptr, - nullptr, fsName, - mozilla::ArrayLength(fsName))) { - return NS_OK; - } - - if (wcscmp(fsName, L"NTFS") == 0) { - fsType = 0; - } else if (wcscmp(fsName, L"FAT32") == 0) { - fsType = 1; - } else if (wcscmp(fsName, L"FAT") == 0) { - fsType = 2; - } else { - fsType = 3; - } -#endif - - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_FS_TYPE, fsType); - CacheObserver::SetCacheFSReported(); - } - return NS_OK; } @@ -3910,18 +3867,6 @@ CacheFileIOManager::OpenNSPRHandle(CacheFileHandle *aHandle, bool aCreate) LOG(("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry" " with hash %08x%08x%08x%08x%08x. %s to create the new file.", LOGSHA1(&hash), NS_SUCCEEDED(rv) ? "Succeeded" : "Failed")); - - // Report the full size only once per session - static bool sSizeReported = false; - if (!sSizeReported) { - uint32_t cacheUsage; - if (NS_SUCCEEDED(CacheIndex::GetCacheSize(&cacheUsage))) { - cacheUsage >>= 10; - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_SIZE_FULL_FAT, - cacheUsage); - sSizeReported = true; - } - } } else { LOG(("CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing" " entry.")); diff --git a/netwerk/cache2/CacheFileMetadata.cpp b/netwerk/cache2/CacheFileMetadata.cpp index 3814b4c87..86fc089aa 100644 --- a/netwerk/cache2/CacheFileMetadata.cpp +++ b/netwerk/cache2/CacheFileMetadata.cpp @@ -14,7 +14,6 @@ #include "nsICacheEntry.h" // for nsICacheEntryMetaDataVisitor #include "../cache/nsCacheUtils.h" #include "nsIFile.h" -#include "mozilla/Telemetry.h" #include "mozilla/DebugOnly.h" #include "prnetdb.h" @@ -687,16 +686,6 @@ CacheFileMetadata::OnDataRead(CacheFileHandle *aHandle, char *aBuf, return NS_OK; } - if (mFirstRead) { - Telemetry::AccumulateTimeDelta( - Telemetry::NETWORK_CACHE_METADATA_FIRST_READ_TIME_MS, mReadStart); - Telemetry::Accumulate( - Telemetry::NETWORK_CACHE_METADATA_FIRST_READ_SIZE, mBufSize); - } else { - Telemetry::AccumulateTimeDelta( - Telemetry::NETWORK_CACHE_METADATA_SECOND_READ_TIME_MS, mReadStart); - } - // check whether we have read all necessary data uint32_t realOffset = NetworkEndian::readUint32(mBuf + mBufSize - sizeof(uint32_t)); @@ -776,9 +765,6 @@ CacheFileMetadata::OnDataRead(CacheFileHandle *aHandle, char *aBuf, return NS_OK; } - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_METADATA_SIZE, - size - realOffset); - // We have all data according to offset information at the end of the entry. // Try to parse it. rv = ParseMetadata(realOffset, realOffset - usedOffset, true); diff --git a/netwerk/cache2/CacheFileUtils.cpp b/netwerk/cache2/CacheFileUtils.cpp index d43e958bf..a090a9cb1 100644 --- a/netwerk/cache2/CacheFileUtils.cpp +++ b/netwerk/cache2/CacheFileUtils.cpp @@ -7,7 +7,6 @@ #include "CacheFileUtils.h" #include "LoadContextInfo.h" #include "mozilla/Tokenizer.h" -#include "mozilla/Telemetry.h" #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsString.h" @@ -402,116 +401,6 @@ ValidityMap::operator[](uint32_t aIdx) return mMap.ElementAt(aIdx); } -StaticMutex DetailedCacheHitTelemetry::sLock; -uint32_t DetailedCacheHitTelemetry::sRecordCnt = 0; -DetailedCacheHitTelemetry::HitRate DetailedCacheHitTelemetry::sHRStats[kNumOfRanges]; - -DetailedCacheHitTelemetry::HitRate::HitRate() -{ - Reset(); -} - -void -DetailedCacheHitTelemetry::HitRate::AddRecord(ERecType aType) -{ - if (aType == HIT) { - ++mHitCnt; - } else { - ++mMissCnt; - } -} - -uint32_t -DetailedCacheHitTelemetry::HitRate::GetHitRateBucket(uint32_t aNumOfBuckets) const -{ - uint32_t bucketIdx = (aNumOfBuckets * mHitCnt) / (mHitCnt + mMissCnt); - if (bucketIdx == aNumOfBuckets) { // make sure 100% falls into the last bucket - --bucketIdx; - } - - return bucketIdx; -} - -uint32_t -DetailedCacheHitTelemetry::HitRate::Count() -{ - return mHitCnt + mMissCnt; -} - -void -DetailedCacheHitTelemetry::HitRate::Reset() -{ - mHitCnt = 0; - mMissCnt = 0; -} - -// static -void -DetailedCacheHitTelemetry::AddRecord(ERecType aType, TimeStamp aLoadStart) -{ - bool isUpToDate = false; - CacheIndex::IsUpToDate(&isUpToDate); - if (!isUpToDate) { - // Ignore the record when the entry file count might be incorrect - return; - } - - uint32_t entryCount; - nsresult rv = CacheIndex::GetEntryFileCount(&entryCount); - if (NS_FAILED(rv)) { - return; - } - - uint32_t rangeIdx = entryCount / kRangeSize; - if (rangeIdx >= kNumOfRanges) { // The last range has no upper limit. - rangeIdx = kNumOfRanges - 1; - } - - uint32_t hitMissValue = 2 * rangeIdx; // 2 values per range - if (aType == MISS) { // The order is HIT, MISS - ++hitMissValue; - } - - StaticMutexAutoLock lock(sLock); - - if (aType == MISS) { - mozilla::Telemetry::AccumulateTimeDelta( - mozilla::Telemetry::NETWORK_CACHE_V2_MISS_TIME_MS, - aLoadStart); - } else { - mozilla::Telemetry::AccumulateTimeDelta( - mozilla::Telemetry::NETWORK_CACHE_V2_HIT_TIME_MS, - aLoadStart); - } - - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_HIT_MISS_STAT_PER_CACHE_SIZE, - hitMissValue); - - sHRStats[rangeIdx].AddRecord(aType); - ++sRecordCnt; - - if (sRecordCnt < kTotalSamplesReportLimit) { - return; - } - - sRecordCnt = 0; - - for (uint32_t i = 0; i < kNumOfRanges; ++i) { - if (sHRStats[i].Count() >= kHitRateSamplesReportLimit) { - // The telemetry enums are grouped by buckets as follows: - // Telemetry value : 0,1,2,3, ... ,19,20,21,22, ... ,398,399 - // Hit rate bucket : 0,0,0,0, ... , 0, 1, 1, 1, ... , 19, 19 - // Cache size range: 0,1,2,3, ... ,19, 0, 1, 2, ... , 18, 19 - uint32_t bucketOffset = sHRStats[i].GetHitRateBucket(kHitRateBuckets) * - kNumOfRanges; - - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_HIT_RATE_PER_CACHE_SIZE, - bucketOffset + i); - sHRStats[i].Reset(); - } - } -} - void FreeBuffer(void *aBuf) { #ifndef NS_FREE_PERMANENT_DATA diff --git a/netwerk/cache2/CacheFileUtils.h b/netwerk/cache2/CacheFileUtils.h index 3371c3eb5..b66f0adf1 100644 --- a/netwerk/cache2/CacheFileUtils.h +++ b/netwerk/cache2/CacheFileUtils.h @@ -10,7 +10,6 @@ #include "nsString.h" #include "nsTArray.h" #include "mozilla/StaticMutex.h" -#include "mozilla/TimeStamp.h" class nsILoadContextInfo; class nsACString; @@ -90,64 +89,6 @@ private: nsTArray<ValidityPair> mMap; }; - -class DetailedCacheHitTelemetry { -public: - enum ERecType { - HIT = 0, - MISS = 1 - }; - - static void AddRecord(ERecType aType, TimeStamp aLoadStart); - -private: - class HitRate { - public: - HitRate(); - - void AddRecord(ERecType aType); - // Returns the bucket index that the current hit rate falls into according - // to the given aNumOfBuckets. - uint32_t GetHitRateBucket(uint32_t aNumOfBuckets) const; - uint32_t Count(); - void Reset(); - - private: - uint32_t mHitCnt; - uint32_t mMissCnt; - }; - - // Group the hits and misses statistics by cache files count ranges (0-5000, - // 5001-10000, ... , 95001- ) - static const uint32_t kRangeSize = 5000; - static const uint32_t kNumOfRanges = 20; - - // Use the same ranges to report an average hit rate. Report the hit rates - // (and reset the counters) every kTotalSamplesReportLimit samples. - static const uint32_t kTotalSamplesReportLimit = 1000; - - // Report hit rate for a given cache size range only if it contains - // kHitRateSamplesReportLimit or more samples. This limit should avoid - // reporting a biased statistics. - static const uint32_t kHitRateSamplesReportLimit = 500; - - // All hit rates are accumulated in a single telemetry probe, so to use - // a sane number of enumerated values the hit rate is divided into buckets - // instead of using a percent value. This constant defines number of buckets - // that we divide the hit rates into. I.e. we'll report ranges 0%-5%, 5%-10%, - // 10-%15%, ... - static const uint32_t kHitRateBuckets = 20; - - // Protects sRecordCnt, sHitStats and Telemetry::Accumulated() calls. - static StaticMutex sLock; - - // Counter of samples that is compared against kTotalSamplesReportLimit. - static uint32_t sRecordCnt; - - // Hit rate statistics for every cache size range. - static HitRate sHRStats[kNumOfRanges]; -}; - void FreeBuffer(void *aBuf); diff --git a/netwerk/cache2/CacheIOThread.cpp b/netwerk/cache2/CacheIOThread.cpp index b96f03216..2fbc0ccce 100644 --- a/netwerk/cache2/CacheIOThread.cpp +++ b/netwerk/cache2/CacheIOThread.cpp @@ -18,56 +18,6 @@ namespace mozilla { namespace net { -namespace { // anon - -class CacheIOTelemetry -{ -public: - typedef CacheIOThread::EventQueue::size_type size_type; - static size_type mMinLengthToReport[CacheIOThread::LAST_LEVEL]; - static void Report(uint32_t aLevel, size_type aLength); -}; - -static CacheIOTelemetry::size_type const kGranularity = 30; - -CacheIOTelemetry::size_type -CacheIOTelemetry::mMinLengthToReport[CacheIOThread::LAST_LEVEL] = { - kGranularity, kGranularity, kGranularity, kGranularity, - kGranularity, kGranularity, kGranularity, kGranularity -}; - -// static -void CacheIOTelemetry::Report(uint32_t aLevel, CacheIOTelemetry::size_type aLength) -{ - if (mMinLengthToReport[aLevel] > aLength) { - return; - } - - static Telemetry::ID telemetryID[] = { - Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_READ_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_MANAGEMENT, - Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN, - Telemetry::HTTP_CACHE_IO_QUEUE_2_READ, - Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE, - Telemetry::HTTP_CACHE_IO_QUEUE_2_INDEX, - Telemetry::HTTP_CACHE_IO_QUEUE_2_EVICT - }; - - // Each bucket is a multiply of kGranularity (30, 60, 90..., 300+) - aLength = (aLength / kGranularity); - // Next time report only when over the current length + kGranularity - mMinLengthToReport[aLevel] = (aLength + 1) * kGranularity; - - // 10 is number of buckets we have in each probe - aLength = std::min<size_type>(aLength, 10); - - Telemetry::Accumulate(telemetryID[aLevel], aLength - 1); // counted from 0 -} - -} // anon - namespace detail { /** @@ -527,7 +477,6 @@ void CacheIOThread::LoopOneLevel(uint32_t aLevel) mCurrentlyExecutingLevel = aLevel; bool returnEvents = false; - bool reportTelementry = true; EventQueue::size_type index; { @@ -541,11 +490,6 @@ void CacheIOThread::LoopOneLevel(uint32_t aLevel) break; } - if (reportTelementry) { - reportTelementry = false; - CacheIOTelemetry::Report(aLevel, length); - } - // Drop any previous flagging, only an event on the current level may set // this flag. mRerunCurrentEvent = false; diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index 4525bbe6d..2c6451d72 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -20,7 +20,6 @@ #include "nsITimer.h" #include "mozilla/AutoRestore.h" #include <algorithm> -#include "mozilla/Telemetry.h" #include "mozilla/Unused.h" @@ -1295,29 +1294,6 @@ CacheIndex::GetCacheSize(uint32_t *_retval) // static nsresult -CacheIndex::GetEntryFileCount(uint32_t *_retval) -{ - LOG(("CacheIndex::GetEntryFileCount()")); - - StaticMutexAutoLock lock(sLock); - - RefPtr<CacheIndex> index = gInstance; - - if (!index) { - return NS_ERROR_NOT_INITIALIZED; - } - - if (!index->IsIndexUsable()) { - return NS_ERROR_NOT_AVAILABLE; - } - - *_retval = index->mIndexStats.ActiveEntriesCount(); - LOG(("CacheIndex::GetEntryFileCount() - returning %u", *_retval)); - return NS_OK; -} - -// static -nsresult CacheIndex::GetCacheStats(nsILoadContextInfo *aInfo, uint32_t *aSize, uint32_t *aCount) { LOG(("CacheIndex::GetCacheStats() [info=%p]", aInfo)); @@ -3167,11 +3143,6 @@ CacheIndex::ChangeState(EState aNewState) return; } - if ((mState == READING || mState == BUILDING || mState == UPDATING) && - aNewState == READY) { - ReportHashStats(); - } - // Try to evict entries over limit everytime we're leaving state READING, // BUILDING or UPDATING, but not during shutdown or when removing all // entries. @@ -3720,76 +3691,6 @@ CacheIndex::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) return mallocSizeOf(gInstance) + SizeOfExcludingThis(mallocSizeOf); } -namespace { - -class HashComparator -{ -public: - bool Equals(CacheIndexRecord* a, CacheIndexRecord* b) const { - return memcmp(&a->mHash, &b->mHash, sizeof(SHA1Sum::Hash)) == 0; - } - bool LessThan(CacheIndexRecord* a, CacheIndexRecord* b) const { - return memcmp(&a->mHash, &b->mHash, sizeof(SHA1Sum::Hash)) < 0; - } -}; - -void -ReportHashSizeMatch(const SHA1Sum::Hash *aHash1, const SHA1Sum::Hash *aHash2) -{ - const uint32_t *h1 = reinterpret_cast<const uint32_t *>(aHash1); - const uint32_t *h2 = reinterpret_cast<const uint32_t *>(aHash2); - - for (uint32_t i = 0; i < 5; ++i) { - if (h1[i] != h2[i]) { - uint32_t bitsDiff = h1[i] ^ h2[i]; - bitsDiff = NetworkEndian::readUint32(&bitsDiff); - - // count leading zeros in bitsDiff - static const uint8_t debruijn32[32] = - { 0, 31, 9, 30, 3, 8, 13, 29, 2, 5, 7, 21, 12, 24, 28, 19, - 1, 10, 4, 14, 6, 22, 25, 20, 11, 15, 23, 26, 16, 27, 17, 18}; - - bitsDiff |= bitsDiff>>1; - bitsDiff |= bitsDiff>>2; - bitsDiff |= bitsDiff>>4; - bitsDiff |= bitsDiff>>8; - bitsDiff |= bitsDiff>>16; - bitsDiff++; - - uint8_t hashSizeMatch = debruijn32[bitsDiff*0x076be629>>27] + (i<<5); - Telemetry::Accumulate(Telemetry::NETWORK_CACHE_HASH_STATS, hashSizeMatch); - - return; - } - } - - MOZ_ASSERT(false, "Found a collision in the index!"); -} - -} // namespace - -void -CacheIndex::ReportHashStats() -{ - // We're gathering the hash stats only once, exclude too small caches. - if (CacheObserver::HashStatsReported() || mFrecencyArray.Length() < 15000) { - return; - } - - nsTArray<CacheIndexRecord *> records; - for (auto iter = mFrecencyArray.Iter(); !iter.Done(); iter.Next()) { - records.AppendElement(iter.Get()); - } - - records.Sort(HashComparator()); - - for (uint32_t i = 1; i < records.Length(); i++) { - ReportHashSizeMatch(&records[i-1]->mHash, &records[i]->mHash); - } - - CacheObserver::SetHashStatsReported(); -} - // static void CacheIndex::OnAsyncEviction(bool aEvicting) diff --git a/netwerk/cache2/CacheIndex.h b/netwerk/cache2/CacheIndex.h index dc72c346f..acb3bdd25 100644 --- a/netwerk/cache2/CacheIndex.h +++ b/netwerk/cache2/CacheIndex.h @@ -662,9 +662,6 @@ public: // Returns cache size in kB. static nsresult GetCacheSize(uint32_t *_retval); - // Returns number of entry files in the cache - static nsresult GetEntryFileCount(uint32_t *_retval); - // Synchronously returns the disk occupation and number of entries per-context. // Callable on any thread. static nsresult GetCacheStats(nsILoadContextInfo *aInfo, uint32_t *aSize, uint32_t *aCount); @@ -918,8 +915,6 @@ private: // Memory reporting (private part) size_t SizeOfExcludingThisInternal(mozilla::MallocSizeOf mallocSizeOf) const; - void ReportHashStats(); - static mozilla::StaticRefPtr<CacheIndex> gInstance; static StaticMutex sLock; diff --git a/netwerk/cache2/CacheObserver.cpp b/netwerk/cache2/CacheObserver.cpp index 6b6d89395..32e0dff95 100644 --- a/netwerk/cache2/CacheObserver.cpp +++ b/netwerk/cache2/CacheObserver.cpp @@ -86,12 +86,6 @@ bool CacheObserver::sSanitizeOnShutdown = kDefaultSanitizeOnShutdown; static bool kDefaultClearCacheOnShutdown = false; bool CacheObserver::sClearCacheOnShutdown = kDefaultClearCacheOnShutdown; -static bool kDefaultCacheFSReported = false; -bool CacheObserver::sCacheFSReported = kDefaultCacheFSReported; - -static bool kDefaultHashStatsReported = false; -bool CacheObserver::sHashStatsReported = kDefaultHashStatsReported; - static uint32_t const kDefaultMaxShutdownIOLag = 2; // seconds Atomic<uint32_t, Relaxed> CacheObserver::sMaxShutdownIOLag(kDefaultMaxShutdownIOLag); @@ -331,58 +325,6 @@ CacheObserver::StoreDiskCacheCapacity() } // static -void -CacheObserver::SetCacheFSReported() -{ - sCacheFSReported = true; - - if (!sSelf) { - return; - } - - if (NS_IsMainThread()) { - sSelf->StoreCacheFSReported(); - } else { - nsCOMPtr<nsIRunnable> event = - NewRunnableMethod(sSelf, &CacheObserver::StoreCacheFSReported); - NS_DispatchToMainThread(event); - } -} - -void -CacheObserver::StoreCacheFSReported() -{ - mozilla::Preferences::SetInt("browser.cache.disk.filesystem_reported", - sCacheFSReported); -} - -// static -void -CacheObserver::SetHashStatsReported() -{ - sHashStatsReported = true; - - if (!sSelf) { - return; - } - - if (NS_IsMainThread()) { - sSelf->StoreHashStatsReported(); - } else { - nsCOMPtr<nsIRunnable> event = - NewRunnableMethod(sSelf, &CacheObserver::StoreHashStatsReported); - NS_DispatchToMainThread(event); - } -} - -void -CacheObserver::StoreHashStatsReported() -{ - mozilla::Preferences::SetInt("browser.cache.disk.hashstats_reported", - sHashStatsReported); -} - -// static void CacheObserver::ParentDirOverride(nsIFile** aDir) { if (NS_WARN_IF(!aDir)) diff --git a/netwerk/cache2/CacheObserver.h b/netwerk/cache2/CacheObserver.h index 62e5bbc6e..ccdd89030 100644 --- a/netwerk/cache2/CacheObserver.h +++ b/netwerk/cache2/CacheObserver.h @@ -61,12 +61,6 @@ class CacheObserver : public nsIObserver { return sHalfLifeExperiment; } static bool ClearCacheOnShutdown() { return sSanitizeOnShutdown && sClearCacheOnShutdown; } - static bool CacheFSReported() - { return sCacheFSReported; } - static void SetCacheFSReported(); - static bool HashStatsReported() - { return sHashStatsReported; } - static void SetHashStatsReported(); static void ParentDirOverride(nsIFile ** aDir); static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk); @@ -82,8 +76,6 @@ private: static CacheObserver* sSelf; void StoreDiskCacheCapacity(); - void StoreCacheFSReported(); - void StoreHashStatsReported(); void AttachToPreferences(); static uint32_t sUseNewCache; @@ -106,8 +98,6 @@ private: static int32_t sHalfLifeExperiment; static bool sSanitizeOnShutdown; static bool sClearCacheOnShutdown; - static bool sCacheFSReported; - static bool sHashStatsReported; static Atomic<uint32_t, Relaxed> sMaxShutdownIOLag; static Atomic<PRIntervalTime> sShutdownDemandedTime; diff --git a/netwerk/cache2/CacheStorageService.cpp b/netwerk/cache2/CacheStorageService.cpp index 67ef4c526..3ee1e15cd 100644 --- a/netwerk/cache2/CacheStorageService.cpp +++ b/netwerk/cache2/CacheStorageService.cpp @@ -964,8 +964,6 @@ CacheStorageService::RegisterEntry(CacheEntry* aEntry) if (mShutdown || !aEntry->CanRegister()) return; - TelemetryRecordEntryCreation(aEntry); - LOG(("CacheStorageService::RegisterEntry [entry=%p]", aEntry)); MemoryPool& pool = Pool(aEntry->IsUsingDisk()); @@ -983,8 +981,6 @@ CacheStorageService::UnregisterEntry(CacheEntry* aEntry) if (!aEntry->IsRegistered()) return; - TelemetryRecordEntryRemoval(aEntry); - LOG(("CacheStorageService::UnregisterEntry [entry=%p]", aEntry)); MemoryPool& pool = Pool(aEntry->IsUsingDisk()); @@ -2018,105 +2014,6 @@ uint32_t CacheStorageService::CacheQueueSize(bool highPriority) return thread->QueueSize(highPriority); } -// Telementry collection - -namespace { - -bool TelemetryEntryKey(CacheEntry const* entry, nsAutoCString& key) -{ - nsAutoCString entryKey; - nsresult rv = entry->HashingKey(entryKey); - if (NS_FAILED(rv)) - return false; - - if (entry->GetStorageID().IsEmpty()) { - // Hopefully this will be const-copied, saves some memory - key = entryKey; - } else { - key.Assign(entry->GetStorageID()); - key.Append(':'); - key.Append(entryKey); - } - - return true; -} - -} // namespace - -void -CacheStorageService::TelemetryPrune(TimeStamp &now) -{ - static TimeDuration const oneMinute = TimeDuration::FromSeconds(60); - static TimeStamp dontPruneUntil = now + oneMinute; - if (now < dontPruneUntil) - return; - - static TimeDuration const fifteenMinutes = TimeDuration::FromSeconds(900); - for (auto iter = mPurgeTimeStamps.Iter(); !iter.Done(); iter.Next()) { - if (now - iter.Data() > fifteenMinutes) { - // We are not interested in resurrection of entries after 15 minutes - // of time. This is also the limit for the telemetry. - iter.Remove(); - } - } - dontPruneUntil = now + oneMinute; -} - -void -CacheStorageService::TelemetryRecordEntryCreation(CacheEntry const* entry) -{ - MOZ_ASSERT(CacheStorageService::IsOnManagementThread()); - - nsAutoCString key; - if (!TelemetryEntryKey(entry, key)) - return; - - TimeStamp now = TimeStamp::NowLoRes(); - TelemetryPrune(now); - - // When an entry is craeted (registered actually) we check if there is - // a timestamp marked when this very same cache entry has been removed - // (deregistered) because of over-memory-limit purging. If there is such - // a timestamp found accumulate telemetry on how long the entry was away. - TimeStamp timeStamp; - if (!mPurgeTimeStamps.Get(key, &timeStamp)) - return; - - mPurgeTimeStamps.Remove(key); - - Telemetry::AccumulateTimeDelta(Telemetry::HTTP_CACHE_ENTRY_RELOAD_TIME, - timeStamp, TimeStamp::NowLoRes()); -} - -void -CacheStorageService::TelemetryRecordEntryRemoval(CacheEntry const* entry) -{ - MOZ_ASSERT(CacheStorageService::IsOnManagementThread()); - - // Doomed entries must not be considered, we are only interested in purged - // entries. Note that the mIsDoomed flag is always set before deregistration - // happens. - if (entry->IsDoomed()) - return; - - nsAutoCString key; - if (!TelemetryEntryKey(entry, key)) - return; - - // When an entry is removed (deregistered actually) we put a timestamp for this - // entry to the hashtable so that when the entry is created (registered) again - // we know how long it was away. Also accumulate number of AsyncOpen calls on - // the entry, this tells us how efficiently the pool actually works. - - TimeStamp now = TimeStamp::NowLoRes(); - TelemetryPrune(now); - mPurgeTimeStamps.Put(key, now); - - Telemetry::Accumulate(Telemetry::HTTP_CACHE_ENTRY_REUSE_COUNT, entry->UseCount()); - Telemetry::AccumulateTimeDelta(Telemetry::HTTP_CACHE_ENTRY_ALIVE_TIME, - entry->LoadStart(), TimeStamp::NowLoRes()); -} - // nsIMemoryReporter size_t diff --git a/netwerk/cache2/CacheStorageService.h b/netwerk/cache2/CacheStorageService.h index f40459d84..7e968e359 100644 --- a/netwerk/cache2/CacheStorageService.h +++ b/netwerk/cache2/CacheStorageService.h @@ -188,12 +188,6 @@ private: bool IsForcedValidEntry(nsACString const &aEntryKeyWithContext); private: - // These are helpers for telemetry monitoring of the memory pools. - void TelemetryPrune(TimeStamp &now); - void TelemetryRecordEntryCreation(CacheEntry const* entry); - void TelemetryRecordEntryRemoval(CacheEntry const* entry); - -private: // Following methods are thread safe to call. friend class CacheStorage; @@ -370,12 +364,6 @@ private: uint32_t mWhat; }; - // Used just for telemetry purposes, accessed only on the management thread. - // Note: not included in the memory reporter, this is not expected to be huge - // and also would be complicated to report since reporting happens on the main - // thread but this table is manipulated on the management thread. - nsDataHashtable<nsCStringHashKey, mozilla::TimeStamp> mPurgeTimeStamps; - // nsICacheTesting class IOThreadSuspender : public Runnable { diff --git a/netwerk/cache2/OldWrappers.cpp b/netwerk/cache2/OldWrappers.cpp index 81df88df0..76a4fa6c1 100644 --- a/netwerk/cache2/OldWrappers.cpp +++ b/netwerk/cache2/OldWrappers.cpp @@ -21,7 +21,6 @@ #include "nsNetCID.h" #include "nsNetUtil.h" #include "nsProxyRelease.h" -#include "mozilla/Telemetry.h" static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID); @@ -793,24 +792,6 @@ _OldCacheLoad::Run() return NS_OK; } - if (NS_SUCCEEDED(mStatus)) { - if (mFlags & nsICacheStorage::OPEN_TRUNCATE) { - mozilla::Telemetry::AccumulateTimeDelta( - mozilla::Telemetry::NETWORK_CACHE_V1_TRUNCATE_TIME_MS, - mLoadStart); - } - else if (mNew) { - mozilla::Telemetry::AccumulateTimeDelta( - mozilla::Telemetry::NETWORK_CACHE_V1_MISS_TIME_MS, - mLoadStart); - } - else { - mozilla::Telemetry::AccumulateTimeDelta( - mozilla::Telemetry::NETWORK_CACHE_V1_HIT_TIME_MS, - mLoadStart); - } - } - if (!(mFlags & CHECK_MULTITHREADED)) Check(); diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 1c4e5e740..6740f7310 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -49,7 +49,6 @@ #include "mozilla/storage.h" #include "mozilla/AutoRestore.h" #include "mozilla/FileUtils.h" -#include "mozilla/Telemetry.h" #include "nsIAppsService.h" #include "mozIApplication.h" #include "mozIApplicationClearPrivateDataParams.h" @@ -120,15 +119,6 @@ static const char kPrefCookiePurgeAge[] = "network.cookie.purgeAge"; static const char kPrefThirdPartySession[] = "network.cookie.thirdparty.sessionOnly"; static const char kCookieLeaveSecurityAlone[] = "network.cookie.leave-secure-alone"; -// For telemetry COOKIE_LEAVE_SECURE_ALONE -#define BLOCKED_SECURE_SET_FROM_HTTP 0 -#define BLOCKED_DOWNGRADE_SECURE 1 -#define DOWNGRADE_SECURE_FROM_SECURE 2 -#define EVICTED_NEWER_INSECURE 3 -#define EVICTED_OLDEST_COOKIE 4 -#define EVICTED_PREFERRED_COOKIE 5 -#define EVICTING_SECURE_BLOCKED 6 - static void bindCookieParameters(mozIStorageBindingParamsArray *aParamsArray, const nsCookieKey &aKey, @@ -954,19 +944,14 @@ nsCookieService::TryInitDB(bool aRecreateDB) NS_ENSURE_SUCCESS(rv, RESULT_FAILURE); } - // This block provides scope for the Telemetry AutoTimer - { - Telemetry::AutoTimer<Telemetry::MOZ_SQLITE_COOKIES_OPEN_READAHEAD_MS> - telemetry; - ReadAheadFile(mDefaultDBState->cookieFile); - - // open a connection to the cookie database, and only cache our connection - // and statements upon success. The connection is opened unshared to eliminate - // cache contention between the main and background threads. - rv = mStorageService->OpenUnsharedDatabase(mDefaultDBState->cookieFile, - getter_AddRefs(mDefaultDBState->dbConn)); - NS_ENSURE_SUCCESS(rv, RESULT_RETRY); - } + ReadAheadFile(mDefaultDBState->cookieFile); + + // open a connection to the cookie database, and only cache our connection + // and statements upon success. The connection is opened unshared to eliminate + // cache contention between the main and background threads. + rv = mStorageService->OpenUnsharedDatabase(mDefaultDBState->cookieFile, + getter_AddRefs(mDefaultDBState->dbConn)); + NS_ENSURE_SUCCESS(rv, RESULT_RETRY); // Set up our listeners. mDefaultDBState->insertListener = new InsertCookieDBListener(mDefaultDBState); @@ -3316,20 +3301,8 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI, // so we can handle them separately. bool newCookie = ParseAttributes(aCookieHeader, cookieAttributes); - // Collect telemetry on how often secure cookies are set from non-secure - // origins, and vice-versa. - // - // 0 = nonsecure and "http:" - // 1 = nonsecure and "https:" - // 2 = secure and "http:" - // 3 = secure and "https:" bool isHTTPS; nsresult rv = aHostURI->SchemeIs("https", &isHTTPS); - if (NS_SUCCEEDED(rv)) { - Telemetry::Accumulate(Telemetry::COOKIE_SCHEME_SECURITY, - ((cookieAttributes.isSecure)? 0x02 : 0x00) | - ((isHTTPS)? 0x01 : 0x00)); - } int64_t currentTimeInUsec = PR_Now(); @@ -3480,8 +3453,6 @@ nsCookieService::AddInternal(const nsCookieKey &aKey, if (mLeaveSecureAlone && aCookie->IsSecure() && !isSecure) { COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "non-https cookie can't set secure flag"); - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - BLOCKED_SECURE_SET_FROM_HTTP); return; } nsListIter exactIter; @@ -3502,14 +3473,7 @@ nsCookieService::AddInternal(const nsCookieKey &aKey, if (!isSecure) { COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "cookie can't save because older cookie is secure cookie but newer cookie is non-secure cookie"); - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - BLOCKED_DOWNGRADE_SECURE); return; - } else { - // A secure site is allowed to downgrade a secure cookie - // but we want to measure anyway - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - DOWNGRADE_SECURE_FROM_SECURE); } } } @@ -3609,8 +3573,6 @@ nsCookieService::AddInternal(const nsCookieKey &aKey, // It's valid to evict a secure cookie for another secure cookie. oldestCookieTime = FindStaleCookie(entry, currentTime, aHostURI, Some(true), iter); } else { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - EVICTING_SECURE_BLOCKED); COOKIE_LOGEVICTED(aCookie, "Too many cookies for this domain and the new cookie is not a secure cookie"); return; @@ -3620,9 +3582,6 @@ nsCookieService::AddInternal(const nsCookieKey &aKey, MOZ_ASSERT(iter.entry); oldCookie = iter.Cookie(); - if (oldestCookieTime > 0 && mLeaveSecureAlone) { - TelemetryForEvictingStaleCookie(oldCookie, oldestCookieTime); - } // remove the oldest cookie from the domain RemoveCookieFromList(iter); @@ -4647,25 +4606,6 @@ nsCookieService::FindStaleCookie(nsCookieEntry *aEntry, return actualOldestCookieTime; } -void -nsCookieService::TelemetryForEvictingStaleCookie(nsCookie *aEvicted, - int64_t oldestCookieTime) -{ - // We need to record the evicting cookie to telemetry. - if (!aEvicted->IsSecure()) { - if (aEvicted->LastAccessed() > oldestCookieTime) { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - EVICTED_NEWER_INSECURE); - } else { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - EVICTED_OLDEST_COOKIE); - } - } else { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - EVICTED_PREFERRED_COOKIE); - } -} - // count the number of cookies stored by a particular host. this is provided by the // nsICookieManager2 interface. NS_IMETHODIMP diff --git a/netwerk/cookie/nsCookieService.h b/netwerk/cookie/nsCookieService.h index e3b2d3e8a..185f0b492 100644 --- a/netwerk/cookie/nsCookieService.h +++ b/netwerk/cookie/nsCookieService.h @@ -314,7 +314,6 @@ class nsCookieService final : public nsICookieService bool FindCookie(const nsCookieKey& aKey, const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter); bool FindSecureCookie(const nsCookieKey& aKey, nsCookie* aCookie); int64_t FindStaleCookie(nsCookieEntry *aEntry, int64_t aCurrentTime, nsIURI* aSource, mozilla::Maybe<bool> aIsSecure, nsListIter &aIter); - void TelemetryForEvictingStaleCookie(nsCookie* aEvicted, int64_t oldestCookieTime); void NotifyRejected(nsIURI *aHostURI); void NotifyThirdParty(nsIURI *aHostURI, bool aAccepted, nsIChannel *aChannel); void NotifyChanged(nsISupports *aSubject, const char16_t *aData); diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index f2e26cadd..323470c34 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -32,7 +32,6 @@ #include "mozilla/HashFunctions.h" #include "mozilla/TimeStamp.h" -#include "mozilla/Telemetry.h" #include "mozilla/DebugOnly.h" #include "mozilla/Preferences.h" @@ -225,7 +224,6 @@ nsHostRecord::CopyExpirationTimesAndFlagsFrom(const nsHostRecord *aFromHostRecor nsHostRecord::~nsHostRecord() { - Telemetry::Accumulate(Telemetry::DNS_BLACKLIST_COUNT, mBlacklistedCount); delete addr_info; delete addr; } @@ -775,7 +773,6 @@ nsHostResolver::ResolveHost(const char *host, LOG_HOST(host, netInterface))); // put reference to host record on stack... result = he->rec; - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT); // For entries that are in the grace period // or all cached negative entries, use the cache but start a new @@ -785,8 +782,6 @@ nsHostResolver::ResolveHost(const char *host, if (he->rec->negative) { LOG((" Negative cache entry for host [%s%s%s].\n", LOG_HOST(host, netInterface))); - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_NEGATIVE_HIT); status = NS_ERROR_UNKNOWN_HOST; } } @@ -794,8 +789,6 @@ nsHostResolver::ResolveHost(const char *host, // go ahead and use it. else if (he->rec->addr) { LOG((" Using cached address for IP Literal [%s].\n", host)); - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_LITERAL); result = he->rec; } // try parsing the host name as an IP address literal to short @@ -808,8 +801,6 @@ nsHostResolver::ResolveHost(const char *host, he->rec->addr = new NetAddr(); PRNetAddrToNetAddr(&tempAddr, he->rec->addr); // put reference to host record on stack... - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_LITERAL); result = he->rec; } else if (mPendingCount >= MAX_NON_PRIORITY_REQUESTS && @@ -819,8 +810,6 @@ nsHostResolver::ResolveHost(const char *host, "host [%s%s%s].\n", IsMediumPriority(flags) ? "medium" : "low", LOG_HOST(host, netInterface))); - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_OVERFLOW); // This is a lower priority request and we are swamped, so refuse it. rv = NS_ERROR_DNS_LOOKUP_QUEUE_FULL; } @@ -885,8 +874,6 @@ nsHostResolver::ResolveHost(const char *host, if (he->rec->negative) { status = NS_ERROR_UNKNOWN_HOST; } - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_HIT); ConditionallyRefreshRecord(he->rec, host); } // For AF_INET6, a new lookup means another AF_UNSPEC @@ -900,8 +887,6 @@ nsHostResolver::ResolveHost(const char *host, result = he->rec; he->rec->negative = true; status = NS_ERROR_UNKNOWN_HOST; - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_NEGATIVE_HIT); } } } @@ -915,8 +900,6 @@ nsHostResolver::ResolveHost(const char *host, PR_APPEND_LINK(callback, &he->rec->callbacks); he->rec->flags = flags; rv = IssueLookup(he->rec); - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_NETWORK_FIRST); if (NS_FAILED(rv)) { PR_REMOVE_AND_INIT_LINK(callback); } @@ -933,8 +916,6 @@ nsHostResolver::ResolveHost(const char *host, PR_APPEND_LINK(callback, &he->rec->callbacks); if (he->rec->onQueue) { - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_NETWORK_SHARED); // Consider the case where we are on a pending queue of // lower priority than the request is being made at. @@ -1085,13 +1066,6 @@ nsHostResolver::ConditionallyRefreshRecord(nsHostRecord *rec, const char *host) LOG((" Using %s cache entry for host [%s] but starting async renewal.", rec->negative ? "negative" :"positive", host)); IssueLookup(rec); - - if (!rec->negative) { - // negative entries are constantly being refreshed, only - // track positive grace period induced renewals - Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, - METHOD_RENEWAL); - } } return NS_OK; } @@ -1326,13 +1300,6 @@ nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, AddrInfo* n PR_REMOVE_AND_INIT_LINK(head); mDB.Remove((nsHostKey *) head); - if (!head->negative) { - // record the age of the entry upon eviction. - TimeDuration age = TimeStamp::NowLoRes() - head->mValidStart; - Telemetry::Accumulate(Telemetry::DNS_CLEANUP_AGE, - static_cast<uint32_t>(age.ToSeconds() / 60)); - } - // release reference to rec owned by mEvictionQ NS_RELEASE(head); } @@ -1451,7 +1418,6 @@ nsHostResolver::ThreadFunc(void *arg) LOG(("DNS lookup thread - Calling getaddrinfo for host [%s%s%s].\n", LOG_HOST(rec->host, rec->netInterface))); - TimeStamp startTime = TimeStamp::Now(); #if TTL_AVAILABLE bool getTtl = rec->mGetTtl; #else @@ -1467,32 +1433,6 @@ nsHostResolver::ThreadFunc(void *arg) } #endif - { // obtain lock to check shutdown and manage inter-module telemetry - MutexAutoLock lock(resolver->mLock); - - if (!resolver->mShutdown) { - TimeDuration elapsed = TimeStamp::Now() - startTime; - uint32_t millis = static_cast<uint32_t>(elapsed.ToMilliseconds()); - - if (NS_SUCCEEDED(status)) { - Telemetry::ID histogramID; - if (!rec->addr_info_gencnt) { - // Time for initial lookup. - histogramID = Telemetry::DNS_LOOKUP_TIME; - } else if (!getTtl) { - // Time for renewal; categorized by expiration strategy. - histogramID = Telemetry::DNS_RENEWAL_TIME; - } else { - // Time to get TTL; categorized by expiration strategy. - histogramID = Telemetry::DNS_RENEWAL_TIME_FOR_TTL; - } - Telemetry::Accumulate(histogramID, millis); - } else { - Telemetry::Accumulate(Telemetry::DNS_FAILED_LOOKUP_TIME, millis); - } - } - } - // OnLookupComplete may release "rec", long before we lose it. LOG(("DNS lookup thread - lookup completed for host [%s%s%s]: %s.\n", LOG_HOST(rec->host, rec->netInterface), diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index 2633ef608..2896f427d 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -56,6 +56,7 @@ struct LoadInfoArgs bool forcePreflight; bool isPreflight; bool loadTriggeredFromExternal; + bool isFromProcessingFrameAttributes; }; /** diff --git a/netwerk/mime/nsMimeTypes.h b/netwerk/mime/nsMimeTypes.h index 215d20507..57a85e9bc 100644 --- a/netwerk/mime/nsMimeTypes.h +++ b/netwerk/mime/nsMimeTypes.h @@ -107,6 +107,9 @@ #define IMAGE_TIFF "image/tiff" #define IMAGE_BMP "image/bmp" #define IMAGE_BMP_MS "image/x-ms-bmp" +// This is used internally to represent Windows clipboard BMPs which remove +// part of the header. +#define IMAGE_BMP_MS_CLIPBOARD "image/x-ms-clipboard-bmp" #define IMAGE_ICO "image/x-icon" #define IMAGE_ICO_MS "image/vnd.microsoft.icon" #define IMAGE_ICON_MS "image/icon" diff --git a/netwerk/protocol/ftp/FTPChannelChild.cpp b/netwerk/protocol/ftp/FTPChannelChild.cpp index f8284aae3..f52586744 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.cpp +++ b/netwerk/protocol/ftp/FTPChannelChild.cpp @@ -516,33 +516,6 @@ FTPChannelChild::RecvOnStopRequest(const nsresult& aChannelStatus, return true; } -class nsFtpChildAsyncAlert : public Runnable -{ -public: - nsFtpChildAsyncAlert(nsIPrompt *aPrompter, nsString aResponseMsg) - : mPrompter(aPrompter) - , mResponseMsg(aResponseMsg) - { - MOZ_COUNT_CTOR(nsFtpChildAsyncAlert); - } -protected: - virtual ~nsFtpChildAsyncAlert() - { - MOZ_COUNT_DTOR(nsFtpChildAsyncAlert); - } -public: - NS_IMETHOD Run() override - { - if (mPrompter) { - mPrompter->Alert(nullptr, mResponseMsg.get()); - } - return NS_OK; - } -private: - nsCOMPtr<nsIPrompt> mPrompter; - nsString mResponseMsg; -}; - class MaybeDivertOnStopFTPEvent : public ChannelEvent { public: @@ -600,19 +573,7 @@ FTPChannelChild::DoOnStopRequest(const nsresult& aChannelStatus, (void)mListener->OnStopRequest(this, mListenerContext, aChannelStatus); if (NS_FAILED(aChannelStatus) && !aErrorMsg.IsEmpty()) { - nsCOMPtr<nsIPrompt> prompter; - GetCallback(prompter); - if (prompter) { - nsCOMPtr<nsIRunnable> alertEvent; - if (aUseUTF8) { - alertEvent = new nsFtpChildAsyncAlert(prompter, - NS_ConvertUTF8toUTF16(aErrorMsg)); - } else { - alertEvent = new nsFtpChildAsyncAlert(prompter, - NS_ConvertASCIItoUTF16(aErrorMsg)); - } - NS_DispatchToMainThread(alertEvent); - } + NS_ERROR("FTP error on stop request."); } mListener = nullptr; diff --git a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp index 2ae12846a..0dae7ca92 100644 --- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp @@ -29,7 +29,6 @@ #include "nsIStreamListenerTee.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" -#include "nsIStringBundle.h" #include "nsAuthInformationHolder.h" #include "nsIProtocolProxyService.h" #include "nsICancelable.h" @@ -926,38 +925,7 @@ nsFtpState::R_syst() { mServerType = FTP_VMS_TYPE; } else { NS_ERROR("Server type list format unrecognized."); - // Guessing causes crashes. - // (Of course, the parsing code should be more robust...) - nsCOMPtr<nsIStringBundleService> bundleService = - do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if (!bundleService) - return FTP_ERROR; - - nsCOMPtr<nsIStringBundle> bundle; - nsresult rv = bundleService->CreateBundle(NECKO_MSGS_URL, - getter_AddRefs(bundle)); - if (NS_FAILED(rv)) - return FTP_ERROR; - - char16_t* ucs2Response = ToNewUnicode(mResponseMsg); - const char16_t *formatStrings[1] = { ucs2Response }; - NS_NAMED_LITERAL_STRING(name, "UnsupportedFTPServer"); - - nsXPIDLString formattedString; - rv = bundle->FormatStringFromName(name.get(), formatStrings, 1, - getter_Copies(formattedString)); - free(ucs2Response); - if (NS_FAILED(rv)) - return FTP_ERROR; - - // TODO(darin): this code should not be dictating UI like this! - nsCOMPtr<nsIPrompt> prompter; - mChannel->GetCallback(prompter); - if (prompter) - prompter->Alert(nullptr, formattedString.get()); - - // since we just alerted the user, clear mResponseMsg, - // which is displayed to the user. + // clear mResponseMsg, which is displayed to the user. mResponseMsg = ""; return FTP_ERROR; } @@ -1779,34 +1747,6 @@ nsFtpState::KillControlConnection() mControlConnection = nullptr; } -class nsFtpAsyncAlert : public Runnable -{ -public: - nsFtpAsyncAlert(nsIPrompt *aPrompter, nsString aResponseMsg) - : mPrompter(aPrompter) - , mResponseMsg(aResponseMsg) - { - MOZ_COUNT_CTOR(nsFtpAsyncAlert); - } -protected: - virtual ~nsFtpAsyncAlert() - { - MOZ_COUNT_DTOR(nsFtpAsyncAlert); - } -public: - NS_IMETHOD Run() override - { - if (mPrompter) { - mPrompter->Alert(nullptr, mResponseMsg.get()); - } - return NS_OK; - } -private: - nsCOMPtr<nsIPrompt> mPrompter; - nsString mResponseMsg; -}; - - nsresult nsFtpState::StopProcessing() { @@ -1818,23 +1758,8 @@ nsFtpState::StopProcessing() LOG_INFO(("FTP:(%x) nsFtpState stopping", this)); if (NS_FAILED(mInternalError) && !mResponseMsg.IsEmpty()) { - // check to see if the control status is bad. - // web shell wont throw an alert. we better: - - // XXX(darin): this code should not be dictating UI like this! - nsCOMPtr<nsIPrompt> prompter; - mChannel->GetCallback(prompter); - if (prompter) { - nsCOMPtr<nsIRunnable> alertEvent; - if (mUseUTF8) { - alertEvent = new nsFtpAsyncAlert(prompter, - NS_ConvertUTF8toUTF16(mResponseMsg)); - } else { - alertEvent = new nsFtpAsyncAlert(prompter, - NS_ConvertASCIItoUTF16(mResponseMsg)); - } - NS_DispatchToMainThread(alertEvent); - } + NS_ERROR("FTP: bad control status."); + // check to see if the control status is bad; forward the error message. nsCOMPtr<nsIFTPChannelParentInternal> ftpChanP; mChannel->GetCallback(ftpChanP); if (ftpChanP) { diff --git a/netwerk/protocol/http/ASpdySession.cpp b/netwerk/protocol/http/ASpdySession.cpp index f22c326d1..d5d98804d 100644 --- a/netwerk/protocol/http/ASpdySession.cpp +++ b/netwerk/protocol/http/ASpdySession.cpp @@ -45,8 +45,6 @@ ASpdySession::NewSpdySession(uint32_t version, // from a list provided in the SERVER HELLO filtered by our acceptable // versions, so there is no risk of the server ignoring our prefs. - Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version); - return new Http2Session(aTransport, version, attemptingEarlyData); } diff --git a/netwerk/protocol/http/AlternateServices.cpp b/netwerk/protocol/http/AlternateServices.cpp index b3e6babe3..ee2fa9331 100644 --- a/netwerk/protocol/http/AlternateServices.cpp +++ b/netwerk/protocol/http/AlternateServices.cpp @@ -654,8 +654,13 @@ private: { nsID channelId; nsLoadFlags flags; + + nsContentPolicyType contentPolicyType = + loadInfo ? loadInfo->GetExternalContentPolicyType() + : nsIContentPolicy::TYPE_OTHER; + if (NS_FAILED(gHttpHandler->NewChannelId(&channelId)) || - NS_FAILED(chan->Init(uri, caps, nullptr, 0, nullptr, channelId)) || + NS_FAILED(chan->Init(uri, caps, nullptr, 0, nullptr, channelId, contentPolicyType)) || NS_FAILED(chan->SetAllowAltSvc(false)) || NS_FAILED(chan->SetRedirectMode(nsIHttpChannelInternal::REDIRECT_MODE_ERROR)) || NS_FAILED(chan->SetLoadInfo(loadInfo)) || diff --git a/netwerk/protocol/http/Http2Compression.cpp b/netwerk/protocol/http/Http2Compression.cpp index 1b4603e1a..9206f8b4c 100644 --- a/netwerk/protocol/http/Http2Compression.cpp +++ b/netwerk/protocol/http/Http2Compression.cpp @@ -292,12 +292,6 @@ Http2BaseCompressor::Http2BaseCompressor() Http2BaseCompressor::~Http2BaseCompressor() { - if (mPeakSize) { - Telemetry::Accumulate(mPeakSizeID, mPeakSize); - } - if (mPeakCount) { - Telemetry::Accumulate(mPeakCountID, mPeakCount); - } UnregisterStrongMemoryReporter(mDynamicReporter); mDynamicReporter->mCompressor = nullptr; mDynamicReporter = nullptr; @@ -336,16 +330,6 @@ Http2BaseCompressor::MakeRoom(uint32_t amount, const char *direction) bytesEvicted += mHeaderTable[index]->Size(); mHeaderTable.RemoveElement(); } - - if (!strcmp(direction, "decompressor")) { - Telemetry::Accumulate(Telemetry::HPACK_ELEMENTS_EVICTED_DECOMPRESSOR, countEvicted); - Telemetry::Accumulate(Telemetry::HPACK_BYTES_EVICTED_DECOMPRESSOR, bytesEvicted); - Telemetry::Accumulate(Telemetry::HPACK_BYTES_EVICTED_RATIO_DECOMPRESSOR, (uint32_t)((100.0 * (double)bytesEvicted) / (double)amount)); - } else { - Telemetry::Accumulate(Telemetry::HPACK_ELEMENTS_EVICTED_COMPRESSOR, countEvicted); - Telemetry::Accumulate(Telemetry::HPACK_BYTES_EVICTED_COMPRESSOR, bytesEvicted); - Telemetry::Accumulate(Telemetry::HPACK_BYTES_EVICTED_RATIO_COMPRESSOR, (uint32_t)((100.0 * (double)bytesEvicted) / (double)amount)); - } } void @@ -418,7 +402,7 @@ Http2Decompressor::DecodeHeaderBlock(const uint8_t *data, uint32_t datalen, nsresult rv = NS_OK; nsresult softfail_rv = NS_OK; - while (NS_SUCCEEDED(rv) && (mOffset < datalen)) { + while (NS_SUCCEEDED(rv) && (mOffset < mDataLen)) { bool modifiesTable = true; if (mData[mOffset] & 0x80) { rv = DoIndexed(); @@ -700,6 +684,11 @@ nsresult Http2Decompressor::DecodeFinalHuffmanCharacter(const HuffmanIncomingTable *table, uint8_t &c, uint8_t &bitsLeft) { + MOZ_ASSERT(mOffset <= mDataLen); + if (mOffset > mDataLen) { + NS_WARNING("DecodeFinalHuffmanCharacter trying to read beyond end of buffer"); + return NS_ERROR_FAILURE; + } uint8_t mask = (1 << bitsLeft) - 1; uint8_t idx = mData[mOffset - 1] & mask; idx <<= (8 - bitsLeft); @@ -737,6 +726,7 @@ Http2Decompressor::DecodeFinalHuffmanCharacter(const HuffmanIncomingTable *table uint8_t Http2Decompressor::ExtractByte(uint8_t bitsLeft, uint32_t &bytesConsumed) { + MOZ_DIAGNOSTIC_ASSERT(mOffset < mDataLen); uint8_t rv; if (bitsLeft) { @@ -766,8 +756,8 @@ Http2Decompressor::DecodeHuffmanCharacter(const HuffmanIncomingTable *table, uint8_t idx = ExtractByte(bitsLeft, bytesConsumed); if (table->IndexHasANextTable(idx)) { - if (bytesConsumed >= mDataLen) { - if (!bitsLeft || (bytesConsumed > mDataLen)) { + if (mOffset >= mDataLen) { + if (!bitsLeft || (mOffset > mDataLen)) { // TODO - does this get me into trouble in the new world? // No info left in input to try to consume, we're done LOG(("DecodeHuffmanCharacter all out of bits to consume, can't chain")); @@ -908,6 +898,13 @@ Http2Decompressor::DoLiteralInternal(nsACString &name, nsACString &value, return rv; } + // sanity check + if (mOffset >= mDataLen) { + NS_WARNING("Http2 Decompressor ran out of data"); + // This is session-fatal + return NS_ERROR_FAILURE; + } + bool isHuffmanEncoded; if (!index) { @@ -935,6 +932,13 @@ Http2Decompressor::DoLiteralInternal(nsACString &name, nsACString &value, return rv; } + // sanity check + if (mOffset >= mDataLen) { + NS_WARNING("Http2 Decompressor ran out of data"); + // This is session-fatal + return NS_ERROR_FAILURE; + } + // now the value uint32_t valueLen; isHuffmanEncoded = mData[mOffset] & (1 << 7); diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp index 4f350af83..4a178f091 100644 --- a/netwerk/protocol/http/Http2Session.cpp +++ b/netwerk/protocol/http/Http2Session.cpp @@ -168,13 +168,6 @@ Http2Session::~Http2Session() this, mDownstreamState)); Shutdown(); - - Telemetry::Accumulate(Telemetry::SPDY_PARALLEL_STREAMS, mConcurrentHighWater); - Telemetry::Accumulate(Telemetry::SPDY_REQUEST_PER_CONN, (mNextStreamID - 1) / 2); - Telemetry::Accumulate(Telemetry::SPDY_SERVER_INITIATED_STREAMS, - mServerPushedResources); - Telemetry::Accumulate(Telemetry::SPDY_GOAWAY_LOCAL, mClientGoAwayReason); - Telemetry::Accumulate(Telemetry::SPDY_GOAWAY_PEER, mPeerGoAwayReason); } void @@ -1508,13 +1501,11 @@ Http2Session::RecvSettings(Http2Session *self) case SETTINGS_TYPE_MAX_CONCURRENT: self->mMaxConcurrent = value; - Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_MAX_STREAMS, value); self->ProcessPending(); break; case SETTINGS_TYPE_INITIAL_WINDOW: { - Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_IW, value >> 10); int32_t delta = value - self->mServerInitialStreamWindow; self->mServerInitialStreamWindow = value; @@ -2494,8 +2485,6 @@ Http2Session::ReadyToProcessDataFrame(enum internalStateType newState) newState == DISCARDING_DATA_FRAME_PADDING); ChangeDownstreamState(newState); - Telemetry::Accumulate(Telemetry::SPDY_CHUNK_RECVD, - mInputFrameDataSize >> 10); mLastDataReadEpoch = mLastReadEpoch; if (!mInputFrameID) { diff --git a/netwerk/protocol/http/Http2Stream.cpp b/netwerk/protocol/http/Http2Stream.cpp index 7a8f96855..581ebe016 100644 --- a/netwerk/protocol/http/Http2Stream.cpp +++ b/netwerk/protocol/http/Http2Stream.cpp @@ -21,7 +21,6 @@ #include "Http2Push.h" #include "TunnelUtils.h" -#include "mozilla/Telemetry.h" #include "nsAlgorithm.h" #include "nsHttp.h" #include "nsHttpHandler.h" @@ -658,16 +657,7 @@ Http2Stream::GenerateOpen() outputOffset += frameLen; } - Telemetry::Accumulate(Telemetry::SPDY_SYN_SIZE, compressedData.Length()); - - // The size of the input headers is approximate - uint32_t ratio = - compressedData.Length() * 100 / - (11 + requestURI.Length() + - mFlatHttpRequestHeaders.Length()); - mFlatHttpRequestHeaders.Truncate(); - Telemetry::Accumulate(Telemetry::SPDY_SYN_RATIO, ratio); return NS_OK; } @@ -984,7 +974,7 @@ Http2Stream::GenerateDataFrameHeader(uint32_t dataLength, bool lastFrame) } // ConvertResponseHeaders is used to convert the response headers -// into HTTP/1 format and report some telemetry +// into HTTP/1 format nsresult Http2Stream::ConvertResponseHeaders(Http2Decompressor *decompressor, nsACString &aHeadersIn, @@ -1025,13 +1015,6 @@ Http2Stream::ConvertResponseHeaders(Http2Decompressor *decompressor, return NS_ERROR_ILLEGAL_VALUE; } - if (aHeadersIn.Length() && aHeadersOut.Length()) { - Telemetry::Accumulate(Telemetry::SPDY_SYN_REPLY_SIZE, aHeadersIn.Length()); - uint32_t ratio = - aHeadersIn.Length() * 100 / aHeadersOut.Length(); - Telemetry::Accumulate(Telemetry::SPDY_SYN_REPLY_RATIO, ratio); - } - // The decoding went ok. Now we can customize and clean up. aHeadersIn.Truncate(); @@ -1047,7 +1030,7 @@ Http2Stream::ConvertResponseHeaders(Http2Decompressor *decompressor, } // ConvertPushHeaders is used to convert the pushed request headers -// into HTTP/1 format and report some telemetry +// into HTTP/1 format nsresult Http2Stream::ConvertPushHeaders(Http2Decompressor *decompressor, nsACString &aHeadersIn, diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index d161f9a43..86e177e71 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -49,7 +49,6 @@ #include "LoadInfo.h" #include "nsNullPrincipal.h" #include "nsISSLSocketControl.h" -#include "mozilla/Telemetry.h" #include "nsIURL.h" #include "nsIConsoleService.h" #include "mozilla/BinarySearch.h" @@ -152,7 +151,8 @@ HttpBaseChannel::Init(nsIURI *aURI, nsProxyInfo *aProxyInfo, uint32_t aProxyResolveFlags, nsIURI *aProxyURI, - const nsID& aChannelId) + const nsID& aChannelId, + nsContentPolicyType aContentPolicyType) { LOG(("HttpBaseChannel::Init [this=%p]\n", this)); @@ -201,7 +201,7 @@ HttpBaseChannel::Init(nsIURI *aURI, rv = mRequestHead.SetHeader(nsHttp::Host, hostLine); if (NS_FAILED(rv)) return rv; - rv = gHttpHandler->AddStandardRequestHeaders(&mRequestHead, isHTTPS); + rv = gHttpHandler->AddStandardRequestHeaders(&mRequestHead, isHTTPS, aContentPolicyType); if (NS_FAILED(rv)) return rv; nsAutoCString type; @@ -997,17 +997,6 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener, } LOG(("converter removed '%s' content-encoding\n", val)); - if (gHttpHandler->IsTelemetryEnabled()) { - int mode = 0; - if (from.Equals("gzip") || from.Equals("x-gzip")) { - mode = 1; - } else if (from.Equals("deflate") || from.Equals("x-deflate")) { - mode = 2; - } else if (from.Equals("br")) { - mode = 3; - } - Telemetry::Accumulate(Telemetry::HTTP_CONTENT_ENCODING, mode); - } nextListener = converter; } else { @@ -1667,13 +1656,7 @@ HttpBaseChannel::SetRequestHeader(const nsACString& aHeader, return NS_ERROR_INVALID_ARG; } - nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get()); - if (!atom) { - NS_WARNING("failed to resolve atom"); - return NS_ERROR_NOT_AVAILABLE; - } - - return mRequestHead.SetHeader(atom, flatValue, aMerge); + return mRequestHead.SetHeader(aHeader, flatValue, aMerge); } NS_IMETHODIMP @@ -1690,13 +1673,7 @@ HttpBaseChannel::SetEmptyRequestHeader(const nsACString& aHeader) return NS_ERROR_INVALID_ARG; } - nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get()); - if (!atom) { - NS_WARNING("failed to resolve atom"); - return NS_ERROR_NOT_AVAILABLE; - } - - return mRequestHead.SetEmptyHeader(atom); + return mRequestHead.SetEmptyHeader(aHeader); } NS_IMETHODIMP @@ -1752,7 +1729,7 @@ HttpBaseChannel::SetResponseHeader(const nsACString& header, mResponseHeadersModified = true; - return mResponseHead->SetHeader(atom, value, merge); + return mResponseHead->SetHeader(header, value, merge); } NS_IMETHODIMP @@ -3690,14 +3667,17 @@ HttpBaseChannel::GetPerformance() return nullptr; } - // We only add to the document's performance object if it has the same - // principal as the one triggering the load. This is to prevent navigations - // triggered _by_ the iframe from showing up in the parent document's - // performance entries if they have different origins. if (!mLoadInfo->TriggeringPrincipal()->Equals(loadingDocument->NodePrincipal())) { return nullptr; } + if (mLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_SUBDOCUMENT && + !mLoadInfo->GetIsFromProcessingFrameAttributes()) { + // We only report loads caused by processing the attributes of the + // browsing context container. + return nullptr; + } + nsCOMPtr<nsPIDOMWindowInner> innerWindow = loadingDocument->GetInnerWindow(); if (!innerWindow) { return nullptr; diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index 9aa696a70..8def0f23c 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -99,7 +99,8 @@ public: virtual nsresult Init(nsIURI *aURI, uint32_t aCaps, nsProxyInfo *aProxyInfo, uint32_t aProxyResolveFlags, nsIURI *aProxyURI, - const nsID& aChannelId); + const nsID& aChannelId, + nsContentPolicyType aContentPolicyType); // nsIRequest NS_IMETHOD GetName(nsACString& aName) override; diff --git a/netwerk/protocol/http/PHttpChannelParams.h b/netwerk/protocol/http/PHttpChannelParams.h index 4df5c7832..b04f57306 100644 --- a/netwerk/protocol/http/PHttpChannelParams.h +++ b/netwerk/protocol/http/PHttpChannelParams.h @@ -98,7 +98,11 @@ struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry> static void Write(Message* aMsg, const paramType& aParam) { - WriteParam(aMsg, aParam.header); + if (aParam.headerNameOriginal.IsEmpty()) { + WriteParam(aMsg, aParam.header); + } else { + WriteParam(aMsg, aParam.headerNameOriginal); + } WriteParam(aMsg, aParam.value); switch (aParam.variety) { case mozilla::net::nsHttpHeaderArray::eVarietyUnknown: @@ -124,11 +128,18 @@ struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry> static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { uint8_t variety; - if (!ReadParam(aMsg, aIter, &aResult->header) || + nsAutoCString header; + if (!ReadParam(aMsg, aIter, &header) || !ReadParam(aMsg, aIter, &aResult->value) || !ReadParam(aMsg, aIter, &variety)) return false; + mozilla::net::nsHttpAtom atom = mozilla::net::nsHttp::ResolveAtom(header); + aResult->header = atom; + if (!header.Equals(atom.get())) { + aResult->headerNameOriginal = header; + } + switch (variety) { case 0: aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyUnknown; diff --git a/netwerk/protocol/http/TunnelUtils.cpp b/netwerk/protocol/http/TunnelUtils.cpp index 4cc24a07f..6880e0187 100644 --- a/netwerk/protocol/http/TunnelUtils.cpp +++ b/netwerk/protocol/http/TunnelUtils.cpp @@ -23,6 +23,7 @@ #include "nsNetCID.h" #include "nsServiceManagerUtils.h" #include "nsComponentManagerUtils.h" +#include "nsSocketTransport2.h" namespace mozilla { namespace net { @@ -42,6 +43,7 @@ TLSFilterTransaction::TLSFilterTransaction(nsAHttpTransaction *aWrapped, , mSegmentReader(aReader) , mSegmentWriter(aWriter) , mForce(false) + , mReadSegmentReturnValue(NS_OK) , mNudgeCounter(0) { MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); @@ -130,6 +132,19 @@ TLSFilterTransaction::Close(nsresult aReason) } mTransaction->Close(aReason); mTransaction = nullptr; + + RefPtr<NullHttpTransaction> baseTrans(do_QueryReferent(mWeakTrans)); + SpdyConnectTransaction *trans = baseTrans + ? baseTrans->QuerySpdyConnectTransaction() + : nullptr; + + LOG(("TLSFilterTransaction::Close %p aReason=%" PRIx32 " trans=%p\n", + this, static_cast<uint32_t>(aReason), trans)); + + if (trans) { + trans->Close(aReason); + trans = nullptr; + } } nsresult @@ -140,7 +155,7 @@ TLSFilterTransaction::OnReadSegment(const char *aData, LOG(("TLSFilterTransaction %p OnReadSegment %d (buffered %d)\n", this, aCount, mEncryptedTextUsed)); - mReadSegmentBlocked = false; + mReadSegmentReturnValue = NS_OK; MOZ_ASSERT(mSegmentReader); if (!mSecInfo) { return NS_ERROR_FAILURE; @@ -188,10 +203,12 @@ TLSFilterTransaction::OnReadSegment(const char *aData, return NS_OK; } // mTransaction ReadSegments actually obscures this code, so - // keep it in a member var for this::ReadSegments to insepct. Similar + // keep it in a member var for this::ReadSegments to inspect. Similar // to nsHttpConnection::mSocketOutCondition - mReadSegmentBlocked = (PR_GetError() == PR_WOULD_BLOCK_ERROR); - return mReadSegmentBlocked ? NS_BASE_STREAM_WOULD_BLOCK : NS_ERROR_FAILURE; + PRErrorCode code = PR_GetError(); + mReadSegmentReturnValue = ErrorAccordingToNSPR(code); + + return mReadSegmentReturnValue; } aCount -= written; aData += written; @@ -273,10 +290,18 @@ TLSFilterTransaction::OnWriteSegment(char *aData, mFilterReadCode = NS_OK; int32_t bytesRead = PR_Read(mFD, aData, aCount); if (bytesRead == -1) { - if (PR_GetError() == PR_WOULD_BLOCK_ERROR) { + PRErrorCode code = PR_GetError(); + if (code == PR_WOULD_BLOCK_ERROR) { return NS_BASE_STREAM_WOULD_BLOCK; } - return NS_ERROR_FAILURE; + // If reading from the socket succeeded (NS_SUCCEEDED(mFilterReadCode)), + // but the nss layer encountered an error remember the error. + if (NS_SUCCEEDED(mFilterReadCode)) { + mFilterReadCode = ErrorAccordingToNSPR(code); + LOG(("TLSFilterTransaction::OnWriteSegment %p nss error %" PRIx32 ".\n", + this, static_cast<uint32_t>(mFilterReadCode))); + } + return mFilterReadCode; } *outCountRead = bytesRead; @@ -303,7 +328,7 @@ TLSFilterTransaction::FilterInput(char *aBuf, int32_t aAmount) if (NS_SUCCEEDED(mFilterReadCode) && outCountRead) { LOG(("TLSFilterTransaction::FilterInput rv=%x read=%d input from net " "1 layer stripped, 1 still on\n", mFilterReadCode, outCountRead)); - if (mReadSegmentBlocked) { + if (mReadSegmentReturnValue == NS_BASE_STREAM_WOULD_BLOCK) { mNudgeCounter = 0; } } @@ -325,19 +350,18 @@ TLSFilterTransaction::ReadSegments(nsAHttpSegmentReader *aReader, return NS_ERROR_UNEXPECTED; } - mReadSegmentBlocked = false; + mReadSegmentReturnValue = NS_OK; mSegmentReader = aReader; nsresult rv = mTransaction->ReadSegments(this, aCount, outCountRead); LOG(("TLSFilterTransaction %p called trans->ReadSegments rv=%x %d\n", this, rv, *outCountRead)); - if (NS_SUCCEEDED(rv) && mReadSegmentBlocked) { - rv = NS_BASE_STREAM_WOULD_BLOCK; + if (NS_SUCCEEDED(rv) && (mReadSegmentReturnValue == NS_BASE_STREAM_WOULD_BLOCK)) { LOG(("TLSFilterTransaction %p read segment blocked found rv=%x\n", - this, rv)); + this, static_cast<uint32_t>(rv))); Connection()->ForceSend(); } - return rv; + return NS_SUCCEEDED(rv) ? mReadSegmentReturnValue : rv; } nsresult @@ -442,7 +466,10 @@ TLSFilterTransaction::Notify(nsITimer *timer) if (timer != mTimer) { return NS_ERROR_UNEXPECTED; } - StartTimerCallback(); + nsresult rv = StartTimerCallback(); + if (NS_FAILED(rv)) { + Close(rv); + } return NS_OK; } @@ -456,7 +483,7 @@ TLSFilterTransaction::StartTimerCallback() // This class can be called re-entrantly, so cleanup m* before ->on() RefPtr<NudgeTunnelCallback> cb(mNudgeCallback); mNudgeCallback = nullptr; - cb->OnTunnelNudged(this); + return cb->OnTunnelNudged(this); } return NS_OK; } @@ -675,10 +702,12 @@ TLSFilterTransaction::TakeSubTransactions( } nsresult -TLSFilterTransaction::SetProxiedTransaction(nsAHttpTransaction *aTrans) +TLSFilterTransaction::SetProxiedTransaction(nsAHttpTransaction *aTrans, + nsAHttpTransaction *aSpdyConnectTransaction) { - LOG(("TLSFilterTransaction::SetProxiedTransaction [this=%p] aTrans=%p\n", - this, aTrans)); + LOG(("TLSFilterTransaction::SetProxiedTransaction [this=%p] aTrans=%p, " + "aSpdyConnectTransaction=%p\n", + this, aTrans, aSpdyConnectTransaction)); mTransaction = aTrans; nsCOMPtr<nsIInterfaceRequestor> callbacks; @@ -688,6 +717,8 @@ TLSFilterTransaction::SetProxiedTransaction(nsAHttpTransaction *aTrans) secCtrl->SetNotificationCallbacks(callbacks); } + mWeakTrans = do_GetWeakReference(aSpdyConnectTransaction); + return NS_OK; } @@ -1075,7 +1106,7 @@ SpdyConnectTransaction::MapStreamToHttpConnection(nsISocketTransport *aTransport if (mForcePlainText) { mTunneledConn->ForcePlainText(); } else { - mTunneledConn->SetupSecondaryTLS(); + mTunneledConn->SetupSecondaryTLS(this); mTunneledConn->SetInSpdyTunnel(true); } diff --git a/netwerk/protocol/http/TunnelUtils.h b/netwerk/protocol/http/TunnelUtils.h index 20cfaf7ee..4a003082e 100644 --- a/netwerk/protocol/http/TunnelUtils.h +++ b/netwerk/protocol/http/TunnelUtils.h @@ -93,10 +93,11 @@ class TLSFilterTransaction; class NudgeTunnelCallback : public nsISupports { public: - virtual void OnTunnelNudged(TLSFilterTransaction *) = 0; + virtual nsresult OnTunnelNudged(TLSFilterTransaction *) = 0; }; -#define NS_DECL_NUDGETUNNELCALLBACK void OnTunnelNudged(TLSFilterTransaction *) override; +#define NS_DECL_NUDGETUNNELCALLBACK \ + nsresult OnTunnelNudged(TLSFilterTransaction *) override; class TLSFilterTransaction final : public nsAHttpTransaction @@ -121,7 +122,8 @@ public: nsresult CommitToSegmentSize(uint32_t size, bool forceCommitment) override; nsresult GetTransactionSecurityInfo(nsISupports **) override; nsresult NudgeTunnel(NudgeTunnelCallback *callback); - nsresult SetProxiedTransaction(nsAHttpTransaction *aTrans); + MOZ_MUST_USE nsresult SetProxiedTransaction(nsAHttpTransaction *aTrans, + nsAHttpTransaction *aSpdyConnectTransaction = nullptr); void newIODriver(nsIAsyncInputStream *aSocketIn, nsIAsyncOutputStream *aSocketOut, nsIAsyncInputStream **outSocketIn, @@ -153,6 +155,7 @@ private: private: RefPtr<nsAHttpTransaction> mTransaction; + nsWeakPtr mWeakTrans; // SpdyConnectTransaction * nsCOMPtr<nsISupports> mSecInfo; nsCOMPtr<nsITimer> mTimer; RefPtr<NudgeTunnelCallback> mNudgeCallback; @@ -168,7 +171,7 @@ private: nsresult mFilterReadCode; bool mForce; - bool mReadSegmentBlocked; + nsresult mReadSegmentReturnValue; uint32_t mNudgeCounter; }; diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index d7247eeab..481df5ff0 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -83,7 +83,6 @@ #include "nsCRT.h" #include "CacheObserver.h" #include "mozilla/dom/Performance.h" -#include "mozilla/Telemetry.h" #include "AlternateServices.h" #include "InterceptedChannel.h" #include "nsIHttpPushListener.h" @@ -123,30 +122,6 @@ static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID); static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID); -enum CacheDisposition { - kCacheHit = 1, - kCacheHitViaReval = 2, - kCacheMissedViaReval = 3, - kCacheMissed = 4 -}; - -void -AccumulateCacheHitTelemetry(CacheDisposition hitOrMiss) -{ - if (!CacheObserver::UseNewCache()) { - Telemetry::Accumulate(Telemetry::HTTP_CACHE_DISPOSITION_2, hitOrMiss); - } - else { - Telemetry::Accumulate(Telemetry::HTTP_CACHE_DISPOSITION_2_V2, hitOrMiss); - - int32_t experiment = CacheObserver::HalfLifeExperiment(); - if (experiment > 0 && hitOrMiss == kCacheMissed) { - Telemetry::Accumulate(Telemetry::HTTP_CACHE_MISS_HALFLIFE_EXPERIMENT_2, - experiment - 1); - } - } -} - // Computes and returns a SHA1 hash of the input buffer. The input buffer // must be a null-terminated string. nsresult @@ -324,11 +299,15 @@ nsHttpChannel::nsHttpChannel() , mPushedStream(nullptr) , mLocalBlocklist(false) , mWarningReporter(nullptr) + , mSendUpgradeRequest(false) , mDidReval(false) { LOG(("Creating nsHttpChannel [this=%p]\n", this)); mChannelCreationTime = PR_Now(); mChannelCreationTimestamp = TimeStamp::Now(); + + mSendUpgradeRequest = + Preferences::GetBool("network.http.upgrade-insecure-requests", false); } nsHttpChannel::~nsHttpChannel() @@ -345,10 +324,16 @@ nsHttpChannel::Init(nsIURI *uri, nsProxyInfo *proxyInfo, uint32_t proxyResolveFlags, nsIURI *proxyURI, - const nsID& channelId) -{ - nsresult rv = HttpBaseChannel::Init(uri, caps, proxyInfo, - proxyResolveFlags, proxyURI, channelId); + const nsID& channelId, + nsContentPolicyType aContentPolicyType) +{ + nsresult rv = HttpBaseChannel::Init(uri, + caps, + proxyInfo, + proxyResolveFlags, + proxyURI, + channelId, + aContentPolicyType); if (NS_FAILED(rv)) return rv; @@ -388,8 +373,9 @@ nsHttpChannel::Connect() mLoadInfo->GetExternalContentPolicyType() : nsIContentPolicy::TYPE_OTHER; - if (type == nsIContentPolicy::TYPE_DOCUMENT || - type == nsIContentPolicy::TYPE_SUBDOCUMENT) { + if (mSendUpgradeRequest && + (type == nsIContentPolicy::TYPE_DOCUMENT || + type == nsIContentPolicy::TYPE_SUBDOCUMENT)) { rv = SetRequestHeader(NS_LITERAL_CSTRING("Upgrade-Insecure-Requests"), NS_LITERAL_CSTRING("1"), false); NS_ENSURE_SUCCESS(rv, rv); @@ -500,11 +486,6 @@ nsHttpChannel::ContinueConnect() event->Revoke(); } - // Don't accumulate the cache hit telemetry for intercepted channels. - if (mInterceptCache != INTERCEPTED) { - AccumulateCacheHitTelemetry(kCacheHit); - } - return rv; } else if (mLoadFlags & LOAD_ONLY_FROM_CACHE) { @@ -1091,10 +1072,8 @@ ProcessXCTO(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo* aLoadI if (aLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_IMAGE) { if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("image/"))) { - Accumulate(Telemetry::XCTO_NOSNIFF_BLOCK_IMAGE, 0); return NS_OK; } - Accumulate(Telemetry::XCTO_NOSNIFF_BLOCK_IMAGE, 1); // Instead of consulting Preferences::GetBool() all the time we // can cache the result to speed things up. static bool sXCTONosniffBlockImages = false; @@ -1141,26 +1120,21 @@ EnsureMIMEOfScript(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo* if (nsContentUtils::IsJavascriptMIMEType(typeString)) { // script load has type script - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 1); return NS_OK; } bool block = false; if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("image/"))) { // script load has type image - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 2); block = true; } else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("audio/"))) { // script load has type audio - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 3); block = true; } else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("video/"))) { // script load has type video - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 4); block = true; } else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/csv"))) { // script load has type text/csv - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 6); block = true; } @@ -1186,42 +1160,35 @@ EnsureMIMEOfScript(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo* if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/plain"))) { // script load has type text/plain - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 5); return NS_OK; } if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/xml"))) { // script load has type text/xml - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 7); return NS_OK; } if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/octet-stream"))) { // script load has type application/octet-stream - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 8); return NS_OK; } if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/xml"))) { // script load has type application/xml - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 9); return NS_OK; } if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/html"))) { // script load has type text/html - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 10); return NS_OK; } if (contentType.IsEmpty()) { // script load has no type - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 11); return NS_OK; } // script load has unknown type - Telemetry::Accumulate(Telemetry::SCRIPT_BLOCK_INCORRECT_MIME, 0); return NS_OK; } @@ -1867,65 +1834,6 @@ nsHttpChannel::ProcessResponse() LOG(("nsHttpChannel::ProcessResponse [this=%p httpStatus=%u]\n", this, httpStatus)); - // do some telemetry - if (gHttpHandler->IsTelemetryEnabled()) { - // Gather data on whether the transaction and page (if this is - // the initial page load) is being loaded with SSL. - Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_IS_SSL, - mConnectionInfo->EndToEndSSL()); - if (mLoadFlags & LOAD_INITIAL_DOCUMENT_URI) { - Telemetry::Accumulate(Telemetry::HTTP_PAGELOAD_IS_SSL, - mConnectionInfo->EndToEndSSL()); - } - - // how often do we see something like Alternate-Protocol: "443:quic,p=1" - nsAutoCString alt_protocol; - mResponseHead->GetHeader(nsHttp::Alternate_Protocol, alt_protocol); - bool saw_quic = (!alt_protocol.IsEmpty() && - PL_strstr(alt_protocol.get(), "quic")) ? 1 : 0; - Telemetry::Accumulate(Telemetry::HTTP_SAW_QUIC_ALT_PROTOCOL, saw_quic); - - // Gather data on how many URLS get redirected - switch (httpStatus) { - case 200: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 0); - break; - case 301: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 1); - break; - case 302: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 2); - break; - case 304: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 3); - break; - case 307: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 4); - break; - case 308: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 5); - break; - case 400: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 6); - break; - case 401: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 7); - break; - case 403: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 8); - break; - case 404: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 9); - break; - case 500: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 10); - break; - default: - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_STATUS_CODE, 11); - break; - } - } - // Let the predictor know whether this was a cacheable response or not so // that it knows whether or not to possibly prefetch this resource in the // future. @@ -2193,33 +2101,6 @@ nsHttpChannel::ContinueProcessResponse2(nsresult rv) break; } - if (gHttpHandler->IsTelemetryEnabled()) { - CacheDisposition cacheDisposition; - if (!mDidReval) { - cacheDisposition = kCacheMissed; - } else if (successfulReval) { - cacheDisposition = kCacheHitViaReval; - } else { - cacheDisposition = kCacheMissedViaReval; - } - AccumulateCacheHitTelemetry(cacheDisposition); - - Telemetry::Accumulate(Telemetry::HTTP_RESPONSE_VERSION, - mResponseHead->Version()); - - if (mResponseHead->Version() == NS_HTTP_VERSION_0_9) { - // DefaultPortTopLevel = 0, DefaultPortSubResource = 1, - // NonDefaultPortTopLevel = 2, NonDefaultPortSubResource = 3 - uint32_t v09Info = 0; - if (!(mLoadFlags & LOAD_INITIAL_DOCUMENT_URI)) { - v09Info += 1; - } - if (mConnectionInfo->OriginPort() != mConnectionInfo->DefaultPort()) { - v09Info += 2; - } - Telemetry::Accumulate(Telemetry::HTTP_09_INFO, v09Info); - } - } return rv; } @@ -3212,7 +3093,6 @@ nsHttpChannel::ProcessNotModified() PipelineFeedbackInfo(mConnectionInfo, nsHttpConnectionMgr::RedCorruptedContent, nullptr, 0); - Telemetry::Accumulate(Telemetry::CACHE_LM_INCONSISTENT, true); } // merge any new headers with the cached response headers @@ -3866,8 +3746,6 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, nsIApplicationCache* appC (!mCachedResponseHead->ExpiresInPast() || !mCachedResponseHead->MustValidateIfExpired())) { LOG(("NOT validating based on isForcedValid being true.\n")); - Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PREFETCHES_USED> used; - ++used; doValidation = false; } // If the LOAD_FROM_CACHE flag is set, any cached data can simply be used @@ -4222,11 +4100,6 @@ nsHttpChannel::OnNormalCacheEntryAvailable(nsICacheEntry *aEntry, if (NS_SUCCEEDED(aEntryStatus)) { mCacheEntry = aEntry; mCacheEntryIsWriteOnly = aNew; - - if (mLoadFlags & LOAD_INITIAL_DOCUMENT_URI) { - Telemetry::Accumulate(Telemetry::HTTP_OFFLINE_CACHE_DOCUMENT_LOAD, - false); - } } return NS_OK; @@ -5897,17 +5770,13 @@ nsHttpChannel::BeginConnect() LOG(("nsHttpChannel %p Using connection info from altsvc mapping", this)); mapping->GetConnectionInfo(getter_AddRefs(mConnectionInfo), proxyInfo, originAttributes); - Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, true); - Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC_OE, !isHttps); } else if (mConnectionInfo) { LOG(("nsHttpChannel %p Using channel supplied connection info", this)); - Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, false); } else { LOG(("nsHttpChannel %p Using default connection info", this)); mConnectionInfo = new nsHttpConnectionInfo(host, port, EmptyCString(), mUsername, proxyInfo, originAttributes, isHttps); - Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, false); } // Set network interface id only when it's not empty to avoid @@ -6637,8 +6506,6 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st if (mTimingEnabled && request == mCachePump) { mCacheReadEnd = TimeStamp::Now(); - - ReportNetVSCacheTelemetry(); } // allow content to be cached if it was loaded successfully (bug #482935) @@ -6829,7 +6696,6 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st chanDisposition = static_cast<ChannelDisposition>(chanDisposition + kHttpsCanceled); } LOG((" nsHttpChannel::OnStopRequest ChannelDisposition %d\n", chanDisposition)); - Telemetry::Accumulate(Telemetry::HTTP_CHANNEL_DISPOSITION, chanDisposition); // if needed, check cache entry has all data we expect if (mCacheEntry && mCachePump && @@ -8196,134 +8062,5 @@ nsHttpChannel::SetDoNotTrack() } } - -void -nsHttpChannel::ReportNetVSCacheTelemetry() -{ - nsresult rv; - if (!mCacheEntry) { - return; - } - - // We only report telemetry if the entry is persistent (on disk) - bool persistent; - rv = mCacheEntry->GetPersistent(&persistent); - if (NS_FAILED(rv) || !persistent) { - return; - } - - nsXPIDLCString tmpStr; - rv = mCacheEntry->GetMetaDataElement("net-response-time-onstart", - getter_Copies(tmpStr)); - if (NS_FAILED(rv)) { - return; - } - uint64_t onStartNetTime = tmpStr.ToInteger64(&rv); - if (NS_FAILED(rv)) { - return; - } - - tmpStr.Truncate(); - rv = mCacheEntry->GetMetaDataElement("net-response-time-onstop", - getter_Copies(tmpStr)); - if (NS_FAILED(rv)) { - return; - } - uint64_t onStopNetTime = tmpStr.ToInteger64(&rv); - if (NS_FAILED(rv)) { - return; - } - - uint64_t onStartCacheTime = (mOnStartRequestTimestamp - mAsyncOpenTime).ToMilliseconds(); - int64_t onStartDiff = onStartNetTime - onStartCacheTime; - onStartDiff += 500; // We offset the difference by 500 ms to report positive values in telemetry - - uint64_t onStopCacheTime = (mCacheReadEnd - mAsyncOpenTime).ToMilliseconds(); - int64_t onStopDiff = onStopNetTime - onStopCacheTime; - onStopDiff += 500; // We offset the difference by 500 ms - - if (mDidReval) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_REVALIDATED, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_REVALIDATED, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_NOTREVALIDATED, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_NOTREVALIDATED, onStopDiff); - } - - if (mDidReval) { - // We don't report revalidated probes as the data would be skewed. - return; - } - - uint32_t diskStorageSizeK = 0; - rv = mCacheEntry->GetDiskStorageSizeInKB(&diskStorageSizeK); - if (NS_FAILED(rv)) { - return; - } - - nsAutoCString contentType; - if (mResponseHead && mResponseHead->HasContentType()) { - mResponseHead->ContentType(contentType); - } - bool isImage = StringBeginsWith(contentType, NS_LITERAL_CSTRING("image/")); - if (isImage) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_ISIMG, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_ISIMG, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_NOTIMG, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_NOTIMG, onStopDiff); - } - - if (mCacheOpenWithPriority) { - if (mCacheQueueSizeWhenOpen < 5) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QSMALL_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QSMALL_HIGHPRI, onStopDiff); - } else if (mCacheQueueSizeWhenOpen < 10) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QMED_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QMED_HIGHPRI, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QBIG_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QBIG_HIGHPRI, onStopDiff); - } - } else { // The limits are higher for normal priority cache queues - if (mCacheQueueSizeWhenOpen < 10) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QSMALL_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QSMALL_NORMALPRI, onStopDiff); - } else if (mCacheQueueSizeWhenOpen < 50) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QMED_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QMED_NORMALPRI, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_QBIG_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_QBIG_NORMALPRI, onStopDiff); - } - } - - if (diskStorageSizeK < 32) { - if (mCacheOpenWithPriority) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_SMALL_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_SMALL_HIGHPRI, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_SMALL_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_SMALL_NORMALPRI, onStopDiff); - } - } else if (diskStorageSizeK < 256) { - if (mCacheOpenWithPriority) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_MED_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_MED_HIGHPRI, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_MED_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_MED_NORMALPRI, onStopDiff); - } - } else { - if (mCacheOpenWithPriority) { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_LARGE_HIGHPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_LARGE_HIGHPRI, onStopDiff); - } else { - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTART_LARGE_NORMALPRI, onStartDiff); - Telemetry::Accumulate(Telemetry::HTTP_NET_VS_CACHE_ONSTOP_LARGE_NORMALPRI, onStopDiff); - } - } -} - } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index 2e24d6e81..0038e1f71 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -123,7 +123,8 @@ public: virtual nsresult Init(nsIURI *aURI, uint32_t aCaps, nsProxyInfo *aProxyInfo, uint32_t aProxyResolveFlags, nsIURI *aProxyURI, - const nsID& aChannelId) override; + const nsID& aChannelId, + nsContentPolicyType aContentPolicyType) override; nsresult OnPush(const nsACString &uri, Http2PushedStream *pushedStream); @@ -431,9 +432,6 @@ private: rv == NS_ERROR_MALFORMED_URI; } - // Report net vs cache time telemetry - void ReportNetVSCacheTelemetry(); - // Create a aggregate set of the current notification callbacks // and ensure the transaction is updated to use it. void UpdateAggregateCallbacks(); @@ -597,6 +595,10 @@ private: HttpChannelSecurityWarningReporter* mWarningReporter; RefPtr<ADivertableParentChannel> mParentChannel; + + // Whether we send opportunistic encryption requests. + bool mSendUpgradeRequest; + protected: virtual void DoNotifyListenerCleanup() override; diff --git a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp index d04f47ddc..0e7eb55c3 100644 --- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp +++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp @@ -867,24 +867,6 @@ nsHttpChannelAuthProvider::GetCredentialsForChallenge(const char *challenge, else if (authFlags & nsIHttpAuthenticator::IDENTITY_ENCRYPTED) level = nsIAuthPrompt2::LEVEL_PW_ENCRYPTED; - // Collect statistics on how frequently the various types of HTTP - // authentication are used over SSL and non-SSL connections. - if (gHttpHandler->IsTelemetryEnabled()) { - if (NS_LITERAL_CSTRING("basic").LowerCaseEqualsASCII(authType)) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_TYPE_STATS, - UsingSSL() ? HTTP_AUTH_BASIC_SECURE : HTTP_AUTH_BASIC_INSECURE); - } else if (NS_LITERAL_CSTRING("digest").LowerCaseEqualsASCII(authType)) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_TYPE_STATS, - UsingSSL() ? HTTP_AUTH_DIGEST_SECURE : HTTP_AUTH_DIGEST_INSECURE); - } else if (NS_LITERAL_CSTRING("ntlm").LowerCaseEqualsASCII(authType)) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_TYPE_STATS, - UsingSSL() ? HTTP_AUTH_NTLM_SECURE : HTTP_AUTH_NTLM_INSECURE); - } else if (NS_LITERAL_CSTRING("negotiate").LowerCaseEqualsASCII(authType)) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_TYPE_STATS, - UsingSSL() ? HTTP_AUTH_NEGOTIATE_SECURE : HTTP_AUTH_NEGOTIATE_INSECURE); - } - } - // Depending on the pref setting, the authentication dialog may be // blocked for all sub-resources, blocked for cross-origin // sub-resources, or always allowed for sub-resources. @@ -991,22 +973,6 @@ nsHttpChannelAuthProvider::BlockPrompt() } } - if (gHttpHandler->IsTelemetryEnabled()) { - if (topDoc) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS, - HTTP_AUTH_DIALOG_TOP_LEVEL_DOC); - } else if (xhr) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS, - HTTP_AUTH_DIALOG_XHR); - } else if (!mCrossOrigin) { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS, - HTTP_AUTH_DIALOG_SAME_ORIGIN_SUBRESOURCE); - } else { - Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS, - HTTP_AUTH_DIALOG_CROSS_ORIGIN_SUBRESOURCE); - } - } - switch (sAuthAllowPref) { case SUBRESOURCE_AUTH_DIALOG_DISALLOW_ALL: // Do not open the http-authentication credentials dialog for diff --git a/netwerk/protocol/http/nsHttpConnection.cpp b/netwerk/protocol/http/nsHttpConnection.cpp index c4564cd8b..505d849c0 100644 --- a/netwerk/protocol/http/nsHttpConnection.cpp +++ b/netwerk/protocol/http/nsHttpConnection.cpp @@ -19,7 +19,6 @@ #include "ASpdySession.h" #include "mozilla/ChaosMode.h" -#include "mozilla/Telemetry.h" #include "nsHttpConnection.h" #include "nsHttpHandler.h" #include "nsHttpPipeline.h" @@ -105,18 +104,12 @@ nsHttpConnection::~nsHttpConnection() if (!mEverUsedSpdy) { LOG(("nsHttpConnection %p performed %d HTTP/1.x transactions\n", this, mHttp1xTransactionCount)); - Telemetry::Accumulate(Telemetry::HTTP_REQUEST_PER_CONN, - mHttp1xTransactionCount); } if (mTotalBytesRead) { uint32_t totalKBRead = static_cast<uint32_t>(mTotalBytesRead >> 10); LOG(("nsHttpConnection %p read %dkb on connection spdy=%d\n", this, totalKBRead, mEverUsedSpdy)); - Telemetry::Accumulate(mEverUsedSpdy ? - Telemetry::SPDY_KBREAD_PER_CONN : - Telemetry::HTTP_KBREAD_PER_CONN, - totalKBRead); } if (mForceSendTimer) { mForceSendTimer->Cancel(); @@ -482,21 +475,6 @@ nsHttpConnection::EnsureNPNComplete(nsresult &aOut0RTTWriteHandshakeValue, int16_t tlsVersion; ssl->GetSSLVersionUsed(&tlsVersion); - // Send the 0RTT telemetry only for tls1.3 - if (tlsVersion > nsISSLSocketControl::TLS_VERSION_1_2) { - Telemetry::Accumulate(Telemetry::TLS_EARLY_DATA_NEGOTIATED, - (!mEarlyDataNegotiated) ? TLS_EARLY_DATA_NOT_AVAILABLE - : ((mWaitingFor0RTTResponse) ? TLS_EARLY_DATA_AVAILABLE_AND_USED - : TLS_EARLY_DATA_AVAILABLE_BUT_NOT_USED)); - if (mWaitingFor0RTTResponse) { - Telemetry::Accumulate(Telemetry::TLS_EARLY_DATA_ACCEPTED, - earlyDataAccepted); - } - if (earlyDataAccepted) { - Telemetry::Accumulate(Telemetry::TLS_EARLY_DATA_BYTES_WRITTEN, - mContentBytesWritten0RTT); - } - } mWaitingFor0RTTResponse = false; if (!earlyDataAccepted) { @@ -518,8 +496,6 @@ nsHttpConnection::EnsureNPNComplete(nsresult &aOut0RTTWriteHandshakeValue, StartSpdy(mSpdySession->SpdyVersion()); } } - - Telemetry::Accumulate(Telemetry::SPDY_NPN_CONNECT, UsingSpdy()); } npnComplete: @@ -559,16 +535,16 @@ npnComplete: return true; } -void +nsresult nsHttpConnection::OnTunnelNudged(TLSFilterTransaction *trans) { MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); LOG(("nsHttpConnection::OnTunnelNudged %p\n", this)); if (trans != mTLSFilter) { - return; + return NS_OK; } LOG(("nsHttpConnection::OnTunnelNudged %p Calling OnSocketWritable\n", this)); - OnSocketWritable(); + return OnSocketWritable(); } // called on the socket thread @@ -663,7 +639,9 @@ nsHttpConnection::Activate(nsAHttpTransaction *trans, uint32_t caps, int32_t pri } if (mTLSFilter) { - mTLSFilter->SetProxiedTransaction(trans); + RefPtr<NullHttpTransaction> baseTrans(do_QueryReferent(mWeakTrans)); + rv = mTLSFilter->SetProxiedTransaction(trans, baseTrans); + NS_ENSURE_SUCCESS(rv, rv); mTransaction = mTLSFilter; } @@ -2003,7 +1981,7 @@ nsHttpConnection::OnSocketReadable() // negotiation are known (which is determined from the write path). // If the server speaks SPDY it is likely the readable data here is // a spdy settings frame and without NPN it would be misinterpreted - // as HTTP/* + // as HTTP LOG(("nsHttpConnection::OnSocketReadable %p return due to inactive " "tunnel setup but incomplete NPN state\n", this)); @@ -2043,12 +2021,14 @@ nsHttpConnection::OnSocketReadable() } void -nsHttpConnection::SetupSecondaryTLS() +nsHttpConnection::SetupSecondaryTLS(nsAHttpTransaction *aSpdyConnectTransaction) { MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); MOZ_ASSERT(!mTLSFilter); - LOG(("nsHttpConnection %p SetupSecondaryTLS %s %d\n", - this, mConnInfo->Origin(), mConnInfo->OriginPort())); + LOG(("nsHttpConnection %p SetupSecondaryTLS %s %d " + "aSpdyConnectTransaction=%p\n", + this, mConnInfo->Origin(), mConnInfo->OriginPort(), + aSpdyConnectTransaction)); nsHttpConnectionInfo *ci = nullptr; if (mTransaction) { @@ -2065,6 +2045,7 @@ nsHttpConnection::SetupSecondaryTLS() if (mTransaction) { mTransaction = mTLSFilter; } + mWeakTrans = do_GetWeakReference(aSpdyConnectTransaction); } void diff --git a/netwerk/protocol/http/nsHttpConnection.h b/netwerk/protocol/http/nsHttpConnection.h index 08eea1de2..ce7523eb5 100644 --- a/netwerk/protocol/http/nsHttpConnection.h +++ b/netwerk/protocol/http/nsHttpConnection.h @@ -202,7 +202,7 @@ public: static nsresult MakeConnectString(nsAHttpTransaction *trans, nsHttpRequestHead *request, nsACString &result); - void SetupSecondaryTLS(); + void SetupSecondaryTLS(nsAHttpTransaction *aSpdyConnectTransaction = nullptr); void SetInSpdyTunnel(bool arg); // Check active connections for traffic (or not). SPDY connections send a @@ -281,6 +281,7 @@ private: // transaction is open, otherwise it is null. RefPtr<nsAHttpTransaction> mTransaction; RefPtr<TLSFilterTransaction> mTLSFilter; + nsWeakPtr mWeakTrans; // SpdyConnectTransaction * RefPtr<nsHttpHandler> mHttpHandler; // keep gHttpHandler alive diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.cpp b/netwerk/protocol/http/nsHttpConnectionInfo.cpp index e965fd1cc..93a40843c 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp +++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp @@ -15,32 +15,26 @@ #include "nsHttpConnectionInfo.h" #include "mozilla/net/DNS.h" -#include "prnetdb.h" -#include "nsICryptoHash.h" #include "nsComponentManagerUtils.h" +#include "nsICryptoHash.h" #include "nsIProtocolProxyService.h" +#include "nsNetCID.h" +#include "prnetdb.h" static nsresult SHA256(const char* aPlainText, nsAutoCString& aResult) { - static nsICryptoHash* hasher = nullptr; nsresult rv; - if (!hasher) { - rv = CallCreateInstance("@mozilla.org/security/hash;1", &hasher); - if (NS_FAILED(rv)) { - LOG(("nsHttpDigestAuth: no crypto hash!\n")); - return rv; - } + nsCOMPtr<nsICryptoHash> hasher = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + LOG(("nsHttpDigestAuth: no crypto hash!\n")); + return rv; } - rv = hasher->Init(nsICryptoHash::SHA256); NS_ENSURE_SUCCESS(rv, rv); - rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText)); NS_ENSURE_SUCCESS(rv, rv); - - rv = hasher->Finish(false, aResult); - return rv; + return hasher->Finish(false, aResult); } namespace mozilla { diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index 9271b49af..907f33436 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -23,7 +23,6 @@ #include "mozilla/net/DNS.h" #include "nsISocketTransport.h" #include "nsISSLSocketControl.h" -#include "mozilla/Telemetry.h" #include "mozilla/net/DashboardTypes.h" #include "NullHttpTransaction.h" #include "nsIDNSRecord.h" @@ -36,8 +35,6 @@ #include "mozilla/Unused.h" #include "nsIURI.h" -#include "mozilla/Telemetry.h" - namespace mozilla { namespace net { @@ -847,7 +844,6 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry) "with %s connections. rv=%x isJoined=%d", preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(), rv, isJoined)); - Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, false); return nullptr; } @@ -857,7 +853,6 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry) "so %s will be coalesced with %s", preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(), preferred->mConnInfo->Origin())); - Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, true); return preferred; } @@ -1189,14 +1184,6 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent, transport->SetConnectionFlags(flags); } - Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_USED_SPECULATIVE_CONN> usedSpeculativeConn; - ++usedSpeculativeConn; - - if (ent->mHalfOpens[i]->IsFromPredictor()) { - Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_USED> totalPreconnectsUsed; - ++totalPreconnectsUsed; - } - // return OK because we have essentially opened a new connection // by converting a speculative half-open to general use return NS_OK; @@ -1390,14 +1377,6 @@ nsHttpConnectionMgr::AddToShortestPipeline(nsConnectionEntry *ent, ent->SetYellowConnection(bestConn); if (!trans->GetPendingTime().IsNull()) { - if (trans->UsesPipelining()) - AccumulateTimeDelta( - Telemetry::TRANSACTION_WAIT_TIME_HTTP_PIPELINES, - trans->GetPendingTime(), TimeStamp::Now()); - else - AccumulateTimeDelta( - Telemetry::TRANSACTION_WAIT_TIME_HTTP, - trans->GetPendingTime(), TimeStamp::Now()); trans->SetPendingTime(false); } return true; @@ -1680,8 +1659,6 @@ nsHttpConnectionMgr::DispatchTransaction(nsConnectionEntry *ent, rv = conn->Activate(trans, caps, priority); MOZ_ASSERT(NS_SUCCEEDED(rv), "SPDY Cannot Fail Dispatch"); if (NS_SUCCEEDED(rv) && !trans->GetPendingTime().IsNull()) { - AccumulateTimeDelta(Telemetry::TRANSACTION_WAIT_TIME_SPDY, - trans->GetPendingTime(), TimeStamp::Now()); trans->SetPendingTime(false); } return rv; @@ -1698,12 +1675,6 @@ nsHttpConnectionMgr::DispatchTransaction(nsConnectionEntry *ent, rv = DispatchAbstractTransaction(ent, trans, caps, conn, priority); if (NS_SUCCEEDED(rv) && !trans->GetPendingTime().IsNull()) { - if (trans->UsesPipelining()) - AccumulateTimeDelta(Telemetry::TRANSACTION_WAIT_TIME_HTTP_PIPELINES, - trans->GetPendingTime(), TimeStamp::Now()); - else - AccumulateTimeDelta(Telemetry::TRANSACTION_WAIT_TIME_HTTP, - trans->GetPendingTime(), TimeStamp::Now()); trans->SetPendingTime(false); } return rv; @@ -1832,21 +1803,6 @@ nsHttpConnectionMgr::BuildPipeline(nsConnectionEntry *ent, return NS_OK; } -void -nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent) -{ - enum { PROXY_NONE = 1, PROXY_HTTP = 2, PROXY_SOCKS = 3, PROXY_HTTPS = 4 }; - - if (!ent->mConnInfo->UsingProxy()) - Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_NONE); - else if (ent->mConnInfo->UsingHttpsProxy()) - Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_HTTPS); - else if (ent->mConnInfo->UsingHttpProxy()) - Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_HTTP); - else - Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_SOCKS); -} - nsresult nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans) { @@ -1890,8 +1846,6 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans) ent = preferredEntry; } - ReportProxyTelemetry(ent); - // Check if the transaction already has a sticky reference to a connection. // If so, then we can just use it directly by transferring its reference // to the new connection variable instead of searching for a new one @@ -1988,13 +1942,9 @@ nsHttpConnectionMgr::CreateTransport(nsConnectionEntry *ent, if (speculative) { sock->SetSpeculative(true); sock->SetAllow1918(allow1918); - Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn; - ++totalSpeculativeConn; if (isFromPredictor) { sock->SetIsFromPredictor(true); - Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated; - ++totalPreconnectsCreated; } } @@ -3107,8 +3057,6 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport, rv = socketTransport->SetSecurityCallbacks(this); NS_ENSURE_SUCCESS(rv, rv); - Telemetry::Accumulate(Telemetry::HTTP_CONNECTION_ENTRY_CACHE_HIT_1, - mEnt->mUsedForConnection); mEnt->mUsedForConnection = true; nsCOMPtr<nsIOutputStream> sout; @@ -3908,16 +3856,6 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen) // will result in it not being present in the halfopen table. That's expected. if (mHalfOpens.RemoveElement(halfOpen)) { - if (halfOpen->IsSpeculative()) { - Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN> unusedSpeculativeConn; - ++unusedSpeculativeConn; - - if (halfOpen->IsFromPredictor()) { - Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_UNUSED> totalPreconnectsUnused; - ++totalPreconnectsUnused; - } - } - MOZ_ASSERT(gHttpHandler->ConnMgr()->mNumHalfOpenConns); if (gHttpHandler->ConnMgr()->mNumHalfOpenConns) { // just in case gHttpHandler->ConnMgr()->mNumHalfOpenConns--; diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index 7ca2a2b28..a2c88c402 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -529,7 +529,6 @@ private: nsresult ProcessNewTransaction(nsHttpTransaction *); nsresult EnsureSocketThreadTarget(); void ClosePersistentConnections(nsConnectionEntry *ent); - void ReportProxyTelemetry(nsConnectionEntry *ent); nsresult CreateTransport(nsConnectionEntry *, nsAHttpTransaction *, uint32_t, bool, bool, bool); void AddActiveConn(nsHttpConnection *, nsConnectionEntry *); diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index f9bcc391d..0f4c94202 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -58,7 +58,6 @@ #include "mozilla/net/NeckoChild.h" #include "mozilla/net/NeckoParent.h" #include "mozilla/ipc/URIUtils.h" -#include "mozilla/Telemetry.h" #include "mozilla/Unused.h" #include "mozilla/BasePrincipal.h" @@ -91,7 +90,6 @@ #define BROWSER_PREF_PREFIX "browser.cache." #define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled" #define H2MANDATORY_SUITE "security.ssl3.ecdhe_rsa_aes_128_gcm_sha256" -#define TELEMETRY_ENABLED "toolkit.telemetry.enabled" #define ALLOW_EXPERIMENTS "network.allow-experiments" #define SAFE_HINT_HEADER_VALUE "safeHint.enabled" #define SECURITY_PREFIX "security." @@ -203,13 +201,13 @@ nsHttpHandler::nsHttpHandler() , mCompatFirefoxEnabled(false) , mCompatFirefoxVersion("52.9") , mUserAgentIsDirty(true) + , mAcceptLanguagesIsDirty(true) , mPromptTempRedirect(true) , mEnablePersistentHttpsCaching(false) , mDoNotTrackEnabled(false) , mSafeHintEnabled(false) , mParentalControlEnabled(false) , mHandlerActive(false) - , mTelemetryEnabled(false) , mAllowExperiments(true) , mDebugObservations(false) , mEnableSpdy(false) @@ -305,7 +303,6 @@ nsHttpHandler::Init() prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true); prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true); prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true); - prefBranch->AddObserver(TELEMETRY_ENABLED, this, true); prefBranch->AddObserver(H2MANDATORY_SUITE, this, true); prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.short_lived_connections"), this, true); prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.long_lived_connections"), this, true); @@ -419,6 +416,7 @@ nsHttpHandler::Init() obsService->AddObserver(this, "browser:purge-session-history", true); obsService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true); obsService->AddObserver(this, "application-background", true); + obsService->AddObserver(this, "string-bundles-have-flushed", true); } MakeNewRequestTokenBucket(); @@ -470,7 +468,9 @@ nsHttpHandler::InitConnectionMgr() } nsresult -nsHttpHandler::AddStandardRequestHeaders(nsHttpRequestHead *request, bool isSecure) +nsHttpHandler::AddStandardRequestHeaders(nsHttpRequestHead *request, + bool isSecure, + nsContentPolicyType aContentPolicyType) { nsresult rv; @@ -483,14 +483,32 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpRequestHead *request, bool isSecu // Add the "Accept" header. Note, this is set as an override because the // service worker expects to see it. The other "default" headers are // hidden from service worker interception. - rv = request->SetHeader(nsHttp::Accept, mAccept, + nsAutoCString accept; + if (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || + aContentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) { + accept.Assign(mAcceptNavigation); + } else if (aContentPolicyType == nsIContentPolicy::TYPE_IMAGE || + aContentPolicyType == nsIContentPolicy::TYPE_IMAGESET) { + accept.Assign(mAcceptImage); + } else if (aContentPolicyType == nsIContentPolicy::TYPE_STYLESHEET) { + accept.Assign(mAcceptStyle); + } else { + accept.Assign(mAcceptDefault); + } + + rv = request->SetHeader(nsHttp::Accept, accept, false, nsHttpHeaderArray::eVarietyRequestOverride); if (NS_FAILED(rv)) return rv; // Add the "Accept-Language" header. This header is also exposed to the // service worker. + if (mAcceptLanguagesIsDirty) { + rv = SetAcceptLanguages(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + } + + // Add the "Accept-Language" header if (!mAcceptLanguages.IsEmpty()) { - // Add the "Accept-Language" header rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages, false, nsHttpHeaderArray::eVarietyRequestOverride); @@ -1265,12 +1283,36 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) mQoSBits = (uint8_t) clamped(val, 0, 0xff); } + if (PREF_CHANGED(HTTP_PREF("accept.navigation"))) { + nsXPIDLCString accept; + rv = prefs->GetCharPref(HTTP_PREF("accept.navigation"), + getter_Copies(accept)); + if (NS_SUCCEEDED(rv)) + SetAccept(accept, ACCEPT_NAVIGATION); + } + + if (PREF_CHANGED(HTTP_PREF("accept.image"))) { + nsXPIDLCString accept; + rv = prefs->GetCharPref(HTTP_PREF("accept.image"), + getter_Copies(accept)); + if (NS_SUCCEEDED(rv)) + SetAccept(accept, ACCEPT_IMAGE); + } + + if (PREF_CHANGED(HTTP_PREF("accept.style"))) { + nsXPIDLCString accept; + rv = prefs->GetCharPref(HTTP_PREF("accept.style"), + getter_Copies(accept)); + if (NS_SUCCEEDED(rv)) + SetAccept(accept, ACCEPT_STYLE); + } + if (PREF_CHANGED(HTTP_PREF("accept.default"))) { nsXPIDLCString accept; rv = prefs->GetCharPref(HTTP_PREF("accept.default"), getter_Copies(accept)); if (NS_SUCCEEDED(rv)) - SetAccept(accept); + SetAccept(accept, ACCEPT_DEFAULT); } if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) { @@ -1511,16 +1553,10 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) // if (PREF_CHANGED(INTL_ACCEPT_LANGUAGES)) { - nsCOMPtr<nsIPrefLocalizedString> pls; - prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES, - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(pls)); - if (pls) { - nsXPIDLString uval; - pls->ToString(getter_Copies(uval)); - if (uval) - SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get()); - } + // We don't want to set the new accept languages here since + // this pref is a complex type and it may be racy with flushing + // string resources. + mAcceptLanguagesIsDirty = true; } // @@ -1547,19 +1583,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) // includes telemetry and allow-experiments because of the abtest profile bool requestTokenBucketUpdated = false; - // - // Telemetry - // - - if (PREF_CHANGED(TELEMETRY_ENABLED)) { - cVar = false; - requestTokenBucketUpdated = true; - rv = prefs->GetBoolPref(TELEMETRY_ENABLED, &cVar); - if (NS_SUCCEEDED(rv)) { - mTelemetryEnabled = cVar; - } - } - // "security.ssl3.ecdhe_rsa_aes_128_gcm_sha256" is the required h2 interop // suite. @@ -1897,19 +1920,37 @@ PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLangua } nsresult -nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages) +nsHttpHandler::SetAcceptLanguages() { + mAcceptLanguagesIsDirty = false; + + const nsAdoptingCString& acceptLanguages = + Preferences::GetLocalizedCString(INTL_ACCEPT_LANGUAGES); + nsAutoCString buf; - nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf); - if (NS_SUCCEEDED(rv)) + nsresult rv = PrepareAcceptLanguages(acceptLanguages.get(), buf); + if (NS_SUCCEEDED(rv)) { mAcceptLanguages.Assign(buf); + } return rv; } nsresult -nsHttpHandler::SetAccept(const char *aAccept) +nsHttpHandler::SetAccept(const char *aAccept, AcceptType aType) { - mAccept = aAccept; + switch (aType) { + case ACCEPT_NAVIGATION: + mAcceptNavigation = aAccept; + break; + case ACCEPT_IMAGE: + mAcceptImage = aAccept; + break; + case ACCEPT_STYLE: + mAcceptStyle = aAccept; + break; + case ACCEPT_DEFAULT: + mAcceptDefault = aAccept; + } return NS_OK; } @@ -2067,7 +2108,11 @@ nsHttpHandler::NewProxiedChannel2(nsIURI *uri, rv = NewChannelId(&channelId); NS_ENSURE_SUCCESS(rv, rv); - rv = httpChannel->Init(uri, caps, proxyInfo, proxyResolveFlags, proxyURI, channelId); + nsContentPolicyType contentPolicyType = + aLoadInfo ? aLoadInfo->GetExternalContentPolicyType() + : nsIContentPolicy::TYPE_OTHER; + + rv = httpChannel->Init(uri, caps, proxyInfo, proxyResolveFlags, proxyURI, channelId, contentPolicyType); if (NS_FAILED(rv)) return rv; @@ -2175,11 +2220,6 @@ nsHttpHandler::Observe(nsISupports *subject, // depend on this value. mSessionStartTime = NowInSeconds(); - if (!mDoNotTrackEnabled) { - Telemetry::Accumulate(Telemetry::DNT_USAGE, 2); - } else { - Telemetry::Accumulate(Telemetry::DNT_USAGE, 1); - } } else if (!strcmp(topic, "profile-change-net-restore")) { // initialize connection manager InitConnectionMgr(); @@ -2233,6 +2273,8 @@ nsHttpHandler::Observe(nsISupports *subject, if (mConnMgr) { mConnMgr->DoShiftReloadConnectionCleanup(nullptr); } + } else if (!strcmp(topic, "string-bundles-have-flushed")) { + mAcceptLanguagesIsDirty = true; } return NS_OK; diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 0904af893..67b9ebe0e 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -15,6 +15,7 @@ #include "nsCOMPtr.h" #include "nsWeakReference.h" +#include "nsIContentPolicy.h" #include "nsIHttpProtocolHandler.h" #include "nsIObserver.h" #include "nsISpeculativeConnect.h" @@ -50,6 +51,14 @@ enum FrameCheckLevel { FRAMECHECK_STRICT }; +// Fetch spec different http Accept types +enum AcceptType { + ACCEPT_NAVIGATION, + ACCEPT_IMAGE, + ACCEPT_STYLE, + ACCEPT_DEFAULT, +}; + //----------------------------------------------------------------------------- // nsHttpHandler - protocol handler for HTTP and HTTPS //----------------------------------------------------------------------------- @@ -70,7 +79,7 @@ public: nsHttpHandler(); nsresult Init(); - nsresult AddStandardRequestHeaders(nsHttpRequestHead *, bool isSecure); + nsresult AddStandardRequestHeaders(nsHttpRequestHead *, bool isSecure, nsContentPolicyType aContentPolicyType); nsresult AddConnectionHeader(nsHttpRequestHead *, uint32_t capabilities); bool IsAcceptableEncoding(const char *encoding, bool isSecure); @@ -105,8 +114,10 @@ public: bool EnforceAssocReq() { return mEnforceAssocReq; } bool IsPersistentHttpsCachingEnabled() { return mEnablePersistentHttpsCaching; } - bool IsTelemetryEnabled() { return mTelemetryEnabled; } - bool AllowExperiments() { return mTelemetryEnabled && mAllowExperiments; } + + // Since telemetry has been removed, experiments should also not be allowed. + // Making this function return `false` for now, it will be cleaned up later. + bool AllowExperiments() { return false; } bool IsSpdyEnabled() { return mEnableSpdy; } bool IsHttp2Enabled() { return mHttp2Enabled; } @@ -383,8 +394,8 @@ private: void InitUserAgentComponents(); void PrefsChanged(nsIPrefBranch *prefs, const char *pref); - nsresult SetAccept(const char *); - nsresult SetAcceptLanguages(const char *); + nsresult SetAccept(const char *, AcceptType aType); + nsresult SetAcceptLanguages(); nsresult SetAcceptEncodings(const char *, bool mIsSecure); nsresult InitConnectionMgr(); @@ -392,8 +403,8 @@ private: void NotifyObservers(nsIHttpChannel *chan, const char *event); static void TimerCallback(nsITimer * aTimer, void * aClosure); + private: - // cached services nsMainThreadPtrHandle<nsIIOService> mIOService; nsMainThreadPtrHandle<nsIStreamConverterService> mStreamConvSvc; @@ -458,7 +469,10 @@ private: bool mPipeliningOverSSL; bool mEnforceAssocReq; - nsCString mAccept; + nsCString mAcceptNavigation; + nsCString mAcceptImage; + nsCString mAcceptStyle; + nsCString mAcceptDefault; nsCString mAcceptLanguages; nsCString mHttpAcceptEncodings; nsCString mHttpsAcceptEncodings; @@ -491,6 +505,7 @@ private: nsCString mUserAgent; nsXPIDLCString mUserAgentOverride; bool mUserAgentIsDirty; // true if mUserAgent should be rebuilt + bool mAcceptLanguagesIsDirty; bool mPromptTempRedirect; @@ -508,9 +523,6 @@ private: // true in between init and shutdown states Atomic<bool, Relaxed> mHandlerActive; - // Whether telemetry is reported or not - uint32_t mTelemetryEnabled : 1; - // The value of network.allow-experiments uint32_t mAllowExperiments : 1; diff --git a/netwerk/protocol/http/nsHttpHeaderArray.cpp b/netwerk/protocol/http/nsHttpHeaderArray.cpp index 670300dea..1030bc91e 100644 --- a/netwerk/protocol/http/nsHttpHeaderArray.cpp +++ b/netwerk/protocol/http/nsHttpHeaderArray.cpp @@ -18,12 +18,37 @@ namespace net { //----------------------------------------------------------------------------- // nsHttpHeaderArray <public> //----------------------------------------------------------------------------- + +nsresult +nsHttpHeaderArray::SetHeader(const nsACString &headerName, + const nsACString &value, + bool merge, + nsHttpHeaderArray::HeaderVariety variety) +{ + nsHttpAtom header = nsHttp::ResolveAtom(PromiseFlatCString(headerName).get()); + if (!header) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + return SetHeader(header, headerName, value, merge, variety); +} + nsresult nsHttpHeaderArray::SetHeader(nsHttpAtom header, const nsACString &value, bool merge, nsHttpHeaderArray::HeaderVariety variety) { + return SetHeader(header, EmptyCString(), value, merge, variety); +} + +nsresult +nsHttpHeaderArray::SetHeader(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, + bool merge, + nsHttpHeaderArray::HeaderVariety variety) +{ MOZ_ASSERT((variety == eVarietyResponse) || (variety == eVarietyRequestDefault) || (variety == eVarietyRequestOverride), @@ -51,7 +76,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, MOZ_ASSERT(!entry || variety != eVarietyRequestDefault, "Cannot set default entry which overrides existing entry!"); if (!entry) { - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerName, value, variety); } else if (merge && !IsSingletonHeader(header)) { return MergeHeader(header, entry, value, variety); } else { @@ -59,7 +84,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, if (entry->variety == eVarietyResponseNetOriginalAndResponse) { MOZ_ASSERT(variety == eVarietyResponse); entry->variety = eVarietyResponseNetOriginal; - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerName, value, variety); } else { entry->value = value; entry->variety = variety; @@ -71,6 +96,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, nsresult nsHttpHeaderArray::SetHeader_internal(nsHttpAtom header, + const nsACString &headerName, const nsACString &value, nsHttpHeaderArray::HeaderVariety variety) { @@ -79,14 +105,26 @@ nsHttpHeaderArray::SetHeader_internal(nsHttpAtom header, return NS_ERROR_OUT_OF_MEMORY; } entry->header = header; + // Only save original form of a header if it is different than the header + // atom string. + if (!headerName.Equals(header.get())) { + entry->headerNameOriginal = headerName; + } entry->value = value; entry->variety = variety; return NS_OK; } nsresult -nsHttpHeaderArray::SetEmptyHeader(nsHttpAtom header, HeaderVariety variety) +nsHttpHeaderArray::SetEmptyHeader(const nsACString &headerName, + HeaderVariety variety) { + nsHttpAtom header = nsHttp::ResolveAtom(PromiseFlatCString(headerName).get()); + if (!header) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + MOZ_ASSERT((variety == eVarietyResponse) || (variety == eVarietyRequestDefault) || (variety == eVarietyRequestOverride), @@ -104,11 +142,12 @@ nsHttpHeaderArray::SetEmptyHeader(nsHttpAtom header, HeaderVariety variety) entry->variety = eVarietyResponseNetOriginal; } - return SetHeader_internal(header, EmptyCString(), variety); + return SetHeader_internal(header, headerName, EmptyCString(), variety); } nsresult nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, + const nsACString &headerNameOriginal, const nsACString &value, bool response) { @@ -125,7 +164,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, LOG(("Ignoring Empty Header: %s\n", header.get())); if (response) { // Set header as original but not as response header. - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } return NS_OK; // ignore empty headers by default @@ -135,7 +174,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, if (response) { variety = eVarietyResponseNetOriginalAndResponse; } - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerNameOriginal, value, variety); } else if (!IsSingletonHeader(header)) { HeaderVariety variety = eVarietyRequestOverride; @@ -147,7 +186,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, return rv; } if (response) { - rv = SetHeader_internal(header, value, + rv = SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } return rv; @@ -164,7 +203,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, } if (response) { - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } } @@ -174,6 +213,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, nsresult nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, + const nsACString &headerNameOriginal, const nsACString &value, nsHttpHeaderArray::HeaderVariety variety) { @@ -183,7 +223,7 @@ nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, "eVarietyResponseNetOriginal"); if (variety == eVarietyResponseNetOriginal) { - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } else { nsTArray<nsEntry>::index_type index = 0; @@ -203,7 +243,8 @@ nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, } } while (index != mHeaders.NoIndex); // If we are here, we have not found an entry so add a new one. - return SetHeader_internal(header, value, eVarietyResponse); + return SetHeader_internal(header, headerNameOriginal, value, + eVarietyResponse); } } @@ -260,8 +301,16 @@ nsHttpHeaderArray::GetOriginalHeader(nsHttpAtom aHeader, if (entry.variety == eVarietyResponse) { continue; } + + nsAutoCString hdr; + if (entry.headerNameOriginal.IsEmpty()) { + hdr = nsDependentCString(entry.header); + } else { + hdr = entry.headerNameOriginal; + } + rv = NS_OK; - if (NS_FAILED(aVisitor->VisitHeader(nsDependentCString(entry.header), + if (NS_FAILED(aVisitor->VisitHeader(hdr, entry.value))) { break; } @@ -298,8 +347,14 @@ nsHttpHeaderArray::VisitHeaders(nsIHttpHeaderVisitor *visitor, nsHttpHeaderArray } else if (filter == eFilterResponseOriginal && entry.variety == eVarietyResponse) { continue; } - rv = visitor->VisitHeader( - nsDependentCString(entry.header), entry.value); + + nsAutoCString hdr; + if (entry.headerNameOriginal.IsEmpty()) { + hdr = nsDependentCString(entry.header); + } else { + hdr = entry.headerNameOriginal; + } + rv = visitor->VisitHeader(hdr, entry.value); if NS_FAILED(rv) { return rv; } @@ -310,6 +365,7 @@ nsHttpHeaderArray::VisitHeaders(nsIHttpHeaderVisitor *visitor, nsHttpHeaderArray /*static*/ nsresult nsHttpHeaderArray::ParseHeaderLine(const nsACString& line, nsHttpAtom *hdr, + nsACString *headerName, nsACString *val) { // @@ -360,6 +416,7 @@ nsHttpHeaderArray::ParseHeaderLine(const nsACString& line, // assign return values if (hdr) *hdr = atom; if (val) val->Assign(p, p2 - p + 1); + if (headerName) headerName->Assign(sub); return NS_OK; } @@ -397,7 +454,11 @@ nsHttpHeaderArray::Flatten(nsACString &buf, bool pruneProxyHeaders, continue; } - buf.Append(entry.header); + if (entry.headerNameOriginal.IsEmpty()) { + buf.Append(entry.header); + } else { + buf.Append(entry.headerNameOriginal); + } buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); @@ -415,7 +476,11 @@ nsHttpHeaderArray::FlattenOriginalHeader(nsACString &buf) continue; } - buf.Append(entry.header); + if (entry.headerNameOriginal.IsEmpty()) { + buf.Append(entry.header); + } else { + buf.Append(entry.headerNameOriginal); + } buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); @@ -423,11 +488,13 @@ nsHttpHeaderArray::FlattenOriginalHeader(nsACString &buf) } const char * -nsHttpHeaderArray::PeekHeaderAt(uint32_t index, nsHttpAtom &header) const +nsHttpHeaderArray::PeekHeaderAt(uint32_t index, nsHttpAtom &header, + nsACString &headerNameOriginal) const { const nsEntry &entry = mHeaders[index]; header = entry.header; + headerNameOriginal = entry.headerNameOriginal; return entry.value.get(); } diff --git a/netwerk/protocol/http/nsHttpHeaderArray.h b/netwerk/protocol/http/nsHttpHeaderArray.h index 91b91f04a..3ffdfa814 100644 --- a/netwerk/protocol/http/nsHttpHeaderArray.h +++ b/netwerk/protocol/http/nsHttpHeaderArray.h @@ -49,19 +49,30 @@ public: }; // Used by internal setters: to set header from network use SetHeaderFromNet + nsresult SetHeader(const nsACString &headerName, + const nsACString &value, + bool merge, HeaderVariety variety); nsresult SetHeader(nsHttpAtom header, const nsACString &value, bool merge, HeaderVariety variety); + nsresult SetHeader(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, + bool merge, HeaderVariety variety); // Used by internal setters to set an empty header - nsresult SetEmptyHeader(nsHttpAtom header, HeaderVariety variety); + nsresult SetEmptyHeader(const nsACString &headerName, HeaderVariety variety); // Merges supported headers. For other duplicate values, determines if error // needs to be thrown or 1st value kept. // For the response header we keep the original headers as well. - nsresult SetHeaderFromNet(nsHttpAtom header, const nsACString &value, + nsresult SetHeaderFromNet(nsHttpAtom header, + const nsACString &headerNameOriginal, + const nsACString &value, bool response); - nsresult SetResponseHeaderFromCache(nsHttpAtom header, const nsACString &value, + nsresult SetResponseHeaderFromCache(nsHttpAtom header, + const nsACString &headerNameOriginal, + const nsACString &value, HeaderVariety variety); nsresult GetHeader(nsHttpAtom header, nsACString &value) const; @@ -97,15 +108,17 @@ public: // parse a header line, return the header atom and a pointer to the // header value (the substring of the header line -- do not free). static nsresult ParseHeaderLine(const nsACString& line, - nsHttpAtom *header=nullptr, - nsACString* value=nullptr); + nsHttpAtom *header = nullptr, + nsACString *headerNameOriginal = nullptr, + nsACString *value = nullptr); void Flatten(nsACString &, bool pruneProxyHeaders, bool pruneTransients); void FlattenOriginalHeader(nsACString &); uint32_t Count() const { return mHeaders.Length(); } - const char *PeekHeaderAt(uint32_t i, nsHttpAtom &header) const; + const char *PeekHeaderAt(uint32_t i, nsHttpAtom &header, + nsACString &headerNameOriginal) const; void Clear(); @@ -113,6 +126,7 @@ public: struct nsEntry { nsHttpAtom header; + nsCString headerNameOriginal; nsCString value; HeaderVariety variety = eVarietyUnknown; @@ -140,7 +154,9 @@ private: int32_t LookupEntry(nsHttpAtom header, nsEntry **); nsresult MergeHeader(nsHttpAtom header, nsEntry *entry, const nsACString &value, HeaderVariety variety); - nsresult SetHeader_internal(nsHttpAtom header, const nsACString &value, + nsresult SetHeader_internal(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, HeaderVariety variety); // Header cannot be merged: only one value possible @@ -257,7 +273,11 @@ nsHttpHeaderArray::MergeHeader(nsHttpAtom header, if (entry->variety == eVarietyResponseNetOriginalAndResponse) { MOZ_ASSERT(variety == eVarietyResponse); entry->variety = eVarietyResponseNetOriginal; - nsresult rv = SetHeader_internal(header, newValue, eVarietyResponse); + // Copy entry->headerNameOriginal because in SetHeader_internal we are going + // to a new one and a realocation can happen. + nsCString headerNameOriginal = entry->headerNameOriginal; + nsresult rv = SetHeader_internal(header, headerNameOriginal, + newValue, eVarietyResponse); if (NS_FAILED(rv)) { return rv; } diff --git a/netwerk/protocol/http/nsHttpPipeline.cpp b/netwerk/protocol/http/nsHttpPipeline.cpp index 293de8e39..4f5777244 100644 --- a/netwerk/protocol/http/nsHttpPipeline.cpp +++ b/netwerk/protocol/http/nsHttpPipeline.cpp @@ -291,6 +291,11 @@ nsHttpPipeline::PushBack(const char *data, uint32_t length) MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); MOZ_ASSERT(mPushBackLen == 0, "push back buffer already has data!"); + // Some bad behaving proxies may yank the connection out from under us. + // Check if we still have a connection to work with. + if (!mConnection) + return NS_ERROR_FAILURE; + // If we have no chance for a pipeline (e.g. due to an Upgrade) // then push this data down to original connection if (!mConnection->IsPersistent()) diff --git a/netwerk/protocol/http/nsHttpRequestHead.cpp b/netwerk/protocol/http/nsHttpRequestHead.cpp index 094a79457..b366a8d54 100644 --- a/netwerk/protocol/http/nsHttpRequestHead.cpp +++ b/netwerk/protocol/http/nsHttpRequestHead.cpp @@ -131,6 +131,20 @@ nsHttpRequestHead::Origin(nsACString &aOrigin) } nsresult +nsHttpRequestHead::SetHeader(const nsACString &h, const nsACString &v, + bool m /*= false*/) +{ + ReentrantMonitorAutoEnter mon(mReentrantMonitor); + + if (mInVisitHeaders) { + return NS_ERROR_FAILURE; + } + + return mHeaders.SetHeader(h, v, m, + nsHttpHeaderArray::eVarietyRequestOverride); +} + +nsresult nsHttpRequestHead::SetHeader(nsHttpAtom h, const nsACString &v, bool m /*= false*/) { @@ -158,7 +172,7 @@ nsHttpRequestHead::SetHeader(nsHttpAtom h, const nsACString &v, bool m, } nsresult -nsHttpRequestHead::SetEmptyHeader(nsHttpAtom h) +nsHttpRequestHead::SetEmptyHeader(const nsACString &h) { ReentrantMonitorAutoEnter mon(mReentrantMonitor); @@ -253,6 +267,7 @@ nsHttpRequestHead::ParseHeaderSet(const char *buffer) { ReentrantMonitorAutoEnter mon(mReentrantMonitor); nsHttpAtom hdr; + nsAutoCString headerNameOriginal; nsAutoCString val; while (buffer) { const char *eof = strchr(buffer, '\r'); @@ -262,9 +277,13 @@ nsHttpRequestHead::ParseHeaderSet(const char *buffer) if (NS_SUCCEEDED(nsHttpHeaderArray::ParseHeaderLine( nsDependentCSubstring(buffer, eof - buffer), &hdr, + &headerNameOriginal, &val))) { - mHeaders.SetHeaderFromNet(hdr, val, false); + mHeaders.SetHeaderFromNet(hdr, + headerNameOriginal, + val, + false); } buffer = eof + 1; if (*buffer == '\n') { diff --git a/netwerk/protocol/http/nsHttpRequestHead.h b/netwerk/protocol/http/nsHttpRequestHead.h index 415968083..b7020d33a 100644 --- a/netwerk/protocol/http/nsHttpRequestHead.h +++ b/netwerk/protocol/http/nsHttpRequestHead.h @@ -57,10 +57,12 @@ public: int32_t port); void Origin(nsACString &aOrigin); + nsresult SetHeader(const nsACString &h, const nsACString &v, + bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m, nsHttpHeaderArray::HeaderVariety variety); - nsresult SetEmptyHeader(nsHttpAtom h); + nsresult SetEmptyHeader(const nsACString &h); nsresult GetHeader(nsHttpAtom h, nsACString &v); nsresult ClearHeader(nsHttpAtom h); diff --git a/netwerk/protocol/http/nsHttpResponseHead.cpp b/netwerk/protocol/http/nsHttpResponseHead.cpp index 6d384c488..fa6430b82 100644 --- a/netwerk/protocol/http/nsHttpResponseHead.cpp +++ b/netwerk/protocol/http/nsHttpResponseHead.cpp @@ -137,6 +137,26 @@ nsHttpResponseHead::Immutable() } nsresult +nsHttpResponseHead::SetHeader(const nsACString &hdr, + const nsACString &val, + bool merge) +{ + ReentrantMonitorAutoEnter monitor(mReentrantMonitor); + + if (mInVisitHeaders) { + return NS_ERROR_FAILURE; + } + + nsHttpAtom atom = nsHttp::ResolveAtom(PromiseFlatCString(hdr).get()); + if (!atom) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + + return SetHeader_locked(atom, hdr, val, merge); +} + +nsresult nsHttpResponseHead::SetHeader(nsHttpAtom hdr, const nsACString &val, bool merge) @@ -147,24 +167,25 @@ nsHttpResponseHead::SetHeader(nsHttpAtom hdr, return NS_ERROR_FAILURE; } - return SetHeader_locked(hdr, val, merge); + return SetHeader_locked(hdr, EmptyCString(), val, merge); } nsresult -nsHttpResponseHead::SetHeader_locked(nsHttpAtom hdr, +nsHttpResponseHead::SetHeader_locked(nsHttpAtom atom, + const nsACString &hdr, const nsACString &val, bool merge) { - nsresult rv = mHeaders.SetHeader(hdr, val, merge, + nsresult rv = mHeaders.SetHeader(atom, hdr, val, merge, nsHttpHeaderArray::eVarietyResponse); if (NS_FAILED(rv)) return rv; // respond to changes in these headers. we need to reparse the entire // header since the change may have merged in additional values. - if (hdr == nsHttp::Cache_Control) - ParseCacheControl(mHeaders.PeekHeader(hdr)); - else if (hdr == nsHttp::Pragma) - ParsePragma(mHeaders.PeekHeader(hdr)); + if (atom == nsHttp::Cache_Control) + ParseCacheControl(mHeaders.PeekHeader(atom)); + else if (atom == nsHttp::Pragma) + ParsePragma(mHeaders.PeekHeader(atom)); return NS_OK; } @@ -316,6 +337,7 @@ nsHttpResponseHead::ParseCachedOriginalHeaders(char *block) char *p = block; nsHttpAtom hdr = {0}; + nsAutoCString headerNameOriginal; nsAutoCString val; nsresult rv; @@ -331,12 +353,13 @@ nsHttpResponseHead::ParseCachedOriginalHeaders(char *block) *p = 0; if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine( - nsDependentCString(block, p - block), &hdr, &val))) { + nsDependentCString(block, p - block), &hdr, &headerNameOriginal, &val))) { return NS_OK; } rv = mHeaders.SetResponseHeaderFromCache(hdr, + headerNameOriginal, val, nsHttpHeaderArray::eVarietyResponseNetOriginal); @@ -567,18 +590,21 @@ nsresult nsHttpResponseHead::ParseHeaderLine_locked(const nsACString &line, bool originalFromNetHeaders) { nsHttpAtom hdr = {0}; + nsAutoCString headerNameOriginal; nsAutoCString val; - if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine(line, &hdr, &val))) { + if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine(line, &hdr, &headerNameOriginal, &val))) { return NS_OK; } nsresult rv; if (originalFromNetHeaders) { rv = mHeaders.SetHeaderFromNet(hdr, + headerNameOriginal, val, true); } else { rv = mHeaders.SetResponseHeaderFromCache(hdr, + headerNameOriginal, val, nsHttpHeaderArray::eVarietyResponse); } @@ -856,7 +882,8 @@ nsHttpResponseHead::UpdateHeaders(nsHttpResponseHead *aOther) uint32_t i, count = aOther->mHeaders.Count(); for (i=0; i<count; ++i) { nsHttpAtom header; - const char *val = aOther->mHeaders.PeekHeaderAt(i, header); + nsAutoCString headerNameOriginal; + const char *val = aOther->mHeaders.PeekHeaderAt(i, header, headerNameOriginal); if (!val) { continue; @@ -890,7 +917,8 @@ nsHttpResponseHead::UpdateHeaders(nsHttpResponseHead *aOther) LOG(("new response header [%s: %s]\n", header.get(), val)); // overwrite the current header value with the new value... - SetHeader_locked(header, nsDependentCString(val)); + SetHeader_locked(header, headerNameOriginal, + nsDependentCString(val)); } } diff --git a/netwerk/protocol/http/nsHttpResponseHead.h b/netwerk/protocol/http/nsHttpResponseHead.h index 0a912f4b4..8b51386ea 100644 --- a/netwerk/protocol/http/nsHttpResponseHead.h +++ b/netwerk/protocol/http/nsHttpResponseHead.h @@ -65,6 +65,8 @@ public: */ int64_t TotalEntitySize(); + nsresult SetHeader(const nsACString &h, const nsACString &v, + bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false); nsresult GetHeader(nsHttpAtom h, nsACString &v); void ClearHeader(nsHttpAtom h); @@ -137,8 +139,8 @@ public: bool HasContentType(); bool HasContentCharset(); private: - nsresult SetHeader_locked(nsHttpAtom h, const nsACString &v, - bool m=false); + nsresult SetHeader_locked(nsHttpAtom atom, const nsACString &h, + const nsACString &v, bool m=false); void AssignDefaultStatusText(); void ParseVersion(const char *); void ParseCacheControl(const char *); diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index 8d837d172..76e0a4ad9 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -1164,7 +1164,9 @@ nsHttpTransaction::Close(nsresult reason) } // closing this pipe triggers the channel's OnStopRequest method. - mPipeOut->CloseWithStatus(reason); + if (mPipeOut) { + mPipeOut->CloseWithStatus(reason); + } #ifdef WIN32 // bug 1153929 MOZ_DIAGNOSTIC_ASSERT(mPipeOut); diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index c6dc8d328..1bcdbcacc 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -55,7 +55,6 @@ #include "nsNetUtil.h" #include "nsINode.h" #include "mozilla/StaticMutex.h" -#include "mozilla/Telemetry.h" #include "mozilla/TimeStamp.h" #include "nsSocketTransportService2.h" @@ -2989,7 +2988,6 @@ WebSocketChannel::ReportConnectionTelemetry() (didProxy ? (1 << 0) : 0); LOG(("WebSocketChannel::ReportConnectionTelemetry() %p %d", this, value)); - Telemetry::Accumulate(Telemetry::WEBSOCKETS_HANDSHAKE_TYPE, value); } // nsIDNSListener diff --git a/netwerk/sctp/datachannel/DataChannel.cpp b/netwerk/sctp/datachannel/DataChannel.cpp index f2a91c589..19be43d1c 100644 --- a/netwerk/sctp/datachannel/DataChannel.cpp +++ b/netwerk/sctp/datachannel/DataChannel.cpp @@ -276,6 +276,7 @@ DataChannelConnection::Destroy() LOG(("Deregistered %p from the SCTP stack.", static_cast<void *>(this))); } + mListener = nullptr; // Finish Destroy on STS thread to avoid bug 876167 - once that's fixed, // the usrsctp_close() calls can move back here (and just proxy the // disconnect_all()) @@ -1927,12 +1928,21 @@ DataChannelConnection::ReceiveCallback(struct socket* sock, void *data, size_t d if (!data) { usrsctp_close(sock); // SCTP has finished shutting down } else { - mLock.AssertCurrentThreadOwns(); + bool locked = false; + if (!IsSTSThread()) { + mLock.Lock(); + locked = true; + } else { + mLock.AssertCurrentThreadOwns(); + } if (flags & MSG_NOTIFICATION) { HandleNotification(static_cast<union sctp_notification *>(data), datalen); } else { HandleMessage(data, datalen, ntohl(rcv.rcv_ppid), rcv.rcv_sid); } + if (locked) { + mLock.Unlock(); + } } // sctp allocates 'data' with malloc(), and expects the receiver to free // it (presumably with free). diff --git a/netwerk/socket/nsSOCKSIOLayer.cpp b/netwerk/socket/nsSOCKSIOLayer.cpp index 22f5751fb..5429637c1 100644 --- a/netwerk/socket/nsSOCKSIOLayer.cpp +++ b/netwerk/socket/nsSOCKSIOLayer.cpp @@ -229,6 +229,7 @@ nsSOCKSSocketInfo::nsSOCKSSocketInfo() , mDataLength(0) , mReadOffset(0) , mAmountToRead(0) + , mFD(nullptr) , mVersion(-1) , mDestinationFamily(AF_INET) , mFlags(0) diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.cpp b/netwerk/streamconv/converters/nsIndexedToHTML.cpp index 0414c4841..29fea8bfb 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp +++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp @@ -146,7 +146,14 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, nsAutoCString baseUri, titleUri; rv = uri->GetAsciiSpec(baseUri); if (NS_FAILED(rv)) return rv; - titleUri = baseUri; + + nsCOMPtr<nsIURI> titleURL; + rv = uri->Clone(getter_AddRefs(titleURL)); + if (NS_FAILED(rv)) titleURL = uri; + rv = titleURL->SetQuery(EmptyCString()); + if (NS_FAILED(rv)) titleURL = uri; + rv = titleURL->SetRef(EmptyCString()); + if (NS_FAILED(rv)) titleURL = uri; nsCString parentStr; @@ -170,16 +177,14 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, // that - see above nsAutoCString pw; - rv = uri->GetPassword(pw); + rv = titleURL->GetPassword(pw); if (NS_FAILED(rv)) return rv; if (!pw.IsEmpty()) { nsCOMPtr<nsIURI> newUri; - rv = uri->Clone(getter_AddRefs(newUri)); + rv = titleURL->Clone(getter_AddRefs(newUri)); if (NS_FAILED(rv)) return rv; rv = newUri->SetPassword(EmptyCString()); if (NS_FAILED(rv)) return rv; - rv = newUri->GetAsciiSpec(titleUri); - if (NS_FAILED(rv)) return rv; } nsAutoCString path; @@ -247,6 +252,11 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, } } + rv = titleURL->GetAsciiSpec(titleUri); + if (NS_FAILED(rv)) { + return rv; + } + buffer.AppendLiteral("<style type=\"text/css\">\n" ":root {\n" " font-family: sans-serif;\n" diff --git a/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp b/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp index 4fc36928a..b9f912d1d 100644 --- a/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp +++ b/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp @@ -24,7 +24,6 @@ #include "mozilla/Services.h" #include "mozilla/SHA1.h" #include "mozilla/Sprintf.h" -#include "mozilla/Telemetry.h" /* a shorter name that better explains what it does */ #define EINTR_RETRY(x) MOZ_TEMP_FAILURE_RETRY(x) @@ -176,12 +175,10 @@ void nsNotifyAddrListener::calculateNetworkId(void) LOG(("networkid: id %s\n", output.get())); if (mNetworkId != output) { // new id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 1); mNetworkId = output; } else { // same id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 2); } found = true; break; @@ -195,7 +192,6 @@ void nsNotifyAddrListener::calculateNetworkId(void) } /* if (froute) */ if (!found) { // no id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 0); } } diff --git a/netwerk/system/mac/nsNetworkLinkService.mm b/netwerk/system/mac/nsNetworkLinkService.mm index ac6a015fb..5b2d7575a 100644 --- a/netwerk/system/mac/nsNetworkLinkService.mm +++ b/netwerk/system/mac/nsNetworkLinkService.mm @@ -24,7 +24,6 @@ #include "mozilla/Preferences.h" #include "mozilla/SHA1.h" #include "mozilla/Base64.h" -#include "mozilla/Telemetry.h" #include "nsNetworkLinkService.h" #import <Cocoa/Cocoa.h> @@ -274,19 +273,16 @@ void nsNetworkLinkService::calculateNetworkId(void) LOG(("networkid: id %s\n", output.get())); if (mNetworkId != output) { // new id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 1); mNetworkId = output; } else { // same id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 2); } found = true; } } if (!found) { // no id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 0); } } diff --git a/netwerk/system/win32/nsNotifyAddrListener.cpp b/netwerk/system/win32/nsNotifyAddrListener.cpp index 5d1ec3a61..58f4345ef 100644 --- a/netwerk/system/win32/nsNotifyAddrListener.cpp +++ b/netwerk/system/win32/nsNotifyAddrListener.cpp @@ -35,7 +35,6 @@ #include "mozilla/Preferences.h" #include "mozilla/SHA1.h" #include "mozilla/Base64.h" -#include "mozilla/Telemetry.h" #include <iptypes.h> #include <iphlpapi.h> @@ -218,12 +217,10 @@ bool nsNotifyAddrListener::findMac(char *gateway) LOG(("networkid: id %s\n", output.get())); if (mNetworkId != output) { // new id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 1); mNetworkId = output; } else { // same id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 2); } found = true; break; @@ -290,7 +287,6 @@ void nsNotifyAddrListener::calculateNetworkId(void) } if (!found) { // no id - Telemetry::Accumulate(Telemetry::NETWORK_ID, 0); } } diff --git a/netwerk/test/mochitests/mochitest.ini b/netwerk/test/mochitests/mochitest.ini index f8a919031..3cd5a674b 100644 --- a/netwerk/test/mochitests/mochitest.ini +++ b/netwerk/test/mochitests/mochitest.ini @@ -25,3 +25,5 @@ support-files = [test_viewsource_unlinkable.html] [test_xhr_method_case.html] [test_1396395.html] +[test_accept_header.html] +support-files = test_accept_header.sjs diff --git a/netwerk/test/mochitests/test_accept_header.html b/netwerk/test/mochitests/test_accept_header.html new file mode 100644 index 000000000..b8434230f --- /dev/null +++ b/netwerk/test/mochitests/test_accept_header.html @@ -0,0 +1,106 @@ +<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Accept header</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script>
+
+// All the requests are sent to test_accept_header.sjs which will return
+// different content based on the queryString. When the queryString is 'get',
+// test_accept_header.sjs returns a JSON object with the latest request and its
+// accept header value.
+
+function test_last_request_and_continue(query, expected) {
+ fetch("test_accept_header.sjs?get").then(r => r.json()).then(json => {
+ is(json.type, query, "Expected: " + query);
+ is(json.accept, expected, "Accept header: " + expected);
+ next();
+ });
+}
+
+function test_iframe() {
+ let observer = new PerformanceObserver(function(list, obj) {
+ obj.disconnect();
+
+ list.getEntries().forEach(entry => {
+ if (entry.name.endsWith("test_accept_header.sjs?iframe")) {
+ obj.disconnect();
+ test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ }
+ });
+ });
+
+ observer.observe({entryTypes: ["resource"]});
+
+ let ifr = document.createElement("iframe");
+ ifr.src = "test_accept_header.sjs?iframe";
+ document.body.appendChild(ifr);
+}
+
+function test_image() {
+ let i = new Image();
+ i.src = "test_accept_header.sjs?image";
+ i.onload = function() {
+ // Fetch spec says we should have: "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"
+ test_last_request_and_continue("image", "image/webp,image/png,image/*;q=0.8,*/*;q=0.5");
+ }
+}
+
+function test_style() {
+ let observer = new PerformanceObserver(function(list, obj) {
+ obj.disconnect();
+
+ list.getEntries().forEach(entry => {
+ if (entry.name.endsWith("test_accept_header.sjs?style")) {
+ obj.disconnect();
+ test_last_request_and_continue("style", "text/css,*/*;q=0.1");
+ }
+ });
+ });
+
+ observer.observe({entryTypes: ["resource"]});
+
+ let head = document.getElementsByTagName("head")[0];
+ let link = document.createElement("link");
+ link.rel = "stylesheet";
+ link.type = "text/css";
+ link.href = "test_accept_header.sjs?style";
+ head.appendChild(link);
+}
+
+function test_worker() {
+ let w = new Worker("test_accept_header.sjs?worker");
+ w.onmessage = function() {
+ test_last_request_and_continue("worker", "*/*");
+ }
+}
+
+let tests = [
+ test_iframe,
+ test_image,
+ test_style,
+ test_worker,
+];
+
+function next() {
+ if (tests.length == 0) {
+ SimpleTest.finish();
+ return;
+ }
+
+ let test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+SpecialPowers.pushPrefEnv({ "set": [
+ [ "dom.enable_performance_observer", true ]
+]}, next);
+
+</script>
+</body>
+</html>
diff --git a/netwerk/test/mochitests/test_accept_header.sjs b/netwerk/test/mochitests/test_accept_header.sjs new file mode 100644 index 000000000..035c886aa --- /dev/null +++ b/netwerk/test/mochitests/test_accept_header.sjs @@ -0,0 +1,48 @@ +function handleRequest(request, response) {
+ response.setStatusLine(request.httpVersion, "200", "OK");
+
+ if (request.queryString == "worker") {
+ response.setHeader("Content-Type", "application/json", false);
+ response.write("postMessage(42)");
+
+ setState("data", JSON.stringify({type: "worker", accept: request.getHeader("Accept") }));
+ return;
+ }
+
+ if (request.queryString == "image") {
+ // A 1x1 PNG image.
+ // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
+ const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
+ "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");
+
+ response.setHeader("Content-Type", "image/png", false);
+ response.write(IMAGE);
+
+ setState("data", JSON.stringify({type: "image", accept: request.getHeader("Accept") }));
+ return;
+ }
+
+ if (request.queryString == "style") {
+ response.setHeader("Content-Type", "text/css", false);
+ response.write("");
+
+ setState("data", JSON.stringify({type: "style", accept: request.getHeader("Accept") }));
+ return;
+ }
+
+ if (request.queryString == "iframe") {
+ response.setHeader("Content-Type", "text/html", false);
+ response.write("<h1>Hello world!</h1>");
+
+ setState("data", JSON.stringify({type: "iframe", accept: request.getHeader("Accept") }));
+ return;
+ }
+
+ if (request.queryString == "get") {
+ response.setHeader("Content-Type", "text/javascript", false);
+ response.write(getState("data"));
+
+ setState("data", "");
+ return;
+ }
+}
diff --git a/netwerk/test/unit/test_be_conservative.js b/netwerk/test/unit/test_be_conservative.js index 2c6ac46ad..36b6d3b90 100644 --- a/netwerk/test/unit/test_be_conservative.js +++ b/netwerk/test/unit/test_be_conservative.js @@ -140,7 +140,6 @@ function startServer(cert, minServerVersion, maxServerVersion) { tlsServer.init(-1, true, -1); tlsServer.serverCert = cert; tlsServer.setVersionRange(minServerVersion, maxServerVersion); - tlsServer.setSessionCache(false); tlsServer.setSessionTickets(false); tlsServer.asyncListen(new ServerSocketListener()); return tlsServer; diff --git a/netwerk/test/unit/test_bug1064258.js b/netwerk/test/unit/test_bug1064258.js index 3f76837ae..da982c2d6 100644 --- a/netwerk/test/unit/test_bug1064258.js +++ b/netwerk/test/unit/test_bug1064258.js @@ -133,7 +133,7 @@ function cacheCheck2(status, entry) do_check_eq(entry.dataSize, 0); try { do_check_neq(entry.getMetaDataElement("response-head"), null); - do_check_true(entry.getMetaDataElement("response-head").match('Etag: testetag')); + do_check_true(entry.getMetaDataElement("response-head").match('etag: testetag')); } catch (ex) { do_throw("Missing response head"); diff --git a/netwerk/test/unit/test_original_sent_received_head.js b/netwerk/test/unit/test_original_sent_received_head.js index c4d02d5d2..d668abf59 100644 --- a/netwerk/test/unit/test_original_sent_received_head.js +++ b/netwerk/test/unit/test_original_sent_received_head.js @@ -114,11 +114,11 @@ function checkResponse(request, data, context) { var locationHeaderFound = 0; request.visitResponseHeaders({ visitHeader: function visit(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { linkHeaderFound++; do_check_eq(aValue, "value1, value2"); } - if (aName == "Location") { + if (aName == "location") { locationHeaderFound++; do_check_eq(aValue, "loc"); } @@ -132,7 +132,7 @@ function checkResponse(request, data, context) { var locationOrgHeaderFound = 0; request.visitOriginalResponseHeaders({ visitHeader: function visitOrg(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { if (linkOrgHeaderFound == 0) { do_check_eq(aValue, ""); } else if (linkOrgHeaderFound == 1 ) { @@ -142,7 +142,7 @@ function checkResponse(request, data, context) { } linkOrgHeaderFound++; } - if (aName == "Location") { + if (aName == "location") { locationOrgHeaderFound++; do_check_eq(aValue, "loc"); } @@ -160,10 +160,10 @@ function checkResponse(request, data, context) { var locationHeaderFound2 = 0; request.visitResponseHeaders({ visitHeader: function visit(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { linkHeaderFound2 = true; } - if (aName == "Location") { + if (aName == "location") { locationHeaderFound2 = true; } } @@ -176,7 +176,7 @@ function checkResponse(request, data, context) { var locationOrgHeaderFound2 = 0; request.visitOriginalResponseHeaders({ visitHeader: function visitOrg(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { if (linkOrgHeaderFound2 == 0) { do_check_eq(aValue, ""); } else if (linkOrgHeaderFound2 == 1 ) { @@ -186,7 +186,7 @@ function checkResponse(request, data, context) { } linkOrgHeaderFound2++; } - if (aName == "Location") { + if (aName == "location") { locationOrgHeaderFound2++; do_check_eq(aValue, "loc"); } @@ -199,7 +199,7 @@ function checkResponse(request, data, context) { if (dbg) { print("============== Test GetResponseHeader"); } var linkOrgHeaderFound3 = 0; - request.getOriginalResponseHeader("Link",{ + request.getOriginalResponseHeader("link",{ visitHeader: function visitOrg(aName, aValue) { if (linkOrgHeaderFound3 == 0) { do_check_eq(aValue, ""); diff --git a/netwerk/test/unit/test_tls_server.js b/netwerk/test/unit/test_tls_server.js index d805359c7..12154a27f 100644 --- a/netwerk/test/unit/test_tls_server.js +++ b/netwerk/test/unit/test_tls_server.js @@ -90,7 +90,6 @@ function startServer(cert, expectingPeerCert, clientCertificateConfig, onStopListening: function() {} }; - tlsServer.setSessionCache(false); tlsServer.setSessionTickets(false); tlsServer.setRequestClientCertificate(clientCertificateConfig); diff --git a/netwerk/test/unit/test_tls_server_multiple_clients.js b/netwerk/test/unit/test_tls_server_multiple_clients.js index b63c0189b..74b814e9c 100644 --- a/netwerk/test/unit/test_tls_server_multiple_clients.js +++ b/netwerk/test/unit/test_tls_server_multiple_clients.js @@ -67,7 +67,6 @@ function startServer(cert) { onStopListening: function() {} }; - tlsServer.setSessionCache(true); tlsServer.setSessionTickets(false); tlsServer.asyncListen(listener); |