Commit cee36dda authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert DocumentCoordinationUnit client to use BrowserInterfaceBroker

This change converts DocumentCoordinationUnit mojom interface
client in components to use BrowserInterfaceBroker.
Since DocumentCoordinationUnit is a WebContentsObserver and a static
helper function is used to register its binder.

Bug: 936482
Change-Id: I146d28c81a39b4f977f53c92b567f6409e727553
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895026Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#716094}
parent ed3da4b7
......@@ -22,6 +22,8 @@
#include "components/dom_distiller/content/common/mojom/distillability_service.mojom.h"
#include "components/dom_distiller/content/common/mojom/distiller_javascript_service.mojom.h"
#include "components/dom_distiller/core/dom_distiller_service.h"
#include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
......@@ -129,6 +131,25 @@ void BindPrerenderCanceler(
prerender_contents->OnPrerenderCancelerReceiver(std::move(receiver));
}
void BindDocumentCoordinationUnit(
content::RenderFrameHost* host,
mojo::PendingReceiver<performance_manager::mojom::DocumentCoordinationUnit>
receiver) {
auto* content = content::WebContents::FromRenderFrameHost(host);
// |content| can be nullable if RenderFrameHost's delegate is not
// WebContents.
if (!content)
return;
auto* helper =
performance_manager::PerformanceManagerTabHelper::FromWebContents(
content);
// This condition is for testing-only. We should handle a bind request after
// PerformanceManagerTabHelper is attached to WebContents.
if (!helper)
return;
return helper->BindDocumentCoordinationUnit(host, std::move(receiver));
}
#if defined(OS_ANDROID)
template <typename Interface>
void ForwardToJavaWebContents(content::RenderFrameHost* frame_host,
......@@ -198,6 +219,9 @@ void PopulateChromeFrameBinders(
map->Add<mojom::PrerenderCanceler>(
base::BindRepeating(&BindPrerenderCanceler));
map->Add<performance_manager::mojom::DocumentCoordinationUnit>(
base::BindRepeating(&BindDocumentCoordinationUnit));
#if defined(OS_ANDROID)
map->Add<blink::mojom::InstalledAppProvider>(base::BindRepeating(
&ForwardToJavaFrame<blink::mojom::InstalledAppProvider>));
......
......@@ -327,13 +327,9 @@ void PerformanceManagerTabHelper::DidUpdateFaviconURL(
PostToGraph(FROM_HERE, &PageNodeImpl::OnFaviconUpdated, page_node_.get());
}
void PerformanceManagerTabHelper::OnInterfaceRequestFromFrame(
void PerformanceManagerTabHelper::BindDocumentCoordinationUnit(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
if (interface_name != mojom::DocumentCoordinationUnit::Name_)
return;
mojo::PendingReceiver<mojom::DocumentCoordinationUnit> receiver) {
// TODO(https://crbug.com/987445): Why else than due to speculative render
// frame hosts would this happen? Is there a race between the RFH creation
// notification and the mojo interface request?
......@@ -354,8 +350,7 @@ void PerformanceManagerTabHelper::OnInterfaceRequestFromFrame(
}
PostToGraph(FROM_HERE, &FrameNodeImpl::Bind, it->second.get(),
mojo::PendingReceiver<mojom::DocumentCoordinationUnit>(
std::move(*interface_pipe)));
std::move(receiver));
}
content::WebContents* PerformanceManagerTabHelper::GetWebContents() const {
......
......@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom-forward.h"
#include "components/performance_manager/web_contents_proxy_impl.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
......@@ -56,15 +57,15 @@ class PerformanceManagerTabHelper
void WebContentsDestroyed() override;
void DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) override;
void OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
// WebContentsProxyImpl overrides.
content::WebContents* GetWebContents() const override;
int64_t LastNavigationId() const override;
void BindDocumentCoordinationUnit(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<mojom::DocumentCoordinationUnit> receiver);
void SetUkmSourceIdForTesting(ukm::SourceId id) { ukm_source_id_ = id; }
// Retrieves the frame node associated with |render_frame_host|.
......
......@@ -219,7 +219,6 @@ const service_manager::Manifest& GetContentBrowserManifest() {
"mojom.ProcessInternalsHandler",
"network.mojom.RestrictedCookieManager",
"blink.mojom.WebSocketConnector",
"performance_manager.mojom.DocumentCoordinationUnit",
"viz.mojom.Gpu"})
.RequireInterfaceFilterCapability_Deprecated(
mojom::kRendererServiceName, "navigation:frame", "browser")
......
......@@ -8170,12 +8170,9 @@ BrowserInterfaceBrokerProxy& Document::GetBrowserInterfaceBroker() {
}
DocumentResourceCoordinator* Document::GetResourceCoordinator() {
if (!resource_coordinator_) {
auto* interface_provider = GetInterfaceProvider();
if (interface_provider) {
resource_coordinator_ =
DocumentResourceCoordinator::MaybeCreate(interface_provider);
}
if (!resource_coordinator_ && GetFrame()) {
resource_coordinator_ =
DocumentResourceCoordinator::MaybeCreate(GetBrowserInterfaceBroker());
}
return resource_coordinator_.get();
}
......
......@@ -7,7 +7,7 @@
#include <memory>
#include "base/memory/ptr_util.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
......@@ -21,16 +21,16 @@ using performance_manager::mojom::InterventionPolicy;
// static
std::unique_ptr<DocumentResourceCoordinator>
DocumentResourceCoordinator::MaybeCreate(
service_manager::InterfaceProvider* interface_provider) {
const BrowserInterfaceBrokerProxy& interface_broker) {
if (!RuntimeEnabledFeatures::PerformanceManagerInstrumentationEnabled())
return nullptr;
return base::WrapUnique(new DocumentResourceCoordinator(interface_provider));
return base::WrapUnique(new DocumentResourceCoordinator(interface_broker));
}
DocumentResourceCoordinator::DocumentResourceCoordinator(
service_manager::InterfaceProvider* interface_provider) {
interface_provider->GetInterface(service_.BindNewPipeAndPassReceiver());
const BrowserInterfaceBrokerProxy& interface_broker) {
interface_broker.GetInterface(service_.BindNewPipeAndPassReceiver());
DCHECK(service_);
}
......
......@@ -13,19 +13,17 @@
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace service_manager {
class InterfaceProvider;
} // namespace service_manager
namespace blink {
class BrowserInterfaceBrokerProxy;
class PLATFORM_EXPORT DocumentResourceCoordinator final {
USING_FAST_MALLOC(DocumentResourceCoordinator);
public:
// Returns nullptr if instrumentation is not enabled.
static std::unique_ptr<DocumentResourceCoordinator> MaybeCreate(
service_manager::InterfaceProvider*);
const BrowserInterfaceBrokerProxy&);
~DocumentResourceCoordinator();
void SetNetworkAlmostIdle();
......@@ -38,7 +36,7 @@ class PLATFORM_EXPORT DocumentResourceCoordinator final {
void OnNonPersistentNotificationCreated();
private:
explicit DocumentResourceCoordinator(service_manager::InterfaceProvider*);
explicit DocumentResourceCoordinator(const BrowserInterfaceBrokerProxy&);
mojo::Remote<performance_manager::mojom::blink::DocumentCoordinationUnit>
service_;
......
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