Skip to content

Commit

Permalink
Refactor out AlwaysAccessNetwork
Browse files Browse the repository at this point in the history
This CL refactors out AlwaysAccessNetwork function and puts it to Blink's
public API.

Bug: 860403
Change-Id: I42a600fd822ef8488b78ac0b16860da40896ba9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2281544
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#786735}
  • Loading branch information
Minggang Wang authored and Commit Bot committed Jul 9, 2020
1 parent b61e162 commit 187e663
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
19 changes: 3 additions & 16 deletions content/renderer/loader/resource_load_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,14 @@
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/loader/network_utils.h"
#include "third_party/blink/public/common/loader/resource_type_util.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"

namespace content {

namespace {

// Returns true if the headers indicate that this resource should always be
// revalidated or not cached.
bool AlwaysAccessNetwork(
const scoped_refptr<net::HttpResponseHeaders>& headers) {
if (!headers)
return false;

// RFC 2616, section 14.9.
return headers->HasHeaderValue("cache-control", "no-cache") ||
headers->HasHeaderValue("cache-control", "no-store") ||
headers->HasHeaderValue("pragma", "no-cache") ||
headers->HasHeaderValue("vary", "*");
}

#if defined(OS_ANDROID)
void UpdateUserGestureCarryoverInfo(int render_frame_id) {
RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(render_frame_id);
Expand Down Expand Up @@ -137,7 +124,7 @@ void NotifyResourceRedirectReceived(
net_redirect_info->network_info->network_accessed =
redirect_response->network_accessed;
net_redirect_info->network_info->always_access_network =
AlwaysAccessNetwork(redirect_response->headers);
blink::AlwaysAccessNetwork(redirect_response->headers);
net_redirect_info->network_info->remote_endpoint =
redirect_response->remote_endpoint;
resource_load_info->redirect_info_chain.push_back(
Expand Down Expand Up @@ -167,7 +154,7 @@ void NotifyResourceResponseReceived(
resource_load_info->network_info->network_accessed =
response_head->network_accessed;
resource_load_info->network_info->always_access_network =
AlwaysAccessNetwork(response_head->headers);
blink::AlwaysAccessNetwork(response_head->headers);
resource_load_info->network_info->remote_endpoint =
response_head->remote_endpoint;

Expand Down
1 change: 1 addition & 0 deletions third_party/blink/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jumbo_source_set("common") {
"input/web_touch_event.cc",
"loader/mime_sniffing_throttle.cc",
"loader/mime_sniffing_url_loader.cc",
"loader/network_utils.cc",
"loader/resource_type_util.cc",
"loader/throttling_url_loader.cc",
"loader/url_loader_factory_bundle.cc",
Expand Down
21 changes: 21 additions & 0 deletions third_party/blink/common/loader/network_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/public/common/loader/network_utils.h"

namespace blink {

bool AlwaysAccessNetwork(
const scoped_refptr<net::HttpResponseHeaders>& headers) {
if (!headers)
return false;

// RFC 2616, section 14.9.
return headers->HasHeaderValue("cache-control", "no-cache") ||
headers->HasHeaderValue("cache-control", "no-store") ||
headers->HasHeaderValue("pragma", "no-cache") ||
headers->HasHeaderValue("vary", "*");
}

} // namespace blink
1 change: 1 addition & 0 deletions third_party/blink/public/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ source_set("headers") {
"loader/loading_behavior_flag.h",
"loader/mime_sniffing_throttle.h",
"loader/mime_sniffing_url_loader.h",
"loader/network_utils.h",
"loader/resource_type_util.h",
"loader/url_loader_factory_bundle.h",
"loader/url_loader_factory_bundle_mojom_traits.h",
Expand Down
21 changes: 21 additions & 0 deletions third_party/blink/public/common/loader/network_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_LOADER_NETWORK_UTILS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_LOADER_NETWORK_UTILS_H_

#include "base/memory/scoped_refptr.h"
#include "net/http/http_response_headers.h"
#include "third_party/blink/public/common/common_export.h"

namespace blink {

// Returns true if the headers indicate that this resource should always be
// revalidated or not cached.
BLINK_COMMON_EXPORT bool AlwaysAccessNetwork(
const scoped_refptr<net::HttpResponseHeaders>& headers);

} // namespace blink

#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_LOADER_NETWORK_UTILS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/network_utils.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_response.h"
Expand All @@ -20,26 +21,6 @@
#include "third_party/blink/renderer/platform/loader/fetch/script_cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/worker_main_script_loader_client.h"

namespace {

// TODO(minggang): Move this to a common place where we could share it outside
// the Blink.
// Returns true if the headers indicate that this resource should
// always be revalidated or not cached.
bool AlwaysAccessNetwork(
const scoped_refptr<net::HttpResponseHeaders>& headers) {
if (!headers)
return false;

// RFC 2616, section 14.9.
return headers->HasHeaderValue("cache-control", "no-cache") ||
headers->HasHeaderValue("cache-control", "no-store") ||
headers->HasHeaderValue("pragma", "no-cache") ||
headers->HasHeaderValue("vary", "*");
}

} // namespace

namespace blink {

void WorkerMainScriptLoader::Start(
Expand Down

0 comments on commit 187e663

Please sign in to comment.