Skip to content

Commit

Permalink
Change signature of OnConnect:
Browse files Browse the repository at this point in the history
- pass remote identity & interface registry instead of dual purpose Connection object
- Connection is now only returned via Connect() & has no AddInterface() methods.
- updates all Service impls & ConnectionFilter.

R=rockot@chromium.org

BUG=
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2215133002
Cr-Commit-Position: refs/heads/master@{#410543}
  • Loading branch information
ben authored and Commit bot committed Aug 9, 2016
1 parent 522801d commit 8366b12
Show file tree
Hide file tree
Showing 107 changed files with 401 additions and 458 deletions.
13 changes: 7 additions & 6 deletions ash/mus/window_manager_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ void WindowManagerApplication::OnStart(const shell::Identity& identity) {
InitWindowManager(window_tree_client);
}

bool WindowManagerApplication::OnConnect(shell::Connection* connection) {
connection->AddInterface<mojom::ShelfLayout>(this);
connection->AddInterface<mojom::UserWindowController>(this);
connection->AddInterface<ui::mojom::AcceleratorRegistrar>(this);
if (connection->GetRemoteIdentity().name() == "mojo:mash_session") {
connector()->ConnectToInterface(connection->GetRemoteIdentity(), &session_);
bool WindowManagerApplication::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface<mojom::ShelfLayout>(this);
registry->AddInterface<mojom::UserWindowController>(this);
registry->AddInterface<ui::mojom::AcceleratorRegistrar>(this);
if (remote_identity.name() == "mojo:mash_session") {
connector()->ConnectToInterface(remote_identity, &session_);
session_->AddScreenlockStateListener(
screenlock_state_listener_binding_.CreateInterfacePtrAndBind());
}
Expand Down
3 changes: 2 additions & 1 deletion ash/mus/window_manager_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class WindowManagerApplication

// shell::Service:
void OnStart(const shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override;

// shell::InterfaceFactory<mojom::ShelfLayout>:
void Create(const shell::Identity& remote_identity,
Expand Down
7 changes: 4 additions & 3 deletions ash/sysui/sysui_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ void SysUIApplication::OnStart(const ::shell::Identity& identity) {
input_device_client_.Connect(std::move(server));
}

bool SysUIApplication::OnConnect(::shell::Connection* connection) {
connection->AddInterface<mash::shelf::mojom::ShelfController>(this);
connection->AddInterface<mojom::WallpaperController>(this);
bool SysUIApplication::OnConnect(const ::shell::Identity& remote_identity,
::shell::InterfaceRegistry* registry) {
registry->AddInterface<mash::shelf::mojom::ShelfController>(this);
registry->AddInterface<mojom::WallpaperController>(this);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion ash/sysui/sysui_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SysUIApplication
private:
// shell::Service:
void OnStart(const ::shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const ::shell::Identity& remote_identity,
::shell::InterfaceRegistry* registry) override;

// InterfaceFactory<mash::shelf::mojom::ShelfController>:
void Create(const shell::Identity& remote_identity,
Expand Down
5 changes: 3 additions & 2 deletions ash/touch_hud/mus/touch_hud_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ void TouchHudApplication::OnStart(const shell::Identity& identity) {
views::WindowManagerConnection::Create(connector(), identity);
}

bool TouchHudApplication::OnConnect(shell::Connection* connection) {
connection->AddInterface<mash::mojom::Launchable>(this);
bool TouchHudApplication::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface<mash::mojom::Launchable>(this);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion ash/touch_hud/mus/touch_hud_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class TouchHudApplication
private:
// shell::Service:
void OnStart(const shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override;

// mojom::Launchable:
void Launch(uint32_t what, mash::mojom::LaunchMode how) override;
Expand Down
5 changes: 3 additions & 2 deletions chrome/app/mash/mash_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class DefaultService : public shell::Service,
~DefaultService() override {}

// shell::Service:
bool OnConnect(shell::Connection* connection) override {
connection->AddInterface<ServiceFactory>(this);
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override {
registry->AddInterface<ServiceFactory>(this);
return true;
}

Expand Down
20 changes: 11 additions & 9 deletions chrome/browser/chromeos/chrome_interface_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mash/public/interfaces/launchable.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/interface_registry.h"
#include "ui/app_list/presenter/app_list_presenter.mojom.h"
#include "ui/keyboard/keyboard.mojom.h"

Expand Down Expand Up @@ -80,9 +81,9 @@ class FactoryImpl {

template <typename Interface>
static void AddFactory(
shell::Connection* connection,
shell::InterfaceRegistry* registry,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
connection->AddInterface<Interface>(
registry->AddInterface<Interface>(
base::Bind(&FactoryImpl::CallMainThreadFactory<Interface>),
task_runner);
}
Expand Down Expand Up @@ -148,16 +149,17 @@ ChromeInterfaceFactory::ChromeInterfaceFactory()

ChromeInterfaceFactory::~ChromeInterfaceFactory() {}

bool ChromeInterfaceFactory::OnConnect(shell::Connection* connection,
bool ChromeInterfaceFactory::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry,
shell::Connector* connector) {
FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(
connection, main_thread_task_runner_);
FactoryImpl::AddFactory<mash::mojom::Launchable>(
connection, main_thread_task_runner_);
FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(registry,
main_thread_task_runner_);
FactoryImpl::AddFactory<mash::mojom::Launchable>(registry,
main_thread_task_runner_);
FactoryImpl::AddFactory<ash::sysui::mojom::WallpaperManager>(
connection, main_thread_task_runner_);
registry, main_thread_task_runner_);
FactoryImpl::AddFactory<app_list::mojom::AppListPresenter>(
connection, main_thread_task_runner_);
registry, main_thread_task_runner_);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/chrome_interface_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ChromeInterfaceFactory : public content::ConnectionFilter {

private:
// content::ConnectionFilter:
bool OnConnect(shell::Connection* connection,
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry,
shell::Connector* connector) override;

scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
Expand Down
5 changes: 3 additions & 2 deletions components/filesystem/file_system_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void FileSystemApp::OnStart(const shell::Identity& identity) {
tracing_.Initialize(connector(), identity.name());
}

bool FileSystemApp::OnConnect(shell::Connection* connection) {
connection->AddInterface<mojom::FileSystem>(this);
bool FileSystemApp::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface<mojom::FileSystem>(this);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion components/filesystem/file_system_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class FileSystemApp : public shell::Service,

// |shell::Service| override:
void OnStart(const shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override;

// |InterfaceFactory<Files>| implementation:
void Create(const shell::Identity& remote_identity,
Expand Down
5 changes: 3 additions & 2 deletions components/font_service/font_service_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ void FontServiceApp::OnStart(const shell::Identity& identity) {
tracing_.Initialize(connector(), identity.name());
}

bool FontServiceApp::OnConnect(shell::Connection* connection) {
connection->AddInterface(this);
bool FontServiceApp::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface(this);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion components/font_service/font_service_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FontServiceApp : public shell::Service,
private:
// shell::Service:
void OnStart(const shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override;

// shell::InterfaceFactory<mojom::FontService>:
void Create(const shell::Identity& remote_identity,
Expand Down
7 changes: 4 additions & 3 deletions components/leveldb/leveldb_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "base/message_loop/message_loop.h"
#include "components/leveldb/leveldb_service_impl.h"
#include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/interface_registry.h"

namespace leveldb {

Expand All @@ -18,8 +18,9 @@ void LevelDBApp::OnStart(const shell::Identity& identity) {
tracing_.Initialize(connector(), identity.name());
}

bool LevelDBApp::OnConnect(shell::Connection* connection) {
connection->AddInterface<mojom::LevelDBService>(this);
bool LevelDBApp::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface<mojom::LevelDBService>(this);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion components/leveldb/leveldb_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LevelDBApp : public shell::Service,
private:
// |Service| override:
void OnStart(const shell::Identity& identity) override;
bool OnConnect(shell::Connection* connection) override;
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) override;

// |InterfaceFactory<mojom::LevelDBService>| implementation:
void Create(const shell::Identity& remote_identity,
Expand Down
4 changes: 2 additions & 2 deletions content/browser/frame_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ void RenderFrameHostImpl::Create(
const shell::Identity& remote_identity,
media::mojom::ServiceFactoryRequest request) {
std::unique_ptr<shell::InterfaceRegistry> registry(
new shell::InterfaceRegistry(nullptr));
new shell::InterfaceRegistry);
#if defined(OS_ANDROID) && defined(ENABLE_MOJO_CDM)
registry->AddInterface(
base::Bind(&ProvisionFetcherImpl::Create, this));
Expand Down Expand Up @@ -2467,7 +2467,7 @@ void RenderFrameHostImpl::SetUpMojoIfNeeded() {
if (interface_registry_.get())
return;

interface_registry_.reset(new shell::InterfaceRegistry(nullptr));
interface_registry_.reset(new shell::InterfaceRegistry);
if (!GetProcess()->GetRemoteInterfaces())
return;

Expand Down
1 change: 1 addition & 0 deletions content/browser/mojo/mojo_child_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/shell/public/cpp/connector.h"
#include "services/shell/public/cpp/identity.h"
#include "services/shell/public/cpp/interface_registry.h"
#include "services/shell/public/interfaces/service.mojom.h"

namespace content {
Expand Down
15 changes: 7 additions & 8 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {

private:
// ConnectionFilter:
bool OnConnect(shell::Connection* connection,
bool OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry,
shell::Connector* connector) override {
if (!weak_factory_)
weak_factory_.reset(new base::WeakPtrFactory<ConnectionFilterImpl>(this));

// We only fulfill connections from the renderer we host.
const shell::Identity& remote_identity = connection->GetRemoteIdentity();
if (child_identity_.name() != remote_identity.name() ||
child_identity_.instance() != remote_identity.instance()) {
return false;
Expand All @@ -496,11 +496,10 @@ class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
for (auto& interface_name : interface_names) {
// Note that the added callbacks may outlive this object, which is
// destroyed in RPH::Cleanup().
connection->GetInterfaceRegistry()->AddInterface(
interface_name,
base::Bind(&ConnectionFilterImpl::GetInterface,
weak_factory_->GetWeakPtr(),
interface_name));
registry->AddInterface(interface_name,
base::Bind(&ConnectionFilterImpl::GetInterface,
weak_factory_->GetWeakPtr(),
interface_name));
}
return true;
}
Expand Down Expand Up @@ -1106,7 +1105,7 @@ void RenderProcessHostImpl::CreateMessageFilters() {

void RenderProcessHostImpl::RegisterMojoInterfaces() {
std::unique_ptr<shell::InterfaceRegistry> registry(
new shell::InterfaceRegistry(nullptr));
new shell::InterfaceRegistry);
#if defined(OS_ANDROID)
interface_registry_android_ =
InterfaceRegistryAndroid::Create(registry.get());
Expand Down
2 changes: 1 addition & 1 deletion content/browser/service_worker/embedded_worker_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void EmbeddedWorkerInstance::Start(
status_ = EmbeddedWorkerStatus::STARTING;
starting_phase_ = ALLOCATING_PROCESS;
network_accessed_for_script_ = false;
interface_registry_.reset(new shell::InterfaceRegistry(nullptr));
interface_registry_.reset(new shell::InterfaceRegistry);
remote_interfaces_.reset(new shell::InterfaceProvider);
FOR_EACH_OBSERVER(Listener, listener_list_, OnStarting());

Expand Down
5 changes: 2 additions & 3 deletions content/browser/service_worker/embedded_worker_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper(
NewMessagePortMessageFilter());

// Setup process level interface registry.
render_process_interface_registry_.reset(
new shell::InterfaceRegistry(nullptr));
render_process_interface_registry_.reset(new shell::InterfaceRegistry);
render_process_interface_registry_->AddInterface(
base::Bind(&MockEmbeddedWorkerSetup::Create, weak_factory_.GetWeakPtr()));
shell::mojom::InterfaceProviderPtr interfaces;
Expand Down Expand Up @@ -420,7 +419,7 @@ void EmbeddedWorkerTestHelper::OnSetupMojoStub(
shell::mojom::InterfaceProviderRequest request,
shell::mojom::InterfaceProviderPtr remote_interfaces) {
std::unique_ptr<shell::InterfaceRegistry> local(
new shell::InterfaceRegistry(nullptr));
new shell::InterfaceRegistry);
local->Bind(std::move(request));

std::unique_ptr<shell::InterfaceProvider> remote(
Expand Down
2 changes: 1 addition & 1 deletion content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ MojoShellConnection* ChildThreadImpl::GetMojoShellConnection() {

shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() {
if (!interface_registry_.get())
interface_registry_.reset(new shell::InterfaceRegistry(nullptr));
interface_registry_.reset(new shell::InterfaceRegistry);
return interface_registry_.get();
}

Expand Down
Loading

0 comments on commit 8366b12

Please sign in to comment.