Commit 9c82d3fa authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert PhishingDetector to new Mojo types

This CL converts PhishingDetectorPtr and
PhishingDetectorRequest to new Mojo types
using Remote, PendingRemote, PendingReceiver,
Receiver, and ReceiverSet.

Bug: 955171
Change-Id: I394157125a31492bbef3d93b6e86f434b45c5408
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816241Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#699261}
parent 98e4cdcd
......@@ -508,7 +508,9 @@ void ClientSideDetectionHost::OnPhishingPreClassificationDone(
DVLOG(1) << "Instruct renderer to start phishing detection for URL: "
<< browse_info_->url;
content::RenderFrameHost* rfh = web_contents()->GetMainFrame();
rfh->GetRemoteInterfaces()->GetInterface(&phishing_detector_);
phishing_detector_.reset();
rfh->GetRemoteInterfaces()->GetInterface(
phishing_detector_.BindNewPipeAndPassReceiver());
phishing_detector_->StartPhishingDetection(
browse_info_->url,
base::BindRepeating(&ClientSideDetectionHost::PhishingDetectionDone,
......
......@@ -18,7 +18,7 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "components/safe_browsing/db/database_manager.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "url/gurl.h"
......@@ -155,7 +155,7 @@ class ClientSideDetectionHost : public content::WebContentsObserver,
// Current host, used to help determine cur_host_redirects_.
std::string cur_host_;
// The currently active message pipe to the renderer PhishingDetector.
mojom::PhishingDetectorPtr phishing_detector_;
mojo::Remote<mojom::PhishingDetector> phishing_detector_;
// Max number of ips we save for each browse
static const size_t kMaxIPsPerBrowse;
......
......@@ -39,6 +39,8 @@
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "ipc/ipc_test_sink.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -205,9 +207,9 @@ class FakePhishingDetector : public mojom::PhishingDetector {
~FakePhishingDetector() override = default;
void BindRequest(mojo::ScopedMessagePipeHandle handle) {
bindings_.AddBinding(this,
mojom::PhishingDetectorRequest(std::move(handle)));
void BindReceiver(mojo::ScopedMessagePipeHandle handle) {
receivers_.Add(this, mojo::PendingReceiver<mojom::PhishingDetector>(
std::move(handle)));
}
// mojom::PhishingDetector
......@@ -241,7 +243,7 @@ class FakePhishingDetector : public mojom::PhishingDetector {
}
private:
mojo::BindingSet<mojom::PhishingDetector> bindings_;
mojo::ReceiverSet<mojom::PhishingDetector> receivers_;
bool phishing_detection_started_ = false;
GURL url_;
......@@ -263,7 +265,7 @@ class ClientSideDetectionHostTestBase : public ChromeRenderViewHostTestHarness {
test_api.SetBinderForName(
mojom::PhishingDetector::Name_,
base::BindRepeating(&FakePhishingDetector::BindRequest,
base::BindRepeating(&FakePhishingDetector::BindReceiver,
base::Unretained(&fake_phishing_detector_)));
}
......
......@@ -105,7 +105,7 @@ PhishingClassifierDelegate::PhishingClassifierDelegate(
SetPhishingScorer(g_phishing_scorer.Get().get());
registry_.AddInterface(
base::BindRepeating(&PhishingClassifierDelegate::PhishingDetectorRequest,
base::BindRepeating(&PhishingClassifierDelegate::PhishingDetectorReceiver,
base::Unretained(this)));
}
......@@ -131,9 +131,9 @@ void PhishingClassifierDelegate::SetPhishingScorer(
MaybeStartClassification();
}
void PhishingClassifierDelegate::PhishingDetectorRequest(
mojom::PhishingDetectorRequest request) {
phishing_detector_bindings_.AddBinding(this, std::move(request));
void PhishingClassifierDelegate::PhishingDetectorReceiver(
mojo::PendingReceiver<mojom::PhishingDetector> receiver) {
phishing_detector_receivers_.Add(this, std::move(receiver));
}
void PhishingClassifierDelegate::OnInterfaceRequestForFrame(
......
......@@ -14,7 +14,8 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_thread_observer.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "ui/base/page_transition_types.h"
......@@ -86,7 +87,8 @@ class PhishingClassifierDelegate : public content::RenderFrameObserver,
CANCEL_CLASSIFICATION_MAX // Always add new values before this one.
};
void PhishingDetectorRequest(mojom::PhishingDetectorRequest request);
void PhishingDetectorReceiver(
mojo::PendingReceiver<mojom::PhishingDetector> receiver);
// Cancels any pending classification and frees the page text.
void CancelPendingClassification(CancelClassificationReason reason);
......@@ -153,7 +155,7 @@ class PhishingClassifierDelegate : public content::RenderFrameObserver,
// The callback from the most recent call to StartPhishingDetection.
StartPhishingDetectionCallback callback_;
mojo::BindingSet<mojom::PhishingDetector> phishing_detector_bindings_;
mojo::ReceiverSet<mojom::PhishingDetector> phishing_detector_receivers_;
service_manager::BinderRegistry registry_;
......
......@@ -19,6 +19,7 @@
#include "components/safe_browsing/proto/csd.pb.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/skia/include/core/SkBitmap.h"
class GURL;
......@@ -257,7 +258,7 @@ class PasswordProtectionRequest : public base::RefCountedThreadSafe<
base::TimeTicks visual_feature_start_time_;
// The Mojo pipe used for extracting DOM features from the renderer.
safe_browsing::mojom::PhishingDetectorPtr phishing_detector_;
mojo::Remote<safe_browsing::mojom::PhishingDetector> phishing_detector_;
// When we start extracting DOM features. Used to compute the duration of DOM
// feature extraction, which is logged at
......
......@@ -560,8 +560,8 @@ bool PasswordProtectionService::IsSupportedPasswordTypeForModalWarning(
#if BUILDFLAG(FULL_SAFE_BROWSING)
void PasswordProtectionService::GetPhishingDetector(
service_manager::InterfaceProvider* provider,
mojom::PhishingDetectorPtr* phishing_detector) {
provider->GetInterface(phishing_detector);
mojo::Remote<mojom::PhishingDetector>* phishing_detector) {
provider->GetInterface(phishing_detector->BindNewPipeAndPassReceiver());
}
#endif
......
......@@ -28,6 +28,7 @@
#include "components/safe_browsing/proto/csd.pb.h"
#include "components/sessions/core/session_id.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
......@@ -411,7 +412,7 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
// |provider|.
virtual void GetPhishingDetector(
service_manager::InterfaceProvider* provider,
mojom::PhishingDetectorPtr* phishing_detector);
mojo::Remote<mojom::PhishingDetector>* phishing_detector);
#endif
// The username of the account which password has been reused on. It is only
......
......@@ -34,6 +34,8 @@
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
......@@ -81,11 +83,12 @@ class MockSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager {
class TestPhishingDetector : public mojom::PhishingDetector {
public:
TestPhishingDetector() : should_timeout_(false), binding_(this) {}
TestPhishingDetector() : should_timeout_(false) {}
~TestPhishingDetector() override {}
void Bind(mojo::ScopedMessagePipeHandle handle) {
binding_.Bind(mojom::PhishingDetectorRequest(std::move(handle)));
receiver_.Bind(
mojo::PendingReceiver<mojom::PhishingDetector>(std::move(handle)));
}
void StartPhishingDetection(
......@@ -110,7 +113,7 @@ class TestPhishingDetector : public mojom::PhishingDetector {
private:
bool should_timeout_;
std::vector<StartPhishingDetectionCallback> deferred_callbacks_;
mojo::Binding<mojom::PhishingDetector> binding_;
mojo::Receiver<mojom::PhishingDetector> receiver_{this};
DISALLOW_COPY_AND_ASSIGN(TestPhishingDetector);
};
......@@ -153,13 +156,13 @@ class TestPasswordProtectionService : public MockPasswordProtectionService {
void GetPhishingDetector(
service_manager::InterfaceProvider* provider,
mojom::PhishingDetectorPtr* phishing_detector) override {
mojo::Remote<mojom::PhishingDetector>* phishing_detector) override {
service_manager::InterfaceProvider::TestApi test_api(provider);
test_api.SetBinderForName(
mojom::PhishingDetector::Name_,
base::BindRepeating(&TestPhishingDetector::Bind,
base::Unretained(&test_phishing_detector_)));
provider->GetInterface(phishing_detector);
provider->GetInterface(phishing_detector->BindNewPipeAndPassReceiver());
test_api.ClearBinderForName(mojom::PhishingDetector::Name_);
}
......
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