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

Convert SpellCheckHost and SpellChecker to new Mojo types

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

It introduces a new template for GetInterface from
LocalInterfaceProvider.

Bug: 955171
Change-Id: I459d2ffc50242f8f2159c31212fd2346e571544f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1813125
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699213}
parent c0879e35
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/extensions_api_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/platform/web_gesture_event.h" #include "third_party/blink/public/platform/web_gesture_event.h"
...@@ -68,7 +69,7 @@ ...@@ -68,7 +69,7 @@
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/user_prefs/user_prefs.h" #include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#if BUILDFLAG(HAS_SPELLCHECK_PANEL) #if BUILDFLAG(HAS_SPELLCHECK_PANEL)
#include "chrome/browser/spellchecker/test/spellcheck_panel_browsertest_helper.h" #include "chrome/browser/spellchecker/test/spellcheck_panel_browsertest_helper.h"
...@@ -873,7 +874,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, ...@@ -873,7 +874,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest,
class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
public: public:
explicit MockSpellCheckHost(content::RenderProcessHost* process_host) explicit MockSpellCheckHost(content::RenderProcessHost* process_host)
: process_host_(process_host), binding_(this) {} : process_host_(process_host) {}
~MockSpellCheckHost() override {} ~MockSpellCheckHost() override {}
content::RenderProcessHost* process_host() const { return process_host_; } content::RenderProcessHost* process_host() const { return process_host_; }
...@@ -907,16 +908,17 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { ...@@ -907,16 +908,17 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
run_loop.Run(); run_loop.Run();
} }
void SpellCheckHostRequest(spellcheck::mojom::SpellCheckHostRequest request) { void SpellCheckHostReceiver(
EXPECT_FALSE(binding_.is_bound()); mojo::PendingReceiver<spellcheck::mojom::SpellCheckHost> receiver) {
binding_.Bind(std::move(request)); EXPECT_FALSE(receiver_.is_bound());
receiver_.Bind(std::move(receiver));
} }
private: private:
void TextReceived(const base::string16& text) { void TextReceived(const base::string16& text) {
text_received_ = true; text_received_ = true;
text_ = text; text_ = text;
binding_.Close(); receiver_.reset();
if (quit_) if (quit_)
std::move(quit_).Run(); std::move(quit_).Run();
} }
...@@ -963,7 +965,7 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { ...@@ -963,7 +965,7 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
content::RenderProcessHost* process_host_; content::RenderProcessHost* process_host_;
bool text_received_ = false; bool text_received_ = false;
base::string16 text_; base::string16 text_;
mojo::Binding<spellcheck::mojom::SpellCheckHost> binding_; mojo::Receiver<spellcheck::mojom::SpellCheckHost> receiver_{this};
base::OnceClosure quit_; base::OnceClosure quit_;
DISALLOW_COPY_AND_ASSIGN(MockSpellCheckHost); DISALLOW_COPY_AND_ASSIGN(MockSpellCheckHost);
...@@ -1027,7 +1029,7 @@ class SpellCheckBrowserTestHelper { ...@@ -1027,7 +1029,7 @@ class SpellCheckBrowserTestHelper {
content::RenderProcessHost* host = content::RenderProcessHost* host =
content::RenderProcessHost::FromID(render_process_id); content::RenderProcessHost::FromID(render_process_id);
auto spell_check_host = std::make_unique<MockSpellCheckHost>(host); auto spell_check_host = std::make_unique<MockSpellCheckHost>(host);
spell_check_host->SpellCheckHostRequest(std::move(receiver)); spell_check_host->SpellCheckHostReceiver(std::move(receiver));
spell_check_hosts_.push_back(std::move(spell_check_host)); spell_check_hosts_.push_back(std::move(spell_check_host));
if (quit_on_bind_closure_) if (quit_on_bind_closure_)
std::move(quit_on_bind_closure_).Run(); std::move(quit_on_bind_closure_).Run();
...@@ -1098,7 +1100,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, OOPIFDisabledSpellCheckTest) { ...@@ -1098,7 +1100,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, OOPIFDisabledSpellCheckTest) {
spell_check_helper.GetSpellCheckHostForProcess( spell_check_helper.GetSpellCheckHostForProcess(
cross_site_subframe->GetProcess()); cross_site_subframe->GetProcess());
// The renderer makes no SpellCheckHostRequest at all, in which case no // The renderer makes no SpellCheckHostReceiver at all, in which case no
// SpellCheckHost is bound and no spellchecking will be done. // SpellCheckHost is bound and no spellchecking will be done.
EXPECT_FALSE(spell_check_host); EXPECT_FALSE(spell_check_host);
......
...@@ -12,14 +12,15 @@ ...@@ -12,14 +12,15 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "mojo/public/cpp/bindings/remote.h"
class SpellCheckHostChromeImplMacBrowserTest : public InProcessBrowserTest { class SpellCheckHostChromeImplMacBrowserTest : public InProcessBrowserTest {
public: public:
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
content::BrowserContext* context = browser()->profile(); content::BrowserContext* context = browser()->profile();
renderer_.reset(new content::MockRenderProcessHost(context)); renderer_.reset(new content::MockRenderProcessHost(context));
SpellCheckHostChromeImpl::Create(renderer_->GetID(), SpellCheckHostChromeImpl::Create(
mojo::MakeRequest(&spell_check_host_)); renderer_->GetID(), spell_check_host_.BindNewPipeAndPassReceiver());
} }
void TearDownOnMainThread() override { renderer_.reset(); } void TearDownOnMainThread() override { renderer_.reset(); }
...@@ -41,7 +42,7 @@ class SpellCheckHostChromeImplMacBrowserTest : public InProcessBrowserTest { ...@@ -41,7 +42,7 @@ class SpellCheckHostChromeImplMacBrowserTest : public InProcessBrowserTest {
protected: protected:
std::unique_ptr<content::MockRenderProcessHost> renderer_; std::unique_ptr<content::MockRenderProcessHost> renderer_;
spellcheck::mojom::SpellCheckHostPtr spell_check_host_; mojo::Remote<spellcheck::mojom::SpellCheckHost> spell_check_host_;
bool received_result_ = false; bool received_result_ = false;
std::vector<SpellCheckResult> result_; std::vector<SpellCheckResult> result_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/spellcheck/common/spellcheck_features.h" #include "components/spellcheck/common/spellcheck_features.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "mojo/public/cpp/bindings/remote.h"
class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
public: public:
...@@ -26,8 +27,8 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { ...@@ -26,8 +27,8 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
base::test::ScopedFeatureList feature_list; base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker); feature_list.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker);
SpellCheckHostChromeImpl::Create(renderer_->GetID(), SpellCheckHostChromeImpl::Create(
mojo::MakeRequest(&spell_check_host_)); renderer_->GetID(), spell_check_host_.BindNewPipeAndPassReceiver());
} }
void TearDownOnMainThread() override { renderer_.reset(); } void TearDownOnMainThread() override { renderer_.reset(); }
...@@ -58,7 +59,7 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { ...@@ -58,7 +59,7 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
protected: protected:
std::unique_ptr<content::MockRenderProcessHost> renderer_; std::unique_ptr<content::MockRenderProcessHost> renderer_;
spellcheck::mojom::SpellCheckHostPtr spell_check_host_; mojo::Remote<spellcheck::mojom::SpellCheckHost> spell_check_host_;
bool received_result_ = false; bool received_result_ = false;
std::vector<SpellCheckResult> result_; std::vector<SpellCheckResult> result_;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
using content::BrowserContext; using content::BrowserContext;
using content::RenderProcessHost; using content::RenderProcessHost;
...@@ -231,14 +232,14 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest { ...@@ -231,14 +232,14 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest {
SpellcheckServiceHostBrowserTest() = default; SpellcheckServiceHostBrowserTest() = default;
void RequestDictionary() { void RequestDictionary() {
spellcheck::mojom::SpellCheckHostPtr interface; mojo::Remote<spellcheck::mojom::SpellCheckHost> interface;
RequestSpellCheckHost(&interface); RequestSpellCheckHost(&interface);
interface->RequestDictionary(); interface->RequestDictionary();
} }
void NotifyChecked() { void NotifyChecked() {
spellcheck::mojom::SpellCheckHostPtr interface; mojo::Remote<spellcheck::mojom::SpellCheckHost> interface;
RequestSpellCheckHost(&interface); RequestSpellCheckHost(&interface);
const bool misspelt = true; const bool misspelt = true;
...@@ -248,7 +249,7 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest { ...@@ -248,7 +249,7 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest {
} }
void CallSpellingService() { void CallSpellingService() {
spellcheck::mojom::SpellCheckHostPtr interface; mojo::Remote<spellcheck::mojom::SpellCheckHost> interface;
RequestSpellCheckHost(&interface); RequestSpellCheckHost(&interface);
base::UTF8ToUTF16("hello", 5, &word_); base::UTF8ToUTF16("hello", 5, &word_);
...@@ -265,9 +266,10 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest { ...@@ -265,9 +266,10 @@ class SpellcheckServiceHostBrowserTest : public SpellcheckServiceBrowserTest {
} }
private: private:
void RequestSpellCheckHost(spellcheck::mojom::SpellCheckHostPtr* interface) { void RequestSpellCheckHost(
mojo::Remote<spellcheck::mojom::SpellCheckHost>* interface) {
SpellCheckHostChromeImpl::Create(GetRenderer()->GetID(), SpellCheckHostChromeImpl::Create(GetRenderer()->GetID(),
mojo::MakeRequest(interface)); interface->BindNewPipeAndPassReceiver());
} }
void SpellingServiceDone(bool success, void SpellingServiceDone(bool success,
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
#include "components/spellcheck/browser/spell_check_host_impl.h" #include "components/spellcheck/browser/spell_check_host_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
SpellCheckHostImpl::SpellCheckHostImpl() = default; SpellCheckHostImpl::SpellCheckHostImpl() = default;
SpellCheckHostImpl::~SpellCheckHostImpl() = default; SpellCheckHostImpl::~SpellCheckHostImpl() = default;
// static // static
void SpellCheckHostImpl::Create( void SpellCheckHostImpl::Create(
spellcheck::mojom::SpellCheckHostRequest request) { mojo::PendingReceiver<spellcheck::mojom::SpellCheckHost> receiver) {
mojo::MakeStrongBinding(std::make_unique<SpellCheckHostImpl>(), mojo::MakeSelfOwnedReceiver(std::make_unique<SpellCheckHostImpl>(),
std::move(request)); std::move(receiver));
} }
void SpellCheckHostImpl::RequestDictionary() { void SpellCheckHostImpl::RequestDictionary() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/spellcheck/browser/spellchecker_session_bridge_android.h" #include "components/spellcheck/browser/spellchecker_session_bridge_android.h"
...@@ -29,7 +30,8 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost { ...@@ -29,7 +30,8 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost {
SpellCheckHostImpl(); SpellCheckHostImpl();
~SpellCheckHostImpl() override; ~SpellCheckHostImpl() override;
static void Create(spellcheck::mojom::SpellCheckHostRequest request); static void Create(
mojo::PendingReceiver<spellcheck::mojom::SpellCheckHost> receiver);
protected: protected:
// spellcheck::mojom::SpellCheckHost: // spellcheck::mojom::SpellCheckHost:
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.h"
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/local_interface_provider.h" #include "services/service_manager/public/cpp/local_interface_provider.h"
#include "third_party/hunspell/src/hunspell/hunspell.hxx" #include "third_party/hunspell/src/hunspell/hunspell.hxx"
...@@ -116,8 +117,9 @@ void HunspellEngine::FillSuggestionList( ...@@ -116,8 +117,9 @@ void HunspellEngine::FillSuggestionList(
bool HunspellEngine::InitializeIfNeeded() { bool HunspellEngine::InitializeIfNeeded() {
if (!initialized_ && !dictionary_requested_) { if (!initialized_ && !dictionary_requested_) {
spellcheck::mojom::SpellCheckHostPtr spell_check_host; mojo::Remote<spellcheck::mojom::SpellCheckHost> spell_check_host;
embedder_provider_->GetInterface(&spell_check_host); embedder_provider_->GetInterface(
spell_check_host.BindNewPipeAndPassReceiver());
spell_check_host->RequestDictionary(); spell_check_host->RequestDictionary();
dictionary_requested_ = true; dictionary_requested_ = true;
return true; return true;
......
...@@ -20,7 +20,8 @@ PlatformSpellingEngine::GetOrBindSpellCheckHost() { ...@@ -20,7 +20,8 @@ PlatformSpellingEngine::GetOrBindSpellCheckHost() {
if (spell_check_host_) if (spell_check_host_)
return *spell_check_host_; return *spell_check_host_;
embedder_provider_->GetInterface(&spell_check_host_); embedder_provider_->GetInterface(
spell_check_host_.BindNewPipeAndPassReceiver());
return *spell_check_host_; return *spell_check_host_;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/renderer/spelling_engine.h" #include "components/spellcheck/renderer/spelling_engine.h"
#include "mojo/public/cpp/bindings/remote.h"
class PlatformSpellingEngine : public SpellingEngine { class PlatformSpellingEngine : public SpellingEngine {
public: public:
...@@ -29,8 +30,7 @@ class PlatformSpellingEngine : public SpellingEngine { ...@@ -29,8 +30,7 @@ class PlatformSpellingEngine : public SpellingEngine {
// Not owned. |embedder_provider_| outlives PlatformSpellingEngine. // Not owned. |embedder_provider_| outlives PlatformSpellingEngine.
service_manager::LocalInterfaceProvider* embedder_provider_; service_manager::LocalInterfaceProvider* embedder_provider_;
spellcheck::mojom::SpellCheckHostPtr spell_check_host_; mojo::Remote<spellcheck::mojom::SpellCheckHost> spell_check_host_;
}; };
#endif // COMPONENTS_SPELLCHECK_RENDERER_PLATFORM_SPELLING_ENGINE_H_ #endif // COMPONENTS_SPELLCHECK_RENDERER_PLATFORM_SPELLING_ENGINE_H_
...@@ -160,7 +160,7 @@ SpellCheck::SpellCheck( ...@@ -160,7 +160,7 @@ SpellCheck::SpellCheck(
DCHECK(embedder_provider); DCHECK(embedder_provider);
if (!registry) if (!registry)
return; // Can be NULL in tests. return; // Can be NULL in tests.
registry->AddInterface(base::BindRepeating(&SpellCheck::SpellCheckerRequest, registry->AddInterface(base::BindRepeating(&SpellCheck::SpellCheckerReceiver,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
} }
...@@ -197,9 +197,9 @@ void SpellCheck::FillSuggestions( ...@@ -197,9 +197,9 @@ void SpellCheck::FillSuggestions(
} }
} }
void SpellCheck::SpellCheckerRequest( void SpellCheck::SpellCheckerReceiver(
spellcheck::mojom::SpellCheckerRequest request) { mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver) {
bindings_.AddBinding(this, std::move(request)); receivers_.Add(this, std::move(receiver));
} }
void SpellCheck::Initialize( void SpellCheck::Initialize(
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/renderer/custom_dictionary_engine.h" #include "components/spellcheck/renderer/custom_dictionary_engine.h"
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.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 "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
class SpellcheckLanguage; class SpellcheckLanguage;
...@@ -140,8 +141,9 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>, ...@@ -140,8 +141,9 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>,
const std::vector<std::vector<base::string16>>& suggestions_list, const std::vector<std::vector<base::string16>>& suggestions_list,
std::vector<base::string16>* optional_suggestions); std::vector<base::string16>* optional_suggestions);
// Binds requests for the SpellChecker interface. // Binds receivers for the SpellChecker interface.
void SpellCheckerRequest(spellcheck::mojom::SpellCheckerRequest request); void SpellCheckerReceiver(
mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver);
// spellcheck::mojom::SpellChecker: // spellcheck::mojom::SpellChecker:
void Initialize( void Initialize(
...@@ -172,8 +174,8 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>, ...@@ -172,8 +174,8 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>,
std::unique_ptr<SpellcheckRequest> pending_request_param_; std::unique_ptr<SpellcheckRequest> pending_request_param_;
#endif #endif
// Bindings for SpellChecker clients. // Receivers for SpellChecker clients.
mojo::BindingSet<spellcheck::mojom::SpellChecker> bindings_; mojo::ReceiverSet<spellcheck::mojom::SpellChecker> receivers_;
// A vector of objects used to actually check spelling, one for each enabled // A vector of objects used to actually check spelling, one for each enabled
// language. // language.
......
...@@ -106,7 +106,8 @@ spellcheck::mojom::SpellCheckHost& SpellCheckProvider::GetSpellCheckHost() { ...@@ -106,7 +106,8 @@ spellcheck::mojom::SpellCheckHost& SpellCheckProvider::GetSpellCheckHost() {
if (spell_check_host_) if (spell_check_host_)
return *spell_check_host_; return *spell_check_host_;
embedder_provider_->GetInterface(&spell_check_host_); embedder_provider_->GetInterface(
spell_check_host_.BindNewPipeAndPassReceiver());
return *spell_check_host_; return *spell_check_host_;
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h" #include "content/public/renderer/render_frame_observer_tracker.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/web/web_text_check_client.h" #include "third_party/blink/public/web/web_text_check_client.h"
class SpellCheck; class SpellCheck;
...@@ -68,8 +70,9 @@ class SpellCheckProvider ...@@ -68,8 +70,9 @@ class SpellCheckProvider
class DictionaryUpdateObserverImpl; class DictionaryUpdateObserverImpl;
// Sets the SpellCheckHost (for unit tests). // Sets the SpellCheckHost (for unit tests).
void SetSpellCheckHostForTesting(spellcheck::mojom::SpellCheckHostPtr host) { void SetSpellCheckHostForTesting(
spell_check_host_ = std::move(host); mojo::PendingRemote<spellcheck::mojom::SpellCheckHost> host) {
spell_check_host_.Bind(std::move(host));
} }
// Reset dictionary_update_observer_ in TestingSpellCheckProvider dtor. // Reset dictionary_update_observer_ in TestingSpellCheckProvider dtor.
...@@ -132,7 +135,7 @@ class SpellCheckProvider ...@@ -132,7 +135,7 @@ class SpellCheckProvider
service_manager::LocalInterfaceProvider* embedder_provider_; service_manager::LocalInterfaceProvider* embedder_provider_;
// Interface to the SpellCheckHost. // Interface to the SpellCheckHost.
spellcheck::mojom::SpellCheckHostPtr spell_check_host_; mojo::Remote<spellcheck::mojom::SpellCheckHost> spell_check_host_;
// Dictionary updated observer. // Dictionary updated observer.
std::unique_ptr<DictionaryUpdateObserverImpl> dictionary_update_observer_; std::unique_ptr<DictionaryUpdateObserverImpl> dictionary_update_observer_;
......
...@@ -34,17 +34,15 @@ TestingSpellCheckProvider::TestingSpellCheckProvider( ...@@ -34,17 +34,15 @@ TestingSpellCheckProvider::TestingSpellCheckProvider(
service_manager::LocalInterfaceProvider* embedder_provider) service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheckProvider(nullptr, : SpellCheckProvider(nullptr,
new SpellCheck(nullptr, embedder_provider), new SpellCheck(nullptr, embedder_provider),
embedder_provider), embedder_provider) {}
binding_(this) {}
TestingSpellCheckProvider::TestingSpellCheckProvider( TestingSpellCheckProvider::TestingSpellCheckProvider(
SpellCheck* spellcheck, SpellCheck* spellcheck,
service_manager::LocalInterfaceProvider* embedder_provider) service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheckProvider(nullptr, spellcheck, embedder_provider), : SpellCheckProvider(nullptr, spellcheck, embedder_provider) {}
binding_(this) {}
TestingSpellCheckProvider::~TestingSpellCheckProvider() { TestingSpellCheckProvider::~TestingSpellCheckProvider() {
binding_.Close(); receiver_.reset();
// dictionary_update_observer_ must be released before deleting spellcheck_. // dictionary_update_observer_ must be released before deleting spellcheck_.
ResetDictionaryUpdateObserverForTesting(); ResetDictionaryUpdateObserverForTesting();
delete spellcheck_; delete spellcheck_;
...@@ -55,11 +53,8 @@ void TestingSpellCheckProvider::RequestTextChecking( ...@@ -55,11 +53,8 @@ void TestingSpellCheckProvider::RequestTextChecking(
std::unique_ptr<blink::WebTextCheckingCompletion> completion) { std::unique_ptr<blink::WebTextCheckingCompletion> completion) {
if (!loop_ && !base::MessageLoopCurrent::Get()) if (!loop_ && !base::MessageLoopCurrent::Get())
loop_ = std::make_unique<base::MessageLoop>(); loop_ = std::make_unique<base::MessageLoop>();
if (!binding_.is_bound()) { if (!receiver_.is_bound())
spellcheck::mojom::SpellCheckHostPtr host_proxy; SetSpellCheckHostForTesting(receiver_.BindNewPipeAndPassRemote());
binding_.Bind(mojo::MakeRequest(&host_proxy));
SetSpellCheckHostForTesting(std::move(host_proxy));
}
SpellCheckProvider::RequestTextChecking(text, std::move(completion)); SpellCheckProvider::RequestTextChecking(text, std::move(completion));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/spellcheck/renderer/empty_local_interface_provider.h" #include "components/spellcheck/renderer/empty_local_interface_provider.h"
#include "components/spellcheck/renderer/spellcheck_provider.h" #include "components/spellcheck/renderer/spellcheck_provider.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/public/web/web_text_checking_completion.h" #include "third_party/blink/public/web/web_text_checking_completion.h"
...@@ -109,8 +109,8 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -109,8 +109,8 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
// Message loop (if needed) to deliver the SpellCheckHost request flow. // Message loop (if needed) to deliver the SpellCheckHost request flow.
std::unique_ptr<base::MessageLoop> loop_; std::unique_ptr<base::MessageLoop> loop_;
// Binding to receive the SpellCheckHost request flow. // Receiver to receive the SpellCheckHost request flow.
mojo::Binding<spellcheck::mojom::SpellCheckHost> binding_; mojo::Receiver<spellcheck::mojom::SpellCheckHost> receiver_{this};
}; };
// SpellCheckProvider test fixture. // SpellCheckProvider test fixture.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/interface_ptr.h" #include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/public/cpp/export.h" #include "services/service_manager/public/cpp/export.h"
...@@ -28,6 +29,10 @@ class LocalInterfaceProvider { ...@@ -28,6 +29,10 @@ class LocalInterfaceProvider {
void GetInterface(mojo::InterfaceRequest<Interface> request) { void GetInterface(mojo::InterfaceRequest<Interface> request) {
GetInterface(Interface::Name_, std::move(request.PassMessagePipe())); GetInterface(Interface::Name_, std::move(request.PassMessagePipe()));
} }
template <typename Interface>
void GetInterface(mojo::PendingReceiver<Interface> receiver) {
GetInterface(Interface::Name_, std::move(receiver.PassPipe()));
}
virtual void GetInterface(const std::string& name, virtual void GetInterface(const std::string& name,
mojo::ScopedMessagePipeHandle request_handle) = 0; mojo::ScopedMessagePipeHandle request_handle) = 0;
}; };
......
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