Commit 656dfe07 authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

[OnionSoup] Add NotifyUpdateUserGestureCarryoverInfo() to ResourceLoadInfoNotifier interface

Currently, NotifyUpdateUserGestureCarryoverInfo() declared in
resource_load_stats.h is used to update information to determine whether
a user gesture should carryover to future navigations, when a request
is initiated.

This patch adds NotifyUpdateUserGestureCarryoverInfo() into
mojo interface ResourceLoadInfoNotifier for Android only to replace it.
Thus, we could call it inside Blink, which is part of OnionSoup
for loaders.

After this patch, all functions defined in resource_load_stats.h/cc
are removed and resource_load_stats.h/cc are deleted.

Bug: 1110032
Change-Id: I8a8eb6f71b827792332806c97dd4038e4be81ba8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427154
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816583}
parent cc61c1e0
......@@ -91,8 +91,6 @@ target(link_target_type, "renderer") {
"loader/request_extra_data.h",
"loader/resource_dispatcher.cc",
"loader/resource_dispatcher.h",
"loader/resource_load_stats.cc",
"loader/resource_load_stats.h",
"loader/sync_load_context.cc",
"loader/sync_load_context.h",
"loader/sync_load_response.cc",
......
......@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/macros.h"
#include "content/renderer/loader/resource_load_stats.h"
#include "content/renderer/loader/web_url_loader_impl.h"
#include "content/renderer/render_frame_impl.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
......
......@@ -26,7 +26,6 @@
#include "content/public/renderer/request_peer.h"
#include "content/public/renderer/resource_dispatcher_delegate.h"
#include "content/renderer/loader/request_extra_data.h"
#include "content/renderer/loader/resource_load_stats.h"
#include "content/renderer/loader/sync_load_context.h"
#include "content/renderer/loader/sync_load_response.h"
#include "content/renderer/loader/url_loader_client_impl.h"
......@@ -518,7 +517,7 @@ int ResourceDispatcher::StartAsync(
DCHECK(!(request->is_main_frame &&
blink::IsRequestDestinationFrame(request->destination)));
if (request->has_user_gesture) {
NotifyUpdateUserGestureCarryoverInfo(request->render_frame_id);
resource_load_info_notifier_wrapper->NotifyUpdateUserGestureCarryoverInfo();
}
#endif
......
// Copyright 2019 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 "content/renderer/loader/resource_load_stats.h"
#include "base/bind.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_thread_impl.h"
namespace content {
namespace {
#if defined(OS_ANDROID)
void UpdateUserGestureCarryoverInfo(int render_frame_id) {
RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(render_frame_id);
if (frame)
frame->GetFrameHost()->UpdateUserGestureCarryoverInfo();
}
#endif
} // namespace
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo(int render_frame_id) {
auto task_runner = RenderThreadImpl::DeprecatedGetMainTaskRunner();
if (!task_runner)
return;
if (task_runner->BelongsToCurrentThread()) {
UpdateUserGestureCarryoverInfo(render_frame_id);
return;
}
task_runner->PostTask(
FROM_HERE,
base::BindOnce(UpdateUserGestureCarryoverInfo, render_frame_id));
}
#endif
} // namespace content
// Copyright 2019 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 CONTENT_RENDERER_LOADER_RESOURCE_LOAD_STATS_H_
#define CONTENT_RENDERER_LOADER_RESOURCE_LOAD_STATS_H_
#include "build/build_config.h"
namespace content {
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo(int render_frame_id);
#endif
} // namespace content
#endif // CONTENT_RENDERER_LOADER_RESOURCE_LOAD_STATS_H_
......@@ -3034,6 +3034,12 @@ void RenderFrameImpl::AddAutoplayFlags(const url::Origin& origin,
// blink::mojom::ResourceLoadInfoNotifier implementation
// --------------------------
#if defined(OS_ANDROID)
void RenderFrameImpl::NotifyUpdateUserGestureCarryoverInfo() {
GetFrameHost()->UpdateUserGestureCarryoverInfo();
}
#endif
void RenderFrameImpl::NotifyResourceRedirectReceived(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr redirect_response) {}
......
......@@ -460,6 +460,9 @@ class CONTENT_EXPORT RenderFrameImpl
const int32_t flags) override;
// blink::mojom::ResourceLoadInfoNotifier implementation:
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo() override;
#endif
void NotifyResourceRedirectReceived(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr redirect_response) override;
......
......@@ -12,6 +12,11 @@ import "url/mojom/url.mojom";
// This interface is used to notify loading stats of the resource.
interface ResourceLoadInfoNotifier {
// Called to update information to determine whether a user gesture should
// carryover to future navigations, when a request is initiated.
[EnableIf=is_android]
NotifyUpdateUserGestureCarryoverInfo();
// Called to notify the request has been redirected.
NotifyResourceRedirectReceived(network.mojom.URLRequestRedirectInfo redirect_info,
network.mojom.URLResponseHead redirect_response);
......
......@@ -34,14 +34,17 @@ class WeakWrapperResourceLoadInfoNotifier;
class BLINK_PLATFORM_EXPORT ResourceLoadInfoNotifierWrapper {
public:
explicit ResourceLoadInfoNotifierWrapper(
base::WeakPtr<blink::WeakWrapperResourceLoadInfoNotifier>
base::WeakPtr<WeakWrapperResourceLoadInfoNotifier>
weak_wrapper_resource_load_info_notifier);
ResourceLoadInfoNotifierWrapper(
base::WeakPtr<blink::WeakWrapperResourceLoadInfoNotifier>
base::WeakPtr<WeakWrapperResourceLoadInfoNotifier>
weak_wrapper_resource_load_info_notifier,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~ResourceLoadInfoNotifierWrapper();
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo();
#endif
void NotifyResourceLoadInitiated(
int64_t request_id,
const GURL& request_url,
......@@ -65,13 +68,13 @@ class BLINK_PLATFORM_EXPORT ResourceLoadInfoNotifierWrapper {
// |weak_wrapper_resource_load_info_notifier_| should only be dereferenced on
// the same thread as |task_runner_| runs on.
base::WeakPtr<blink::WeakWrapperResourceLoadInfoNotifier>
base::WeakPtr<WeakWrapperResourceLoadInfoNotifier>
weak_wrapper_resource_load_info_notifier_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// This struct holds the loading stats passed to
// |weak_wrapper_resource_load_info_notifier_|.
blink::mojom::ResourceLoadInfoPtr resource_load_info_;
mojom::ResourceLoadInfoPtr resource_load_info_;
};
} // namespace blink
......
......@@ -7,6 +7,7 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "third_party/blink/public/common/loader/previews_state.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h"
......@@ -26,6 +27,9 @@ class BLINK_PLATFORM_EXPORT WeakWrapperResourceLoadInfoNotifier
// blink::mojom::ResourceLoadInfoNotifier overrides, these methods should be
// called from the same thread.
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo() override;
#endif
void NotifyResourceRedirectReceived(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr redirect_response) override;
......
......@@ -20,14 +20,14 @@
namespace blink {
ResourceLoadInfoNotifierWrapper::ResourceLoadInfoNotifierWrapper(
base::WeakPtr<blink::WeakWrapperResourceLoadInfoNotifier>
base::WeakPtr<WeakWrapperResourceLoadInfoNotifier>
weak_wrapper_resource_load_info_notifier)
: ResourceLoadInfoNotifierWrapper(
std::move(weak_wrapper_resource_load_info_notifier),
base::ThreadTaskRunnerHandle::Get()) {}
ResourceLoadInfoNotifierWrapper::ResourceLoadInfoNotifierWrapper(
base::WeakPtr<blink::WeakWrapperResourceLoadInfoNotifier>
base::WeakPtr<WeakWrapperResourceLoadInfoNotifier>
weak_wrapper_resource_load_info_notifier,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: weak_wrapper_resource_load_info_notifier_(
......@@ -39,6 +39,23 @@ ResourceLoadInfoNotifierWrapper::ResourceLoadInfoNotifierWrapper(
ResourceLoadInfoNotifierWrapper::~ResourceLoadInfoNotifierWrapper() = default;
#if defined(OS_ANDROID)
void ResourceLoadInfoNotifierWrapper::NotifyUpdateUserGestureCarryoverInfo() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (task_runner_->BelongsToCurrentThread()) {
if (weak_wrapper_resource_load_info_notifier_) {
weak_wrapper_resource_load_info_notifier_
->NotifyUpdateUserGestureCarryoverInfo();
}
return;
}
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&mojom::ResourceLoadInfoNotifier::
NotifyUpdateUserGestureCarryoverInfo,
weak_wrapper_resource_load_info_notifier_));
}
#endif
void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadInitiated(
int64_t request_id,
const GURL& request_url,
......@@ -51,14 +68,14 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadInitiated(
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(!resource_load_info_);
resource_load_info_ = blink::mojom::ResourceLoadInfo::New();
resource_load_info_ = mojom::ResourceLoadInfo::New();
resource_load_info_->method = http_method;
resource_load_info_->original_url = request_url;
resource_load_info_->final_url = request_url;
resource_load_info_->request_destination = request_destination;
resource_load_info_->request_id = request_id;
resource_load_info_->referrer = referrer;
resource_load_info_->network_info = blink::mojom::CommonNetworkInfo::New();
resource_load_info_->network_info = mojom::CommonNetworkInfo::New();
resource_load_info_->request_priority = request_priority;
}
......@@ -70,15 +87,14 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceRedirectReceived(
resource_load_info_->final_url = redirect_info.new_url;
resource_load_info_->method = redirect_info.new_method;
resource_load_info_->referrer = GURL(redirect_info.new_referrer);
blink::mojom::RedirectInfoPtr net_redirect_info =
blink::mojom::RedirectInfo::New();
mojom::RedirectInfoPtr net_redirect_info = mojom::RedirectInfo::New();
net_redirect_info->origin_of_new_url =
url::Origin::Create(redirect_info.new_url);
net_redirect_info->network_info = blink::mojom::CommonNetworkInfo::New();
net_redirect_info->network_info = mojom::CommonNetworkInfo::New();
net_redirect_info->network_info->network_accessed =
redirect_response->network_accessed;
net_redirect_info->network_info->always_access_network =
blink::network_utils::AlwaysAccessNetwork(redirect_response->headers);
network_utils::AlwaysAccessNetwork(redirect_response->headers);
net_redirect_info->network_info->remote_endpoint =
redirect_response->remote_endpoint;
resource_load_info_->redirect_info_chain.push_back(
......@@ -107,7 +123,7 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceResponseReceived(
resource_load_info_->network_info->network_accessed =
response_head->network_accessed;
resource_load_info_->network_info->always_access_network =
blink::network_utils::AlwaysAccessNetwork(response_head->headers);
network_utils::AlwaysAccessNetwork(response_head->headers);
resource_load_info_->network_info->remote_endpoint =
response_head->remote_endpoint;
......@@ -128,12 +144,12 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceResponseReceived(
}
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&blink::mojom::ResourceLoadInfoNotifier::
NotifyResourceResponseReceived,
weak_wrapper_resource_load_info_notifier_,
resource_load_info_->request_id,
resource_load_info_->final_url, std::move(response_head),
resource_load_info_->request_destination, previews_state));
base::BindOnce(
&mojom::ResourceLoadInfoNotifier::NotifyResourceResponseReceived,
weak_wrapper_resource_load_info_notifier_,
resource_load_info_->request_id, resource_load_info_->final_url,
std::move(response_head), resource_load_info_->request_destination,
previews_state));
}
void ResourceLoadInfoNotifierWrapper::NotifyResourceTransferSizeUpdated(
......@@ -149,18 +165,18 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceTransferSizeUpdated(
}
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&blink::mojom::ResourceLoadInfoNotifier::
NotifyResourceTransferSizeUpdated,
weak_wrapper_resource_load_info_notifier_,
resource_load_info_->request_id, transfer_size_diff));
base::BindOnce(
&mojom::ResourceLoadInfoNotifier::NotifyResourceTransferSizeUpdated,
weak_wrapper_resource_load_info_notifier_,
resource_load_info_->request_id, transfer_size_diff));
}
void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadCompleted(
const network::URLLoaderCompletionStatus& status) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
blink::RecordLoadHistograms(
url::Origin::Create(resource_load_info_->final_url),
resource_load_info_->request_destination, status.error_code);
RecordLoadHistograms(url::Origin::Create(resource_load_info_->final_url),
resource_load_info_->request_destination,
status.error_code);
resource_load_info_->was_cached = status.exists_in_cache;
resource_load_info_->net_error = status.error_code;
......@@ -177,7 +193,7 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadCompleted(
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&blink::mojom::ResourceLoadInfoNotifier::NotifyResourceLoadCompleted,
&mojom::ResourceLoadInfoNotifier::NotifyResourceLoadCompleted,
weak_wrapper_resource_load_info_notifier_,
std::move(resource_load_info_), status));
}
......@@ -185,9 +201,8 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadCompleted(
void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadCanceled(
int net_error) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
blink::RecordLoadHistograms(
url::Origin::Create(resource_load_info_->final_url),
resource_load_info_->request_destination, net_error);
RecordLoadHistograms(url::Origin::Create(resource_load_info_->final_url),
resource_load_info_->request_destination, net_error);
if (task_runner_->BelongsToCurrentThread()) {
if (weak_wrapper_resource_load_info_notifier_) {
......@@ -199,7 +214,7 @@ void ResourceLoadInfoNotifierWrapper::NotifyResourceLoadCanceled(
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&blink::mojom::ResourceLoadInfoNotifier::NotifyResourceLoadCanceled,
&mojom::ResourceLoadInfoNotifier::NotifyResourceLoadCanceled,
weak_wrapper_resource_load_info_notifier_,
resource_load_info_->request_id));
}
......
......@@ -21,6 +21,14 @@ void WeakWrapperResourceLoadInfoNotifier::NotifyResourceRedirectReceived(
redirect_info, std::move(redirect_response));
}
#if defined(OS_ANDROID)
void WeakWrapperResourceLoadInfoNotifier::
NotifyUpdateUserGestureCarryoverInfo() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
resource_load_info_notifier_->NotifyUpdateUserGestureCarryoverInfo();
}
#endif
void WeakWrapperResourceLoadInfoNotifier::NotifyResourceResponseReceived(
int64_t request_id,
const GURL& final_url,
......
......@@ -6,6 +6,7 @@
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/http/http_util.h"
......@@ -127,6 +128,9 @@ class WorkerMainScriptLoaderTest : public testing::Test {
const FakeResourceLoadInfoNotifier&) = delete;
// blink::mojom::ResourceLoadInfoNotifier overrides.
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo() override {}
#endif
void NotifyResourceRedirectReceived(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr redirect_response) override {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment