Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp

Issue 2701753003: [WIP] off-main-thread loading
Patch Set: small fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp
index 8a530c15fdc46d0dc797a2436d0b8655b7905526..8637a0b1b8f0c845fe1c3a300a3b06ec4c219311 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp
@@ -574,14 +574,13 @@ void InspectorNetworkAgent::shouldBlockRequest(const ResourceRequest& request,
}
void InspectorNetworkAgent::didBlockRequest(
- LocalFrame* frame,
const ResourceRequest& request,
DocumentLoader* loader,
const FetchInitiatorInfo& initiatorInfo,
ResourceRequestBlockedReason reason) {
unsigned long identifier = createUniqueIdentifier();
- willSendRequestInternal(frame, identifier, loader, request,
- ResourceResponse(), initiatorInfo);
+ willSendRequestInternal(identifier, loader, request, ResourceResponse(),
+ initiatorInfo);
String requestId = IdentifiersFactory::requestId(identifier);
String protocolReason = buildBlockedReason(reason);
@@ -601,14 +600,13 @@ void InspectorNetworkAgent::didChangeResourcePriority(
}
void InspectorNetworkAgent::willSendRequestInternal(
- LocalFrame* frame,
unsigned long identifier,
DocumentLoader* loader,
const ResourceRequest& request,
const ResourceResponse& redirectResponse,
const FetchInitiatorInfo& initiatorInfo) {
String requestId = IdentifiersFactory::requestId(identifier);
- String loaderId = IdentifiersFactory::loaderId(loader);
+ String loaderId = loader ? IdentifiersFactory::loaderId(loader) : "";
m_resourcesData->resourceCreated(requestId, loaderId, request.url());
InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource;
@@ -619,12 +617,13 @@ void InspectorNetworkAgent::willSendRequestInternal(
type = InspectorPageAgent::DocumentResource;
m_resourcesData->setResourceType(requestId, type);
}
-
- String frameId =
- loader->frame() ? IdentifiersFactory::frameId(loader->frame()) : "";
+ String frameId = loader && loader->frame()
+ ? IdentifiersFactory::frameId(loader->frame())
+ : "";
std::unique_ptr<protocol::Network::Initiator> initiatorObject =
- buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0,
- initiatorInfo);
+ buildInitiatorObject(
+ loader && loader->frame() ? loader->frame()->document() : 0,
+ initiatorInfo);
if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
FrameNavigationInitiatorMap::iterator it =
m_frameNavigationInitiatorMap.find(frameId);
@@ -635,8 +634,11 @@ void InspectorNetworkAgent::willSendRequestInternal(
std::unique_ptr<protocol::Network::Request> requestInfo(
buildObjectForResourceRequest(request));
- requestInfo->setMixedContentType(mixedContentTypeForContextType(
- MixedContentChecker::contextTypeForInspector(frame, request)));
+ if (loader) {
+ requestInfo->setMixedContentType(mixedContentTypeForContextType(
+ MixedContentChecker::contextTypeForInspector(loader->frame(),
+ request)));
+ }
requestInfo->setReferrerPolicy(referrerPolicy(request.getReferrerPolicy()));
if (initiatorInfo.isLinkPreload)
@@ -645,15 +647,15 @@ void InspectorNetworkAgent::willSendRequestInternal(
String resourceType = InspectorPageAgent::resourceTypeJson(type);
frontend()->requestWillBeSent(
requestId, frameId, loaderId,
- urlWithoutFragment(loader->url()).getString(), std::move(requestInfo),
- monotonicallyIncreasingTime(), currentTime(), std::move(initiatorObject),
+ loader ? urlWithoutFragment(loader->url()).getString() : "",
+ std::move(requestInfo), monotonicallyIncreasingTime(), currentTime(),
+ std::move(initiatorObject),
buildObjectForResourceResponse(redirectResponse), resourceType);
if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async())
frontend()->flush();
}
void InspectorNetworkAgent::willSendRequest(
- LocalFrame* frame,
unsigned long identifier,
DocumentLoader* loader,
ResourceRequest& request,
@@ -693,7 +695,7 @@ void InspectorNetworkAgent::willSendRequest(
if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false))
request.setServiceWorkerMode(WebURLRequest::ServiceWorkerMode::None);
- willSendRequestInternal(frame, identifier, loader, request, redirectResponse,
+ willSendRequestInternal(identifier, loader, request, redirectResponse,
initiatorInfo);
if (!m_hostId.isEmpty())
@@ -711,7 +713,6 @@ void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) {
}
void InspectorNetworkAgent::didReceiveResourceResponse(
- LocalFrame* frame,
unsigned long identifier,
DocumentLoader* loader,
const ResourceResponse& response,
@@ -747,7 +748,9 @@ void InspectorNetworkAgent::didReceiveResourceResponse(
// doesn't affect Resource lifetime.
if (cachedResource)
m_resourcesData->addResource(requestId, cachedResource);
- String frameId = IdentifiersFactory::frameId(frame);
+ String frameId = loader && loader->frame()
+ ? IdentifiersFactory::frameId(loader->frame())
+ : "";
String loaderId = loader ? IdentifiersFactory::loaderId(loader) : "";
m_resourcesData->responseReceived(requestId, frameId, response);
m_resourcesData->setResourceType(requestId, type);
@@ -770,15 +773,15 @@ void InspectorNetworkAgent::didReceiveResourceResponse(
// following didReceiveResponse as there will be no calls to didReceiveData
// from the network stack.
if (isNotModified && cachedResource && cachedResource->encodedSize())
- didReceiveData(frame, identifier, 0, cachedResource->encodedSize());
+ didReceiveData(identifier, loader, 0, cachedResource->encodedSize());
}
static bool isErrorStatusCode(int statusCode) {
return statusCode >= 400;
}
-void InspectorNetworkAgent::didReceiveData(LocalFrame*,
- unsigned long identifier,
+void InspectorNetworkAgent::didReceiveData(unsigned long identifier,
+ DocumentLoader* loader,
const char* data,
int dataLength) {
String requestId = IdentifiersFactory::requestId(identifier);
@@ -800,15 +803,14 @@ void InspectorNetworkAgent::didReceiveData(LocalFrame*,
}
void InspectorNetworkAgent::didReceiveEncodedDataLength(
- LocalFrame*,
unsigned long identifier,
int encodedDataLength) {
String requestId = IdentifiersFactory::requestId(identifier);
m_resourcesData->addPendingEncodedDataLength(requestId, encodedDataLength);
}
-void InspectorNetworkAgent::didFinishLoading(LocalFrame*,
- unsigned long identifier,
+void InspectorNetworkAgent::didFinishLoading(unsigned long identifier,
+ DocumentLoader*,
double monotonicFinishTime,
int64_t encodedDataLength,
int64_t decodedBodyLength) {
@@ -845,8 +847,8 @@ void InspectorNetworkAgent::didReceiveCORSRedirectResponse(
const ResourceResponse& response,
Resource* resource) {
// Update the response and finish loading
- didReceiveResourceResponse(frame, identifier, loader, response, resource);
- didFinishLoading(frame, identifier, 0,
+ didReceiveResourceResponse(identifier, loader, response, resource);
+ didFinishLoading(identifier, loader, 0,
WebURLLoaderClient::kUnknownEncodedDataLength, 0);
}
@@ -932,9 +934,11 @@ void InspectorNetworkAgent::willLoadXHR(XMLHttpRequest* xhr,
void InspectorNetworkAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr) {
if (!m_replayXHRs.contains(xhr))
return;
+ // TODO(horo): |m_removeFinishedReplayXHRTimer| is null on workers.
+ DCHECK(m_removeFinishedReplayXHRTimer);
m_replayXHRsToBeDeleted.insert(xhr);
m_replayXHRs.erase(xhr);
- m_removeFinishedReplayXHRTimer.startOneShot(0, BLINK_FROM_HERE);
+ m_removeFinishedReplayXHRTimer->startOneShot(0, BLINK_FROM_HERE);
}
void InspectorNetworkAgent::didFailXHRLoading(ExecutionContext* context,
@@ -1423,7 +1427,7 @@ Response InspectorNetworkAgent::setCacheDisabled(bool cacheDisabled) {
// We should extract network cache state into a global entity which can be
// queried from FrameLoader and other places.
m_state->setBoolean(NetworkAgentState::cacheDisabled, cacheDisabled);
- if (cacheDisabled)
+ if (cacheDisabled && isMainThread())
memoryCache()->evictResources();
return Response::OK();
}
@@ -1463,7 +1467,8 @@ void InspectorNetworkAgent::didCommitLoad(LocalFrame* frame,
if (loader->frame() != m_inspectedFrames->root())
return;
- if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false))
+ if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false) &&
+ isMainThread())
memoryCache()->evictResources(MemoryCache::DoNotEvictUnusedPreloads);
m_resourcesData->clear(IdentifiersFactory::loaderId(loader));
@@ -1513,9 +1518,10 @@ bool InspectorNetworkAgent::fetchResourceContent(Document* document,
bool* base64Encoded) {
// First try to fetch content from the cached resource.
Resource* cachedResource = document->fetcher()->cachedResource(url);
- if (!cachedResource)
+ if (!cachedResource && isMainThread()) {
cachedResource = memoryCache()->resourceForURL(
url, document->fetcher()->getCacheIdentifier());
+ }
if (cachedResource && InspectorPageAgent::cachedResourceContent(
cachedResource, content, base64Encoded))
return true;
@@ -1547,10 +1553,13 @@ InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspectedFrames)
maximumResourceBufferSize)),
m_pendingRequest(nullptr),
m_removeFinishedReplayXHRTimer(
- TaskRunnerHelper::get(TaskType::UnspecedLoading,
- inspectedFrames->root()),
- this,
- &InspectorNetworkAgent::removeFinishedReplayXHRFired) {}
+ inspectedFrames
+ ? new TaskRunnerTimer<InspectorNetworkAgent>(
+ TaskRunnerHelper::get(TaskType::UnspecedLoading,
+ inspectedFrames->root()),
+ this,
+ &InspectorNetworkAgent::removeFinishedReplayXHRFired)
+ : nullptr) {}
void InspectorNetworkAgent::shouldForceCORSPreflight(bool* result) {
if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false))

Powered by Google App Engine
This is Rietveld 408576698