mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1753025 - Adding debugging log for FetchSerivce/FetchInstance. r=dom-worker-reviewers,jesup
Depends on D137594 Differential Revision: https://phabricator.services.mozilla.com/D137599
This commit is contained in:
parent
a319862300
commit
7e7901fca2
19
dom/fetch/FetchLog.h
Normal file
19
dom/fetch/FetchLog.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _mozilla_dom_FetchLog_h
|
||||
#define _mozilla_dom_FetchLog_h
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
extern mozilla::LazyLogModule gFetchLog;
|
||||
|
||||
#define FETCH_LOG(args) MOZ_LOG(gFetchLog, LogLevel::Debug, args)
|
||||
|
||||
} // namespace mozilla::dom
|
||||
#endif
|
@ -4,6 +4,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FetchLog.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsILoadInfo.h"
|
||||
#include "nsIPrincipal.h"
|
||||
@ -22,6 +23,8 @@
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
mozilla::LazyLogModule gFetchLog("Fetch");
|
||||
|
||||
// FetchInstance
|
||||
|
||||
FetchService::FetchInstance::FetchInstance(SafeRefPtr<InternalRequest> aRequest)
|
||||
@ -35,6 +38,8 @@ nsresult FetchService::FetchInstance::Initialize(nsIChannel* aChannel) {
|
||||
|
||||
// Get needed information for FetchDriver from passed-in channel.
|
||||
if (aChannel) {
|
||||
FETCH_LOG(("FetchInstance::Initialize [%p] aChannel[%p]", this, aChannel));
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
MOZ_ASSERT(loadInfo);
|
||||
@ -95,6 +100,13 @@ RefPtr<FetchServiceResponsePromise> FetchService::FetchInstance::Fetch() {
|
||||
MOZ_ASSERT(mPrincipal);
|
||||
MOZ_ASSERT(mLoadGroup);
|
||||
|
||||
nsAutoCString principalSpec;
|
||||
MOZ_ALWAYS_SUCCEEDS(mPrincipal->GetAsciiSpec(principalSpec));
|
||||
nsAutoCString requestURL;
|
||||
mRequest->GetURL(requestURL);
|
||||
FETCH_LOG(("FetchInstance::Fetch [%p], mRequest URL: %s mPrincipal: %s", this,
|
||||
requestURL.BeginReading(), principalSpec.BeginReading()));
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Create a FetchDriver instance
|
||||
@ -115,6 +127,8 @@ RefPtr<FetchServiceResponsePromise> FetchService::FetchInstance::Fetch() {
|
||||
// FetchService::CancelFetch() to abort the running fetch.
|
||||
rv = mFetchDriver->Fetch(nullptr, this);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
FETCH_LOG(
|
||||
("FetchInstance::Fetch FetchDriver::Fetch failed(0x%X)", (uint32_t)rv));
|
||||
return FetchServiceResponsePromise::CreateAndResolve(
|
||||
InternalResponse::NetworkError(rv), __func__);
|
||||
}
|
||||
@ -126,6 +140,8 @@ void FetchService::FetchInstance::Cancel() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
FETCH_LOG(("FetchInstance::Cancel() [%p]", this));
|
||||
|
||||
if (mFetchDriver) {
|
||||
mFetchDriver->RunAbortAlgorithm();
|
||||
}
|
||||
@ -144,6 +160,7 @@ void FetchService::FetchInstance::OnResponseEnd(
|
||||
|
||||
void FetchService::FetchInstance::OnResponseAvailableInternal(
|
||||
SafeRefPtr<InternalResponse> aResponse) {
|
||||
FETCH_LOG(("FetchInstance::OnResponseAvailableInternal [%p]", this));
|
||||
if (!mResponsePromiseHolder.IsEmpty()) {
|
||||
// Remove the FetchInstance from FetchInstanceTable
|
||||
RefPtr<FetchServiceResponsePromise> responsePromise =
|
||||
@ -153,6 +170,10 @@ void FetchService::FetchInstance::OnResponseAvailableInternal(
|
||||
auto entry = fetchService->mFetchInstanceTable.Lookup(responsePromise);
|
||||
MOZ_ASSERT(entry);
|
||||
entry.Remove();
|
||||
FETCH_LOG(
|
||||
("FetchInstance::OnResponseAvailableInternal entry of "
|
||||
"responsePromise[%p] is removed",
|
||||
responsePromise.get()));
|
||||
}
|
||||
// Resolve the FetchServiceResponsePromise
|
||||
mResponsePromiseHolder.ResolveIfExists(std::move(aResponse), __func__);
|
||||
@ -201,6 +222,9 @@ RefPtr<FetchServiceResponsePromise> FetchService::Fetch(
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
FETCH_LOG(("FetchService::Fetch aRequest[%p], aChannel[%p]",
|
||||
aRequest.unsafeGetRawPtr(), aChannel));
|
||||
|
||||
// Create FetchInstance
|
||||
RefPtr<FetchInstance> fetch = MakeRefPtr<FetchInstance>(aRequest.clonePtr());
|
||||
|
||||
@ -223,8 +247,12 @@ RefPtr<FetchServiceResponsePromise> FetchService::Fetch(
|
||||
entry.Insert(fetch);
|
||||
return true;
|
||||
})) {
|
||||
FETCH_LOG(("FetchService::Fetch entry of responsePromise[%p] exists",
|
||||
responsePromise.get()));
|
||||
return NetworkErrorResponse(NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
FETCH_LOG(("FetchService::Fetch responsePromise[%p], fetchInstance[%p]",
|
||||
responsePromise.get(), fetch.get()));
|
||||
}
|
||||
return responsePromise;
|
||||
}
|
||||
@ -234,11 +262,15 @@ void FetchService::CancelFetch(
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aResponsePromise);
|
||||
FETCH_LOG(("FetchService::CancelFetch aResponsePromise[%p]",
|
||||
aResponsePromise.get()));
|
||||
|
||||
auto entry = mFetchInstanceTable.Lookup(aResponsePromise);
|
||||
if (entry) {
|
||||
entry.Data()->Cancel();
|
||||
entry.Remove();
|
||||
FETCH_LOG(("FetchService::CancelFetch aResponsePromise[%p] is removed",
|
||||
aResponsePromise.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user