Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: chrome/browser/search_engines/search_provider_install_state_impl.cc

Issue 2072613003: Convert GetSearchProviderInstallState to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small twiddles Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/search_provider_install_state_impl.cc
diff --git a/chrome/browser/search_engines/search_provider_install_state_message_filter.cc b/chrome/browser/search_engines/search_provider_install_state_impl.cc
similarity index 54%
rename from chrome/browser/search_engines/search_provider_install_state_message_filter.cc
rename to chrome/browser/search_engines/search_provider_install_state_impl.cc
index ccd32f4dcb5690316e8b538772a645ea67829686..f426432682e8ce024f5994949fefd8fdd4ad0902 100644
--- a/chrome/browser/search_engines/search_provider_install_state_message_filter.cc
+++ b/chrome/browser/search_engines/search_provider_install_state_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
+#include "chrome/browser/search_engines/search_provider_install_state_impl.h"
#include "base/bind.h"
#include "base/logging.h"
@@ -11,17 +11,16 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/search_provider.mojom.h"
#include "content/public/browser/render_process_host.h"
#include "url/gurl.h"
using content::BrowserThread;
-SearchProviderInstallStateMessageFilter::
-SearchProviderInstallStateMessageFilter(
+SearchProviderInstallStateImpl::SearchProviderInstallStateImpl(
int render_process_id,
Profile* profile)
- : BrowserMessageFilter(ChromeMsgStart),
- provider_data_(TemplateURLServiceFactory::GetForProfile(profile),
+ : provider_data_(TemplateURLServiceFactory::GetForProfile(profile),
UIThreadSearchTermsData(profile).GoogleBaseURLValue(),
GoogleURLTrackerFactory::GetForProfile(profile),
content::RenderProcessHost::FromID(render_process_id)),
@@ -32,26 +31,28 @@ SearchProviderInstallStateMessageFilter(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
-bool SearchProviderInstallStateMessageFilter::OnMessageReceived(
- const IPC::Message& message) {
+SearchProviderInstallStateImpl::~SearchProviderInstallStateImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(SearchProviderInstallStateMessageFilter, message)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(
- ChromeViewHostMsg_GetSearchProviderInstallState,
- OnGetSearchProviderInstallState)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
}
-SearchProviderInstallStateMessageFilter::
-~SearchProviderInstallStateMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+void SearchProviderInstallStateImpl::InstallService(
+ content::RenderProcessHost* host) {
+ int id = host->GetID();
+ Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
+ auto* adapter = new SearchProviderInstallStateImplAdapter(
+ std::unique_ptr<SearchProviderInstallStateImpl,
+ content::BrowserThread::DeleteOnIOThread>(
+ new SearchProviderInstallStateImpl(id, profile)));
+ host->GetServiceRegistry()->AddService<mojom::SearchProviderInstallState>(
sky 2016/06/20 15:20:26 I'm not familiar with the threading requirements o
tibell 2016/06/21 01:31:32 I'm just preserving the same threading behavior as
+ base::Bind(&SearchProviderInstallStateImpl::Bind,
+ base::Unretained(adapter->get())),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
+ host->SetUserData(SearchProviderInstallStateImpl::kRenderProcessHostKey,
+ adapter);
}
search_provider::InstallState
-SearchProviderInstallStateMessageFilter::GetSearchProviderInstallState(
+SearchProviderInstallStateImpl::GetSearchProviderInstallState(
const GURL& page_location,
const GURL& requested_host) {
GURL requested_origin = requested_host.GetOrigin();
@@ -64,7 +65,7 @@ SearchProviderInstallStateMessageFilter::GetSearchProviderInstallState(
// done after the security check or else a web site can detect that the
// user is in incognito mode just by doing a cross origin request.)
if (is_off_the_record_)
- return search_provider::NOT_INSTALLED;
+ return search_provider::NOT_INSTALLED;
switch (provider_data_.GetInstallState(requested_origin)) {
case SearchProviderInstallData::NOT_INSTALLED:
@@ -81,31 +82,38 @@ SearchProviderInstallStateMessageFilter::GetSearchProviderInstallState(
return search_provider::NOT_INSTALLED;
}
-void
-SearchProviderInstallStateMessageFilter::OnGetSearchProviderInstallState(
+void SearchProviderInstallStateImpl::Bind(
+ mojom::SearchProviderInstallStateRequest request) {
+ binding_set_.AddBinding(this, std::move(request));
+}
+
+const char SearchProviderInstallStateImpl::kRenderProcessHostKey[] =
+ "kRenderProcessHostKey";
+
+void SearchProviderInstallStateImpl::GetInstallState(
const GURL& page_location,
const GURL& requested_host,
- IPC::Message* reply_msg) {
- provider_data_.CallWhenLoaded(
- base::Bind(
- &SearchProviderInstallStateMessageFilter::
- ReplyWithProviderInstallState,
- weak_factory_.GetWeakPtr(),
- page_location,
- requested_host,
- reply_msg));
+ const GetInstallStateCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ provider_data_.CallWhenLoaded(base::Bind(
+ &SearchProviderInstallStateImpl::ReplyWithProviderInstallState,
+ weak_factory_.GetWeakPtr(), page_location, requested_host, callback));
}
-void SearchProviderInstallStateMessageFilter::ReplyWithProviderInstallState(
+void SearchProviderInstallStateImpl::ReplyWithProviderInstallState(
const GURL& page_location,
const GURL& requested_host,
- IPC::Message* reply_msg) {
- DCHECK(reply_msg);
+ const GetInstallStateCallback& callback) {
search_provider::InstallState install_state =
GetSearchProviderInstallState(page_location, requested_host);
- ChromeViewHostMsg_GetSearchProviderInstallState::WriteReplyParams(
- reply_msg,
- install_state);
- Send(reply_msg);
+ callback.Run(install_state);
}
+
+SearchProviderInstallStateImplAdapter::SearchProviderInstallStateImplAdapter(
+ std::unique_ptr<SearchProviderInstallStateImpl,
+ content::BrowserThread::DeleteOnIOThread> filter)
+ : ptr_(std::move(filter)) {}
+
+SearchProviderInstallStateImplAdapter::
+ ~SearchProviderInstallStateImplAdapter() = default;

Powered by Google App Engine
This is Rietveld 408576698