summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 22:35:51 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 22:35:51 +0000
commit5e1a832c8186ef29546b6b60f90d7974ca72d3c9 (patch)
tree41b3fd3eaf316e7353a566c2b8923566788dd446
parent92028f1406eeb252247b55b8db63b1b8cdf69945 (diff)
downloadchromium_src-5e1a832c8186ef29546b6b60f90d7974ca72d3c9.zip
chromium_src-5e1a832c8186ef29546b6b60f90d7974ca72d3c9.tar.gz
chromium_src-5e1a832c8186ef29546b6b60f90d7974ca72d3c9.tar.bz2
Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl
Interfaces no longer have explicit Peer attributes. An interface may now optionally have a Client interface, in which case a SetClient method will be auto-generated. InterfacePtr is a proxy to a remote instance of an interface. InterfaceImpl is a base class used when implementing an interface. Both have facilities for binding to a pipe, etc. An InterfacePtr is movable but not copyable and looks a lot like RemotePtr save for how it gets initialized (via the Bind method now). I've added some new top-level functions: MakeProxy - makes it easy to initialize an InterfacePtr in say a member initializer list. BindToPipe - this is how you bind an InterfaceImpl to a pipe. once bound, they cannot be unbound until the object is destroyed or the pipe is closed. BindToProxy - builds on top of BindToPipe, however, it hides the details of the pipe. What you get back is an InterfacePtr. Generated C++ code now passes InterfacePtr instead of InterfaceHandle. As a result, we have far less need for typed subclasses of MessagePipeHandle, so I eliminated them. The code that needs to deal with raw handles generally has to deal with {Scoped}MessagePipeHandle, and adding strong typing to these handles doesn't seem helpful anymore. R=davemoore@chromium.org Review URL: https://codereview.chromium.org/265793015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269443 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/webui/mojo_web_ui_controller.cc8
-rw-r--r--chrome/browser/ui/webui/omnibox/omnibox.mojom3
-rw-r--r--chrome/browser/ui/webui/omnibox/omnibox_ui.cc5
-rw-r--r--chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc9
-rw-r--r--chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h13
-rw-r--r--content/browser/mojo/mojo_application_host.cc17
-rw-r--r--content/browser/mojo/mojo_application_host.h29
-rw-r--r--content/browser/renderer_host/render_process_host_impl.h12
-rw-r--r--content/browser/renderer_host/render_view_host_impl.cc9
-rw-r--r--content/browser/webui/web_ui_mojo_browsertest.cc29
-rw-r--r--content/child/child_thread.h2
-rw-r--r--content/child/mojo/mojo_application.cc4
-rw-r--r--content/child/mojo/mojo_application.h3
-rw-r--r--content/renderer/web_ui_setup_impl.cc14
-rw-r--r--content/renderer/web_ui_setup_impl.h15
-rw-r--r--content/test/data/web_ui_test_mojo_bindings.mojom9
-rw-r--r--mojo/apps/js/test/js_to_cpp.mojom3
-rw-r--r--mojo/apps/js/test/js_to_cpp_unittest.cc32
-rw-r--r--mojo/aura/window_tree_host_mojo.cc6
-rw-r--r--mojo/aura/window_tree_host_mojo.h6
-rw-r--r--mojo/dbus/dbus_external_service.cc7
-rw-r--r--mojo/dbus/dbus_external_service.h46
-rw-r--r--mojo/examples/aura_demo/aura_demo.cc8
-rw-r--r--mojo/examples/compositor_app/compositor_app.cc19
-rw-r--r--mojo/examples/dbus_echo/dbus_echo_app.cc16
-rw-r--r--mojo/examples/launcher/launcher.cc42
-rw-r--r--mojo/examples/launcher/launcher.mojom3
-rw-r--r--mojo/examples/pepper_container_app/pepper_container_app.cc11
-rw-r--r--mojo/examples/sample_app/gles2_client_impl.h1
-rw-r--r--mojo/examples/sample_app/sample_app.cc21
-rw-r--r--mojo/gles2/command_buffer_client_impl.cc23
-rw-r--r--mojo/gles2/command_buffer_client_impl.h7
-rw-r--r--mojo/gles2/gles2_context.cc2
-rw-r--r--mojo/gles2/gles2_context.h3
-rw-r--r--mojo/gles2/gles2_support_impl.cc2
-rw-r--r--mojo/mojo.gyp7
-rw-r--r--mojo/mojo_public.gypi12
-rw-r--r--mojo/public/cpp/bindings/BUILD.gn6
-rw-r--r--mojo/public/cpp/bindings/error_handler.h12
-rw-r--r--mojo/public/cpp/bindings/interface.h92
-rw-r--r--mojo/public/cpp/bindings/interface_impl.h79
-rw-r--r--mojo/public/cpp/bindings/interface_ptr.h116
-rw-r--r--mojo/public/cpp/bindings/lib/array_internal.h1
-rw-r--r--mojo/public/cpp/bindings/lib/connector.cc12
-rw-r--r--mojo/public/cpp/bindings/lib/connector.h7
-rw-r--r--mojo/public/cpp/bindings/lib/interface_impl_internal.h72
-rw-r--r--mojo/public/cpp/bindings/lib/interface_ptr_internal.h108
-rw-r--r--mojo/public/cpp/bindings/lib/no_interface.cc (renamed from mojo/public/cpp/bindings/lib/interface.cc)2
-rw-r--r--mojo/public/cpp/bindings/lib/router.h8
-rw-r--r--mojo/public/cpp/bindings/no_interface.h52
-rw-r--r--mojo/public/cpp/bindings/remote_ptr.h161
-rw-r--r--mojo/public/cpp/bindings/sync_dispatcher.h10
-rw-r--r--mojo/public/cpp/bindings/tests/array_unittest.cc26
-rw-r--r--mojo/public/cpp/bindings/tests/handle_passing_unittest.cc155
-rw-r--r--mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc (renamed from mojo/public/cpp/bindings/tests/remote_ptr_unittest.cc)113
-rw-r--r--mojo/public/cpp/bindings/tests/request_response_unittest.cc38
-rw-r--r--mojo/public/cpp/bindings/tests/sample_service_unittest.cc32
-rw-r--r--mojo/public/cpp/shell/application.h8
-rw-r--r--mojo/public/cpp/shell/lib/application.cc4
-rw-r--r--mojo/public/cpp/shell/lib/service.cc5
-rw-r--r--mojo/public/cpp/shell/service.h125
-rw-r--r--mojo/public/interfaces/bindings/tests/math_calculator.mojom3
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_factory.mojom3
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_interfaces.mojom4
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_service.mojom5
-rw-r--r--mojo/public/interfaces/shell/shell.mojom3
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl21
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl14
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl6
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl4
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl9
-rw-r--r--mojo/public/tools/bindings/generators/mojom_cpp_generator.py13
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/data.py4
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/data_tests.py2
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/generator.py3
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/generate/module.py4
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/translate.py2
-rw-r--r--mojo/service_manager/background_service_loader.cc14
-rw-r--r--mojo/service_manager/background_service_loader.h4
-rw-r--r--mojo/service_manager/service_loader.h2
-rw-r--r--mojo/service_manager/service_manager.cc79
-rw-r--r--mojo/service_manager/service_manager.h9
-rw-r--r--mojo/service_manager/service_manager_unittest.cc60
-rw-r--r--mojo/service_manager/test.mojom3
-rw-r--r--mojo/services/dbus_echo/dbus_echo_service.cc5
-rw-r--r--mojo/services/dbus_echo/echo.mojom5
-rw-r--r--mojo/services/gles2/command_buffer.mojom4
-rw-r--r--mojo/services/gles2/command_buffer_impl.cc17
-rw-r--r--mojo/services/gles2/command_buffer_impl.h14
-rw-r--r--mojo/services/native_viewport/native_viewport.mojom3
-rw-r--r--mojo/services/native_viewport/native_viewport_service.cc39
-rw-r--r--mojo/services/native_viewport/native_viewport_service.h3
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc13
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h3
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom3
-rw-r--r--mojo/services/view_manager/main.cc8
-rw-r--r--mojo/services/view_manager/root_view_manager.cc10
-rw-r--r--mojo/services/view_manager/view_manager_connection.cc20
-rw-r--r--mojo/services/view_manager/view_manager_connection.h9
-rw-r--r--mojo/services/view_manager/view_manager_connection_unittest.cc20
-rw-r--r--mojo/shell/app_child_process.cc74
-rw-r--r--mojo/shell/app_child_process.mojom8
-rw-r--r--mojo/shell/app_child_process_host.cc11
-rw-r--r--mojo/shell/app_child_process_host.h9
-rw-r--r--mojo/shell/context.cc2
-rw-r--r--mojo/shell/dbus_service_loader_linux.cc16
-rw-r--r--mojo/shell/dbus_service_loader_linux.h2
-rw-r--r--mojo/shell/dynamic_service_loader.cc6
-rw-r--r--mojo/shell/dynamic_service_loader.h2
-rw-r--r--mojo/shell/dynamic_service_runner.h2
-rw-r--r--mojo/shell/external_service.mojom5
-rw-r--r--mojo/shell/in_process_dynamic_service_runner.cc2
-rw-r--r--mojo/shell/in_process_dynamic_service_runner.h4
-rw-r--r--mojo/shell/out_of_process_dynamic_service_runner.cc2
-rw-r--r--mojo/shell/out_of_process_dynamic_service_runner.h8
-rw-r--r--mojo/shell/shell_test_helper.cc5
-rw-r--r--mojo/shell/shell_test_helper.h3
-rw-r--r--mojo/shell/view_manager_loader.cc2
-rw-r--r--mojo/shell/view_manager_loader.h2
119 files changed, 1293 insertions, 1021 deletions
diff --git a/chrome/browser/ui/webui/mojo_web_ui_controller.cc b/chrome/browser/ui/webui/mojo_web_ui_controller.cc
index 099efaf..04ba05f 100644
--- a/chrome/browser/ui/webui/mojo_web_ui_controller.cc
+++ b/chrome/browser/ui/webui/mojo_web_ui_controller.cc
@@ -9,7 +9,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/bindings_policy.h"
-#include "mojo/public/cpp/bindings/interface.h"
+#include "mojo/public/cpp/system/core.h"
MojoWebUIController::MojoWebUIController(content::WebUI* contents)
: WebUIController(contents),
@@ -23,9 +23,9 @@ void MojoWebUIController::RenderViewCreated(
content::RenderViewHost* render_view_host) {
render_view_host->AllowBindings(content::BINDINGS_POLICY_WEB_UI);
- mojo::InterfacePipe<mojo::AnyInterface, mojo::AnyInterface> pipe;
- ui_handler_ = CreateUIHandler(pipe.handle_to_peer.Pass());
- render_view_host->SetWebUIHandle(pipe.handle_to_self.Pass());
+ mojo::MessagePipe pipe;
+ ui_handler_ = CreateUIHandler(pipe.handle0.Pass());
+ render_view_host->SetWebUIHandle(pipe.handle1.Pass());
}
void MojoWebUIController::AddMojoResourcePath(const std::string& path,
diff --git a/chrome/browser/ui/webui/omnibox/omnibox.mojom b/chrome/browser/ui/webui/omnibox/omnibox.mojom
index 5dcf32c..d7afd5d 100644
--- a/chrome/browser/ui/webui/omnibox/omnibox.mojom
+++ b/chrome/browser/ui/webui/omnibox/omnibox.mojom
@@ -47,7 +47,7 @@ struct OmniboxResultMojo {
AutocompleteResultsForProviderMojo[] results_by_provider;
};
-[Peer=OmniboxPage]
+[Client=OmniboxPage]
interface OmniboxUIHandlerMojo {
StartOmniboxQuery(string input_string,
int32 cursor_position,
@@ -56,7 +56,6 @@ interface OmniboxUIHandlerMojo {
int32 page_classification);
};
-[Peer=OmniboxUIHandlerMojo]
interface OmniboxPage {
HandleNewAutocompleteResult(OmniboxResultMojo result);
};
diff --git a/chrome/browser/ui/webui/omnibox/omnibox_ui.cc b/chrome/browser/ui/webui/omnibox/omnibox_ui.cc
index b288fc3..2ff94ac 100644
--- a/chrome/browser/ui/webui/omnibox/omnibox_ui.cc
+++ b/chrome/browser/ui/webui/omnibox/omnibox_ui.cc
@@ -31,7 +31,6 @@ OmniboxUI::~OmniboxUI() {}
scoped_ptr<MojoWebUIHandler> OmniboxUI::CreateUIHandler(
mojo::ScopedMessagePipeHandle handle_to_page) {
return scoped_ptr<MojoWebUIHandler>(
- new OmniboxUIHandler(
- ScopedOmniboxPageHandle::From(handle_to_page.Pass()).Pass(),
- Profile::FromWebUI(web_ui())));
+ mojo::BindToPipe(new OmniboxUIHandler(Profile::FromWebUI(web_ui())),
+ handle_to_page.Pass()));
}
diff --git a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc
index 14b0de7..e693765 100644
--- a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc
+++ b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc
@@ -111,9 +111,8 @@ class TypeConverter<AutocompleteResultsForProviderMojo, AutocompleteProvider*> {
} // namespace mojo
-OmniboxUIHandler::OmniboxUIHandler(ScopedOmniboxPageHandle handle,
- Profile* profile)
- : page_(handle.Pass(), this),
+OmniboxUIHandler::OmniboxUIHandler(Profile* profile)
+ : page_(NULL),
profile_(profile) {
ResetController();
}
@@ -163,6 +162,10 @@ bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host,
return true;
}
+void OmniboxUIHandler::SetClient(OmniboxPage* page) {
+ page_ = page;
+}
+
void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string,
int32_t cursor_position,
bool prevent_inline_autocomplete,
diff --git a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h
index 9538110..9cfea3a 100644
--- a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h
+++ b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h
@@ -14,7 +14,6 @@
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/ui/webui/mojo_web_ui_handler.h"
#include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
class AutocompleteController;
class Profile;
@@ -24,16 +23,22 @@ class Profile;
// AutocompleteController to OnResultChanged() and passes those results to
// the OmniboxPage.
class OmniboxUIHandler : public AutocompleteControllerDelegate,
- public OmniboxUIHandlerMojo,
+ public mojo::InterfaceImpl<OmniboxUIHandlerMojo>,
public MojoWebUIHandler {
public:
- OmniboxUIHandler(ScopedOmniboxPageHandle handle, Profile* profile);
+ explicit OmniboxUIHandler(Profile* profile);
virtual ~OmniboxUIHandler();
// AutocompleteControllerDelegate overrides:
virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
+ // ErrorHandler overrides:
+ virtual void OnConnectionError() OVERRIDE {
+ // TODO(darin): How should we handle connection error?
+ }
+
// OmniboxUIHandlerMojo overrides:
+ virtual void SetClient(OmniboxPage* page) OVERRIDE;
virtual void StartOmniboxQuery(const mojo::String& input_string,
int32_t cursor_position,
bool prevent_inline_autocomplete,
@@ -50,7 +55,7 @@ class OmniboxUIHandler : public AutocompleteControllerDelegate,
// next query.
void ResetController();
- mojo::RemotePtr<OmniboxPage> page_;
+ OmniboxPage* page_;
// The omnibox AutocompleteController that collects/sorts/dup-
// eliminates the results as they come in.
diff --git a/content/browser/mojo/mojo_application_host.cc b/content/browser/mojo/mojo_application_host.cc
index 48d343a..efe2ddf 100644
--- a/content/browser/mojo/mojo_application_host.cc
+++ b/content/browser/mojo/mojo_application_host.cc
@@ -30,7 +30,7 @@ MojoApplicationHost::~MojoApplicationHost() {
}
bool MojoApplicationHost::Init() {
- DCHECK(shell_client_.is_null()) << "Already initialized!";
+ DCHECK(!shell_.get()) << "Already initialized!";
mojo::embedder::PlatformChannelPair channel_pair;
@@ -43,10 +43,7 @@ bool MojoApplicationHost::Init() {
// Forward this to the client once we know its process handle.
client_handle_ = channel_pair.PassClientHandle();
- // TODO(darin): Provide a Shell implementation
- shell_client_.reset(
- mojo::ScopedShellClientHandle::From(message_pipe.Pass()), NULL);
-
+ shell_.reset(BindToPipe(new ShellImpl(), message_pipe.Pass()));
return true;
}
@@ -62,4 +59,14 @@ bool MojoApplicationHost::Activate(IPC::Sender* sender,
return did_activate_;
}
+void MojoApplicationHost::ShellImpl::SetClient(mojo::ShellClient* client) {
+ client_ = client;
+}
+
+void MojoApplicationHost::ShellImpl::Connect(
+ const mojo::String& url,
+ mojo::ScopedMessagePipeHandle handle) {
+ // TODO(darin): Provide something meaningful here.
+}
+
} // namespace content
diff --git a/content/browser/mojo/mojo_application_host.h b/content/browser/mojo/mojo_application_host.h
index 68f6c32..a28d2a3 100644
--- a/content/browser/mojo/mojo_application_host.h
+++ b/content/browser/mojo/mojo_application_host.h
@@ -8,7 +8,6 @@
#include "base/process/process_handle.h"
#include "mojo/common/channel_init.h"
#include "mojo/embedder/scoped_platform_handle.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
namespace IPC {
@@ -25,7 +24,7 @@ namespace content {
class MojoApplicationHost {
public:
MojoApplicationHost();
- ~MojoApplicationHost();
+ virtual ~MojoApplicationHost();
// Two-phase initialization:
// 1- Init makes the shell_client() available synchronously.
@@ -35,12 +34,34 @@ class MojoApplicationHost {
bool did_activate() const { return did_activate_; }
- mojo::ShellClient* shell_client() { return shell_client_.get(); }
+ mojo::ShellClient* shell_client() {
+ DCHECK(shell_.get());
+ return shell_->client();
+ }
private:
+ class ShellImpl : public mojo::InterfaceImpl<mojo::Shell> {
+ public:
+ ShellImpl() : client_(NULL) {}
+ mojo::ShellClient* client() { return client_; }
+
+ virtual void OnConnectionError() OVERRIDE {
+ // TODO(darin): How should we handle this error?
+ }
+
+ // mojo::Shell methods:
+ virtual void SetClient(mojo::ShellClient* client) OVERRIDE;
+ virtual void Connect(const mojo::String& url,
+ mojo::ScopedMessagePipeHandle handle) OVERRIDE;
+ private:
+ mojo::ShellClient* client_;
+ };
+
mojo::common::ChannelInit channel_init_;
mojo::embedder::ScopedPlatformHandle client_handle_;
- mojo::RemotePtr<mojo::ShellClient> shell_client_;
+
+ scoped_ptr<ShellImpl> shell_;
+
bool did_activate_;
DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost);
diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h
index cddc4dc..358109f 100644
--- a/content/browser/renderer_host/render_process_host_impl.h
+++ b/content/browser/renderer_host/render_process_host_impl.h
@@ -21,9 +21,7 @@
#include "content/public/browser/render_process_host.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_platform_file.h"
-#include "mojo/embedder/scoped_platform_handle.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
-#include "mojo/public/interfaces/shell/shell.mojom.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params;
@@ -245,6 +243,14 @@ class CONTENT_EXPORT RenderProcessHostImpl
void ConnectTo(const base::StringPiece& service_name,
mojo::ScopedMessagePipeHandle handle);
+ template <typename Interface>
+ void ConnectTo(const base::StringPiece& service_name,
+ mojo::InterfacePtr<Interface>* ptr) {
+ mojo::MessagePipe pipe;
+ ptr->Bind(pipe.handle0.Pass());
+ ConnectTo(service_name, pipe.handle1.Pass());
+ }
+
protected:
// A proxy for our IPC::Channel that lives on the IO thread (see
// browser_process.h)
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
index c173bb9..49a17ef 100644
--- a/content/browser/renderer_host/render_view_host_impl.cc
+++ b/content/browser/renderer_host/render_view_host_impl.cc
@@ -687,12 +687,11 @@ void RenderViewHostImpl::SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) {
DCHECK(renderer_initialized_);
- mojo::InterfacePipe<WebUISetup, mojo::AnyInterface> pipe;
- mojo::RemotePtr<WebUISetup> web_ui_setup(pipe.handle_to_self.Pass(), NULL);
- web_ui_setup->SetWebUIHandle(GetRoutingID(), handle.Pass());
-
+ WebUISetupPtr web_ui_setup;
static_cast<RenderProcessHostImpl*>(GetProcess())->ConnectTo(
- kRendererService_WebUISetup, pipe.handle_to_peer.Pass());
+ kRendererService_WebUISetup, &web_ui_setup);
+
+ web_ui_setup->SetWebUIHandle(GetRoutingID(), handle.Pass());
}
#if defined(OS_ANDROID)
diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc
index 598dbe1..039db85 100644
--- a/content/browser/webui/web_ui_mojo_browsertest.cc
+++ b/content/browser/webui/web_ui_mojo_browsertest.cc
@@ -25,7 +25,6 @@
#include "grit/content_resources.h"
#include "mojo/common/test/test_utils.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/js/bindings/constants.h"
namespace content {
@@ -54,23 +53,24 @@ bool GetResource(const std::string& id,
return true;
}
-class BrowserTargetImpl : public mojo::BrowserTarget {
+class BrowserTargetImpl : public BrowserTarget {
public:
- BrowserTargetImpl(mojo::ScopedRendererTargetHandle& handle,
+ BrowserTargetImpl(mojo::ScopedMessagePipeHandle handle,
base::RunLoop* run_loop)
- : client_(handle.Pass(), this),
+ : renderer_(mojo::MakeProxy<RendererTarget>(handle.Pass())),
run_loop_(run_loop) {
+ renderer_->SetClient(this);
}
virtual ~BrowserTargetImpl() {}
- // mojo::BrowserTarget overrides:
+ // BrowserTarget overrides:
virtual void PingResponse() OVERRIDE {
NOTREACHED();
}
protected:
- mojo::RemotePtr<mojo::RendererTarget> client_;
+ RendererTargetPtr renderer_;
base::RunLoop* run_loop_;
private:
@@ -79,15 +79,15 @@ class BrowserTargetImpl : public mojo::BrowserTarget {
class PingBrowserTargetImpl : public BrowserTargetImpl {
public:
- PingBrowserTargetImpl(mojo::ScopedRendererTargetHandle handle,
+ PingBrowserTargetImpl(mojo::ScopedMessagePipeHandle handle,
base::RunLoop* run_loop)
- : BrowserTargetImpl(handle, run_loop) {
- client_->Ping();
+ : BrowserTargetImpl(handle.Pass(), run_loop) {
+ renderer_->Ping();
}
virtual ~PingBrowserTargetImpl() {}
- // mojo::BrowserTarget overrides:
+ // BrowserTarget overrides:
// Quit the RunLoop when called.
virtual void PingResponse() OVERRIDE {
got_message = true;
@@ -128,11 +128,10 @@ class PingTestWebUIController : public TestWebUIController {
// WebUIController overrides:
virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE {
- mojo::InterfacePipe<mojo::BrowserTarget, mojo::RendererTarget> pipe;
- browser_target_.reset(new PingBrowserTargetImpl(
- pipe.handle_to_peer.Pass(), run_loop_));
- render_view_host->SetWebUIHandle(
- mojo::ScopedMessagePipeHandle(pipe.handle_to_self.release()));
+ mojo::MessagePipe pipe;
+ browser_target_.reset(
+ new PingBrowserTargetImpl(pipe.handle0.Pass(), run_loop_));
+ render_view_host->SetWebUIHandle(pipe.handle1.Pass());
}
private:
diff --git a/content/child/child_thread.h b/content/child/child_thread.h
index 8887e7a..1b04830 100644
--- a/content/child/child_thread.h
+++ b/content/child/child_thread.h
@@ -58,7 +58,7 @@ struct RequestInfo;
// The main thread of a child process derives from this class.
class CONTENT_EXPORT ChildThread : public IPC::Listener,
public IPC::Sender,
- public mojo::ShellClient {
+ public NON_EXPORTED_BASE(mojo::ShellClient) {
public:
// Creates the thread.
ChildThread();
diff --git a/content/child/mojo/mojo_application.cc b/content/child/mojo/mojo_application.cc
index 1d61c0b..5cec176 100644
--- a/content/child/mojo/mojo_application.cc
+++ b/content/child/mojo/mojo_application.cc
@@ -38,8 +38,8 @@ void MojoApplication::OnActivate(
ChildProcess::current()->io_message_loop_proxy());
DCHECK(message_pipe.is_valid());
- shell_.reset(
- mojo::ScopedShellHandle::From(message_pipe.Pass()), shell_client_);
+ shell_.Bind(message_pipe.Pass());
+ shell_->SetClient(shell_client_);
}
} // namespace content
diff --git a/content/child/mojo/mojo_application.h b/content/child/mojo/mojo_application.h
index fad9888..88646b6 100644
--- a/content/child/mojo/mojo_application.h
+++ b/content/child/mojo/mojo_application.h
@@ -7,7 +7,6 @@
#include "ipc/ipc_platform_file.h"
#include "mojo/common/channel_init.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
namespace IPC {
@@ -36,7 +35,7 @@ class MojoApplication {
void OnActivate(const IPC::PlatformFileForTransit& file);
mojo::common::ChannelInit channel_init_;
- mojo::RemotePtr<mojo::Shell> shell_;
+ mojo::ShellPtr shell_;
mojo::ShellClient* shell_client_;
DISALLOW_COPY_AND_ASSIGN(MojoApplication);
diff --git a/content/renderer/web_ui_setup_impl.cc b/content/renderer/web_ui_setup_impl.cc
index e4c065f..7cb7cda 100644
--- a/content/renderer/web_ui_setup_impl.cc
+++ b/content/renderer/web_ui_setup_impl.cc
@@ -11,15 +11,11 @@ namespace content {
// static
void WebUISetupImpl::Bind(mojo::ScopedMessagePipeHandle handle) {
- // This instance will be destroyed when the pipe is closed. See OnError.
- new WebUISetupImpl(handle.Pass());
+ mojo::BindToPipe(new WebUISetupImpl(), handle.Pass());
}
-WebUISetupImpl::WebUISetupImpl(mojo::ScopedMessagePipeHandle handle)
- : client_(ScopedWebUISetupClientHandle::From(handle.Pass()), this) {
-}
-
-WebUISetupImpl::~WebUISetupImpl() {
+void WebUISetupImpl::OnConnectionError() {
+ delete this;
}
void WebUISetupImpl::SetWebUIHandle(
@@ -34,8 +30,4 @@ void WebUISetupImpl::SetWebUIHandle(
web_ui_mojo->SetBrowserHandle(web_ui_handle.Pass());
}
-void WebUISetupImpl::OnError() {
- delete this;
-}
-
} // namespace content
diff --git a/content/renderer/web_ui_setup_impl.h b/content/renderer/web_ui_setup_impl.h
index 1bfc6ca..6523454 100644
--- a/content/renderer/web_ui_setup_impl.h
+++ b/content/renderer/web_ui_setup_impl.h
@@ -7,30 +7,23 @@
#include "base/basictypes.h"
#include "content/common/web_ui_setup.mojom.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
namespace content {
-class WebUISetupImpl : public WebUISetup,
- public mojo::ErrorHandler {
+class WebUISetupImpl : public mojo::InterfaceImpl<WebUISetup> {
public:
static void Bind(mojo::ScopedMessagePipeHandle handle);
private:
- explicit WebUISetupImpl(mojo::ScopedMessagePipeHandle handle);
- virtual ~WebUISetupImpl();
+ WebUISetupImpl() {}
+
+ virtual void OnConnectionError() OVERRIDE;
// WebUISetup methods:
virtual void SetWebUIHandle(
int32_t view_routing_id,
mojo::ScopedMessagePipeHandle web_ui_handle) OVERRIDE;
- // mojo::ErrorHandler methods:
- virtual void OnError() OVERRIDE;
-
- mojo::RemotePtr<WebUISetupClient> client_;
-
DISALLOW_COPY_AND_ASSIGN(WebUISetupImpl);
};
diff --git a/content/test/data/web_ui_test_mojo_bindings.mojom b/content/test/data/web_ui_test_mojo_bindings.mojom
index 67d5983..9cac34e 100644
--- a/content/test/data/web_ui_test_mojo_bindings.mojom
+++ b/content/test/data/web_ui_test_mojo_bindings.mojom
@@ -1,11 +1,14 @@
-module mojo {
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module content {
-[Peer=RendererTarget]
interface BrowserTarget {
PingResponse();
};
-[Peer=BrowserTarget]
+[Client=BrowserTarget]
interface RendererTarget {
Ping();
};
diff --git a/mojo/apps/js/test/js_to_cpp.mojom b/mojo/apps/js/test/js_to_cpp.mojom
index a432eb8..509f2f7 100644
--- a/mojo/apps/js/test/js_to_cpp.mojom
+++ b/mojo/apps/js/test/js_to_cpp.mojom
@@ -23,7 +23,6 @@ struct EchoArgs {
handle<data_pipe_consumer> data_handle;
};
-[Peer=JsSide]
interface CppSide {
StartTest(); // Sent for all tests to notify that the JS side is now ready.
TestFinished(); // Sent in echo / bit-flip tests to indicate end.
@@ -32,7 +31,7 @@ interface CppSide {
BitFlipResponse(EchoArgs arg);
};
-[Peer=CppSide]
+[Client=CppSide]
interface JsSide {
Ping();
Echo(int32 numIterations, EchoArgs arg);
diff --git a/mojo/apps/js/test/js_to_cpp_unittest.cc b/mojo/apps/js/test/js_to_cpp_unittest.cc
index a0df09a..89e3d2e 100644
--- a/mojo/apps/js/test/js_to_cpp_unittest.cc
+++ b/mojo/apps/js/test/js_to_cpp_unittest.cc
@@ -13,7 +13,6 @@
#include "mojo/common/common_type_converters.h"
#include "mojo/common/test/test_utils.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
@@ -114,15 +113,15 @@ void CheckSampleEchoArgs(const js_to_cpp::EchoArgs& arg) {
// run_loop().
class CppSideConnection : public js_to_cpp::CppSide {
public:
- CppSideConnection() : run_loop_(NULL), client_(NULL) {
+ CppSideConnection() : run_loop_(NULL), js_side_(NULL) {
}
virtual ~CppSideConnection() {}
void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; }
base::RunLoop* run_loop() { return run_loop_; }
- void set_client(js_to_cpp::JsSide* client) { client_ = client; }
- js_to_cpp::JsSide* client() { return client_; }
+ void set_js_side(js_to_cpp::JsSide* js_side) { js_side_ = js_side; }
+ js_to_cpp::JsSide* js_side() { return js_side_; }
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
@@ -148,7 +147,7 @@ class CppSideConnection : public js_to_cpp::CppSide {
protected:
base::RunLoop* run_loop_;
- js_to_cpp::JsSide* client_;
+ js_to_cpp::JsSide* js_side_;
private:
Environment environment;
@@ -163,7 +162,7 @@ class PingCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
- client_->Ping();
+ js_side_->Ping();
}
virtual void PingResponse() OVERRIDE {
@@ -192,7 +191,7 @@ class EchoCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
AllocationScope scope;
- client_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
+ js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
}
virtual void EchoResponse(const js_to_cpp::EchoArgs& arg1,
@@ -231,7 +230,7 @@ class BitFlipCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
AllocationScope scope;
- client_->BitFlip(BuildSampleEchoArgs());
+ js_side_->BitFlip(BuildSampleEchoArgs());
}
virtual void BitFlipResponse(const js_to_cpp::EchoArgs& arg1) OVERRIDE {
@@ -260,18 +259,21 @@ class JsToCppTest : public testing::Test {
void RunTest(const std::string& test, CppSideConnection* cpp_side) {
cpp_side->set_run_loop(&run_loop_);
- InterfacePipe<js_to_cpp::CppSide, js_to_cpp::JsSide> pipe;
- RemotePtr<js_to_cpp::JsSide> js_side;
- js_side.reset(pipe.handle_to_peer.Pass(), cpp_side);
- js_side.router_for_testing()->
+
+ MessagePipe pipe;
+ js_to_cpp::JsSidePtr js_side =
+ MakeProxy<js_to_cpp::JsSide>(pipe.handle0.Pass());
+ js_side->SetClient(cpp_side);
+
+ js_side.internal_state()->router()->
set_enforce_errors_from_incoming_receiver(false);
- cpp_side->set_client(js_side.get());
+
+ cpp_side->set_js_side(js_side.get());
gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode);
apps::MojoRunnerDelegate delegate;
gin::ShellRunner runner(&delegate, instance.isolate());
- delegate.Start(&runner, pipe.handle_to_self.release().value(),
- test);
+ delegate.Start(&runner, pipe.handle1.release().value(), test);
run_loop_.Run();
}
diff --git a/mojo/aura/window_tree_host_mojo.cc b/mojo/aura/window_tree_host_mojo.cc
index b623bbd..9aba1d8 100644
--- a/mojo/aura/window_tree_host_mojo.cc
+++ b/mojo/aura/window_tree_host_mojo.cc
@@ -26,12 +26,14 @@ mojo::ContextFactoryMojo* WindowTreeHostMojo::context_factory_ = NULL;
// WindowTreeHostMojo, public:
WindowTreeHostMojo::WindowTreeHostMojo(
- ScopedNativeViewportHandle viewport_handle,
+ NativeViewportPtr viewport,
const gfx::Rect& bounds,
const base::Callback<void()>& compositor_created_callback)
- : native_viewport_(viewport_handle.Pass(), this),
+ : native_viewport_(viewport.Pass()),
compositor_created_callback_(compositor_created_callback),
bounds_(bounds) {
+ native_viewport_->SetClient(this);
+
AllocationScope scope;
native_viewport_->Create(bounds);
diff --git a/mojo/aura/window_tree_host_mojo.h b/mojo/aura/window_tree_host_mojo.h
index c53e884..1a02b77 100644
--- a/mojo/aura/window_tree_host_mojo.h
+++ b/mojo/aura/window_tree_host_mojo.h
@@ -6,8 +6,6 @@
#define MOJO_AURA_WINDOW_TREE_HOST_MOJO_H_
#include "base/bind.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/services/native_viewport/native_viewport.mojom.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event_source.h"
@@ -25,7 +23,7 @@ class WindowTreeHostMojo : public aura::WindowTreeHost,
public ui::EventSource,
public NativeViewportClient {
public:
- WindowTreeHostMojo(ScopedNativeViewportHandle viewport_handle,
+ WindowTreeHostMojo(NativeViewportPtr viewport,
const gfx::Rect& bounds,
const base::Callback<void()>& compositor_created_callback);
virtual ~WindowTreeHostMojo();
@@ -61,7 +59,7 @@ class WindowTreeHostMojo : public aura::WindowTreeHost,
static ContextFactoryMojo* context_factory_;
- RemotePtr<NativeViewport> native_viewport_;
+ NativeViewportPtr native_viewport_;
base::Callback<void()> compositor_created_callback_;
gfx::Rect bounds_;
diff --git a/mojo/dbus/dbus_external_service.cc b/mojo/dbus/dbus_external_service.cc
index 3a13cf7..92cd6f3 100644
--- a/mojo/dbus/dbus_external_service.cc
+++ b/mojo/dbus/dbus_external_service.cc
@@ -16,7 +16,6 @@
#include "dbus/object_path.h"
#include "mojo/common/channel_init.h"
#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/shell/external_service.mojom.h"
@@ -37,10 +36,6 @@ void DBusExternalServiceBase::Start() {
DVLOG(1) << "External service started";
}
-void DBusExternalServiceBase::OnError() {
- Disconnect();
-}
-
void DBusExternalServiceBase::ConnectChannel(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender sender) {
@@ -61,7 +56,7 @@ void DBusExternalServiceBase::ConnectChannel(
base::MessageLoopProxy::current());
CHECK(message_pipe.is_valid());
- Connect(mojo::ScopedExternalServiceHostHandle::From(message_pipe.Pass()));
+ Connect(message_pipe.Pass());
sender.Run(dbus::Response::FromMethodCall(method_call));
}
diff --git a/mojo/dbus/dbus_external_service.h b/mojo/dbus/dbus_external_service.h
index 1a33c4c7..c3e20e1 100644
--- a/mojo/dbus/dbus_external_service.h
+++ b/mojo/dbus/dbus_external_service.h
@@ -8,8 +8,6 @@
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "mojo/common/channel_init.h"
-#include "mojo/public/cpp/bindings/interface.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/shell/external_service.mojom.h"
@@ -19,7 +17,7 @@ const char kMojoDBusImplPath[] = "/org/chromium/MojoImpl";
const char kMojoDBusInterface[] = "org.chromium.Mojo";
const char kMojoDBusConnectMethod[] = "ConnectChannel";
-class DBusExternalServiceBase : public mojo::ErrorHandler {
+class DBusExternalServiceBase {
public:
explicit DBusExternalServiceBase(const std::string& service_name);
virtual ~DBusExternalServiceBase();
@@ -28,15 +26,13 @@ class DBusExternalServiceBase : public mojo::ErrorHandler {
protected:
// TODO(cmasone): Enable multiple peers to connect/disconnect
- virtual void Connect(ScopedExternalServiceHostHandle client_handle) = 0;
+ virtual void Connect(ScopedMessagePipeHandle client_handle) = 0;
virtual void Disconnect() = 0;
private:
- virtual void OnError() OVERRIDE;
-
// Implementation of org.chromium.Mojo.ConnectChannel, exported over DBus.
// Takes a file descriptor and uses it to create a MessagePipe that is then
- // hooked to a RemotePtr<mojo::ExternalServiceHost>.
+ // hooked to an implementation of ExternalService.
void ConnectChannel(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender sender);
@@ -47,13 +43,12 @@ class DBusExternalServiceBase : public mojo::ErrorHandler {
const std::string service_name_;
scoped_refptr<dbus::Bus> bus_;
dbus::ExportedObject* exported_object_; // Owned by bus_;
- scoped_ptr<mojo::common::ChannelInit> channel_init_;
+ scoped_ptr<common::ChannelInit> channel_init_;
DISALLOW_COPY_AND_ASSIGN(DBusExternalServiceBase);
};
template <class ServiceImpl>
-class DBusExternalService : public DBusExternalServiceBase,
- public mojo::ExternalService {
+class DBusExternalService : public DBusExternalServiceBase {
public:
explicit DBusExternalService(const std::string& service_name)
: DBusExternalServiceBase(service_name) {
@@ -61,25 +56,32 @@ class DBusExternalService : public DBusExternalServiceBase,
virtual ~DBusExternalService() {}
protected:
- virtual void Connect(ScopedExternalServiceHostHandle client_handle) OVERRIDE {
- external_service_host_.reset(client_handle.Pass(), this, this);
+ virtual void Connect(ScopedMessagePipeHandle client_handle) OVERRIDE {
+ external_service_.reset(BindToPipe(new Impl(this), client_handle.Pass()));
}
virtual void Disconnect() OVERRIDE {
- app_.reset();
- external_service_host_.reset();
+ external_service_.reset();
}
private:
- virtual void Activate(mojo::ScopedMessagePipeHandle client_handle) OVERRIDE {
- mojo::ScopedShellHandle shell_handle(
- mojo::ShellHandle(client_handle.release().value()));
- app_.reset(new mojo::Application(shell_handle.Pass()));
- app_->AddServiceConnector(new mojo::ServiceConnector<ServiceImpl>());
- }
+ class Impl : public InterfaceImpl<ExternalService> {
+ public:
+ explicit Impl(DBusExternalService* service) : service_(service) {
+ }
+ virtual void OnConnectionError() OVERRIDE {
+ service_->Disconnect();
+ }
+ virtual void Activate(ScopedMessagePipeHandle shell_handle) OVERRIDE {
+ app_.reset(new Application(shell_handle.Pass()));
+ app_->AddServiceConnector(new ServiceConnector<ServiceImpl>());
+ }
+ private:
+ DBusExternalService* service_;
+ scoped_ptr<Application> app_;
+ };
- mojo::RemotePtr<mojo::ExternalServiceHost> external_service_host_;
- scoped_ptr<mojo::Application> app_;
+ scoped_ptr<Impl> external_service_;
};
} // namespace mojo
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index 14f00f5..46879d9 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -117,13 +117,11 @@ class AuraDemo : public Application {
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
- InterfacePipe<NativeViewport, AnyInterface> pipe;
+ NativeViewportPtr native_viewport;
+ ConnectTo("mojo:mojo_native_viewport_service", &native_viewport);
- mojo::AllocationScope scope;
- shell()->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
window_tree_host_.reset(new WindowTreeHostMojo(
- pipe.handle_to_self.Pass(),
+ native_viewport.Pass(),
gfx::Rect(800, 600),
base::Bind(&AuraDemo::HostContextCreated, base::Unretained(this))));
}
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
index dbeff85..3339804 100644
--- a/mojo/examples/compositor_app/compositor_app.cc
+++ b/mojo/examples/compositor_app/compositor_app.cc
@@ -9,7 +9,6 @@
#include "base/message_loop/message_loop.h"
#include "mojo/examples/compositor_app/compositor_host.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/cpp/system/core.h"
@@ -34,21 +33,17 @@ namespace examples {
class SampleApp : public Application, public NativeViewportClient {
public:
explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
- InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
-
AllocationScope scope;
- shell()->Connect("mojo:mojo_native_viewport_service",
- viewport_pipe.handle_to_peer.Pass());
- viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
+ ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ viewport_->SetClient(this);
+
viewport_->Create(gfx::Rect(10, 10, 800, 600));
viewport_->Show();
- ScopedMessagePipeHandle gles2_handle;
- ScopedMessagePipeHandle gles2_client_handle;
- CreateMessagePipe(&gles2_handle, &gles2_client_handle);
- viewport_->CreateGLES2Context(gles2_client_handle.Pass());
- host_.reset(new CompositorHost(gles2_handle.Pass()));
+ MessagePipe gles2_pipe;
+ viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass());
+ host_.reset(new CompositorHost(gles2_pipe.handle1.Pass()));
}
virtual void OnCreated() OVERRIDE {
@@ -68,7 +63,7 @@ class SampleApp : public Application, public NativeViewportClient {
}
private:
- RemotePtr<NativeViewport> viewport_;
+ NativeViewportPtr viewport_;
scoped_ptr<CompositorHost> host_;
};
diff --git a/mojo/examples/dbus_echo/dbus_echo_app.cc b/mojo/examples/dbus_echo/dbus_echo_app.cc
index 459ad21..13bf8e0 100644
--- a/mojo/examples/dbus_echo/dbus_echo_app.cc
+++ b/mojo/examples/dbus_echo/dbus_echo_app.cc
@@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/logging.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/cpp/system/core.h"
@@ -30,14 +29,13 @@
namespace mojo {
namespace examples {
-class DBusEchoApp : public Application, public mojo::EchoClient {
+class DBusEchoApp : public Application {
public:
explicit DBusEchoApp(MojoHandle shell_handle) : Application(shell_handle) {
- InterfacePipe<EchoService, AnyInterface> echo_pipe;
- mojo::AllocationScope scope;
- shell()->Connect("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
- echo_pipe.handle_to_peer.Pass());
- echo_service_.reset(echo_pipe.handle_to_self.Pass(), this);
+ ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
+ &echo_service_);
+
+ AllocationScope scope;
echo_service_->Echo("who", base::Bind(&DBusEchoApp::OnEcho,
base::Unretained(this)));
}
@@ -46,11 +44,11 @@ class DBusEchoApp : public Application, public mojo::EchoClient {
}
private:
- void OnEcho(const mojo::String& echoed) {
+ void OnEcho(const String& echoed) {
LOG(INFO) << "echo'd " << echoed.To<std::string>();
}
- RemotePtr<EchoService> echo_service_;
+ EchoServicePtr echo_service_;
};
} // namespace examples
diff --git a/mojo/examples/launcher/launcher.cc b/mojo/examples/launcher/launcher.cc
index a02effc..cbee9d7 100644
--- a/mojo/examples/launcher/launcher.cc
+++ b/mojo/examples/launcher/launcher.cc
@@ -16,7 +16,6 @@
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/examples/launcher/launcher.mojom.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/cpp/system/core.h"
@@ -189,38 +188,32 @@ class LauncherController : public views::TextfieldController {
DISALLOW_COPY_AND_ASSIGN(LauncherController);
};
-class LauncherImpl : public Application,
- public Launcher,
+class LauncherImpl : public ServiceConnection<Launcher, LauncherImpl>,
public URLReceiver {
public:
- explicit LauncherImpl(MojoHandle shell_handle)
- : Application(shell_handle),
- launcher_controller_(this),
+ LauncherImpl()
+ : launcher_controller_(this),
+ launcher_client_(NULL),
pending_show_(false) {
+ }
+
+ void Initialize() {
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
- InterfacePipe<NativeViewport, AnyInterface> pipe;
-
- AllocationScope scope;
- shell()->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
+ NativeViewportPtr viewport;
+ ConnectTo(shell(), "mojo:mojo_native_viewport_service", &viewport);
window_tree_host_.reset(new WindowTreeHostMojo(
- pipe.handle_to_self.Pass(), gfx::Rect(50, 50, 450, 60),
+ viewport.Pass(), gfx::Rect(50, 50, 450, 60),
base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this))));
}
private:
- // Overridden from Application:
- virtual void AcceptConnection(const mojo::String& url,
- ScopedMessagePipeHandle handle) OVERRIDE {
- launcher_client_.reset(
- MakeScopedHandle(LauncherClientHandle(handle.release().value())).Pass(),
- this);
- }
-
// Overridden from Launcher:
+ virtual void SetClient(LauncherClient* client) OVERRIDE {
+ launcher_client_ = client;
+ }
virtual void Show() OVERRIDE {
if (!window_tree_host_.get()) {
pending_show_ = true;
@@ -269,7 +262,7 @@ class LauncherImpl : public Application,
LauncherController launcher_controller_;
- RemotePtr<LauncherClient> launcher_client_;
+ LauncherClient* launcher_client_;
scoped_ptr<aura::WindowTreeHost> window_tree_host_;
bool pending_show_;
@@ -297,8 +290,11 @@ extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain(
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance(true);
- mojo::examples::LauncherImpl launcher(shell_handle);
- loop.Run();
+ mojo::Application app(shell_handle);
+ app.AddServiceConnector(
+ new mojo::ServiceConnector<mojo::examples::LauncherImpl>());
+
+ loop.Run();
return MOJO_RESULT_OK;
}
diff --git a/mojo/examples/launcher/launcher.mojom b/mojo/examples/launcher/launcher.mojom
index e4e64cb..f3ec257 100644
--- a/mojo/examples/launcher/launcher.mojom
+++ b/mojo/examples/launcher/launcher.mojom
@@ -4,13 +4,12 @@
module mojo {
-[Peer=LauncherClient]
+[Client=LauncherClient]
interface Launcher {
Show();
Hide();
};
-[Peer=Launcher]
interface LauncherClient {
// Called when the user has requested |url| be launched.
OnURLEntered(string url);
diff --git a/mojo/examples/pepper_container_app/pepper_container_app.cc b/mojo/examples/pepper_container_app/pepper_container_app.cc
index 4100507..db2fad4 100644
--- a/mojo/examples/pepper_container_app/pepper_container_app.cc
+++ b/mojo/examples/pepper_container_app/pepper_container_app.cc
@@ -12,7 +12,6 @@
#include "mojo/examples/pepper_container_app/plugin_module.h"
#include "mojo/examples/pepper_container_app/type_converters.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/shell/application.h"
@@ -43,11 +42,11 @@ class PepperContainerApp: public Application,
: Application(shell_handle),
ppapi_globals_(this),
plugin_module_(new PluginModule) {
- InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
mojo::AllocationScope scope;
- shell()->Connect("mojo:mojo_native_viewport_service",
- viewport_pipe.handle_to_peer.Pass());
- viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
+
+ ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ viewport_->SetClient(this);
+
Rect::Builder rect;
Point::Builder point;
point.set_x(10);
@@ -110,7 +109,7 @@ class PepperContainerApp: public Application,
private:
MojoPpapiGlobals ppapi_globals_;
- RemotePtr<NativeViewport> viewport_;
+ NativeViewportPtr viewport_;
scoped_refptr<PluginModule> plugin_module_;
scoped_ptr<PluginInstance> plugin_instance_;
diff --git a/mojo/examples/sample_app/gles2_client_impl.h b/mojo/examples/sample_app/gles2_client_impl.h
index e0cb95db..08b2a3e 100644
--- a/mojo/examples/sample_app/gles2_client_impl.h
+++ b/mojo/examples/sample_app/gles2_client_impl.h
@@ -7,7 +7,6 @@
#include "mojo/examples/sample_app/spinning_cube.h"
#include "mojo/public/c/gles2/gles2.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/services/native_viewport/native_viewport.mojom.h"
#include "ui/gfx/point_f.h"
#include "ui/gfx/size.h"
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index f45a4dd..27e8796 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -7,7 +7,6 @@
#include "mojo/examples/sample_app/gles2_client_impl.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/shell/application.h"
@@ -30,14 +29,14 @@
namespace mojo {
namespace examples {
-class SampleApp : public Application, public mojo::NativeViewportClient {
+class SampleApp : public Application, public NativeViewportClient {
public:
explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
- InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
- mojo::AllocationScope scope;
- shell()->Connect("mojo:mojo_native_viewport_service",
- viewport_pipe.handle_to_peer.Pass());
- viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
+ ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ viewport_->SetClient(this);
+
+ AllocationScope scope;
+
Rect::Builder rect;
Point::Builder point;
point.set_x(10);
@@ -51,8 +50,8 @@ class SampleApp : public Application, public mojo::NativeViewportClient {
viewport_->Show();
MessagePipe gles2_pipe;
- viewport_->CreateGLES2Context(gles2_pipe.handle1.Pass());
- gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle0.Pass()));
+ viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass());
+ gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass()));
}
virtual ~SampleApp() {
@@ -72,7 +71,7 @@ class SampleApp : public Application, public mojo::NativeViewportClient {
}
virtual void OnEvent(const Event& event,
- const mojo::Callback<void()>& callback) MOJO_OVERRIDE {
+ const Callback<void()>& callback) MOJO_OVERRIDE {
if (!event.location().is_null())
gles2_client_->HandleInputEvent(event);
callback.Run();
@@ -80,7 +79,7 @@ class SampleApp : public Application, public mojo::NativeViewportClient {
private:
scoped_ptr<GLES2ClientImpl> gles2_client_;
- RemotePtr<NativeViewport> viewport_;
+ NativeViewportPtr viewport_;
};
} // namespace examples
diff --git a/mojo/gles2/command_buffer_client_impl.cc b/mojo/gles2/command_buffer_client_impl.cc
index 8beef82..9c05f4f 100644
--- a/mojo/gles2/command_buffer_client_impl.cc
+++ b/mojo/gles2/command_buffer_client_impl.cc
@@ -50,13 +50,17 @@ void CommandBufferDelegate::DrawAnimationFrame() {}
CommandBufferClientImpl::CommandBufferClientImpl(
CommandBufferDelegate* delegate,
MojoAsyncWaiter* async_waiter,
- ScopedCommandBufferHandle command_buffer_handle)
+ ScopedMessagePipeHandle command_buffer_handle)
: delegate_(delegate),
- command_buffer_(command_buffer_handle.Pass(), this, this, async_waiter),
+ command_buffer_(MakeProxy<mojo::CommandBuffer>(
+ command_buffer_handle.Pass(), async_waiter)),
shared_state_(NULL),
last_put_offset_(-1),
next_transfer_buffer_id_(0),
- initialize_result_(false) {}
+ initialize_result_(false) {
+ command_buffer_.set_error_handler(this);
+ command_buffer_->SetClient(this);
+}
CommandBufferClientImpl::~CommandBufferClientImpl() {}
@@ -73,11 +77,14 @@ bool CommandBufferClientImpl::Initialize() {
shared_state()->Initialize();
- InterfacePipe<CommandBufferSyncClient, NoInterface> sync_pipe;
+ // TODO(darin): We need better sugar for sync calls.
+ MessagePipe sync_pipe;
sync_dispatcher_.reset(new SyncDispatcher<CommandBufferSyncClient>(
- sync_pipe.handle_to_peer.Pass(), this));
+ sync_pipe.handle0.Pass(), this));
+ CommandBufferSyncClientPtr sync_client =
+ MakeProxy<CommandBufferSyncClient>(sync_pipe.handle1.Pass());
AllocationScope scope;
- command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), duped.Pass());
+ command_buffer_->Initialize(sync_client.Pass(), duped.Pass());
// Wait for DidInitialize to come on the sync client pipe.
if (!sync_dispatcher_->WaitAndDispatchOneMessage()) {
VLOG(1) << "Channel encountered error while creating command buffer";
@@ -243,7 +250,9 @@ void CommandBufferClientImpl::LostContext(int32_t lost_reason) {
delegate_->ContextLost();
}
-void CommandBufferClientImpl::OnError() { LostContext(gpu::error::kUnknown); }
+void CommandBufferClientImpl::OnConnectionError() {
+ LostContext(gpu::error::kUnknown);
+}
void CommandBufferClientImpl::TryUpdateState() {
if (last_state_.error == gpu::error::kNoError)
diff --git a/mojo/gles2/command_buffer_client_impl.h b/mojo/gles2/command_buffer_client_impl.h
index c867e4d..5b67524 100644
--- a/mojo/gles2/command_buffer_client_impl.h
+++ b/mojo/gles2/command_buffer_client_impl.h
@@ -13,7 +13,6 @@
#include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/command_buffer_shared.h"
#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/services/gles2/command_buffer.mojom.h"
namespace base {
@@ -43,7 +42,7 @@ class CommandBufferClientImpl : public CommandBufferClient,
explicit CommandBufferClientImpl(
CommandBufferDelegate* delegate,
MojoAsyncWaiter* async_waiter,
- ScopedCommandBufferHandle command_buffer_handle);
+ ScopedMessagePipeHandle command_buffer_handle);
virtual ~CommandBufferClientImpl();
// CommandBuffer implementation:
@@ -88,7 +87,7 @@ class CommandBufferClientImpl : public CommandBufferClient,
virtual void LostContext(int32_t lost_reason) OVERRIDE;
// ErrorHandler implementation:
- virtual void OnError() OVERRIDE;
+ virtual void OnConnectionError() OVERRIDE;
virtual void DrawAnimationFrame() OVERRIDE;
@@ -98,7 +97,7 @@ class CommandBufferClientImpl : public CommandBufferClient,
gpu::CommandBufferSharedState* shared_state() const { return shared_state_; }
CommandBufferDelegate* delegate_;
- RemotePtr<mojo::CommandBuffer> command_buffer_;
+ CommandBufferPtr command_buffer_;
scoped_ptr<SyncDispatcher<CommandBufferSyncClient> > sync_dispatcher_;
State last_state_;
diff --git a/mojo/gles2/gles2_context.cc b/mojo/gles2/gles2_context.cc
index 306ffeb..78e5168 100644
--- a/mojo/gles2/gles2_context.cc
+++ b/mojo/gles2/gles2_context.cc
@@ -21,7 +21,7 @@ const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
}
GLES2Context::GLES2Context(MojoAsyncWaiter* async_waiter,
- ScopedCommandBufferHandle command_buffer_handle,
+ ScopedMessagePipeHandle command_buffer_handle,
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure)
diff --git a/mojo/gles2/gles2_context.h b/mojo/gles2/gles2_context.h
index 02c051e..9f5ff7d 100644
--- a/mojo/gles2/gles2_context.h
+++ b/mojo/gles2/gles2_context.h
@@ -10,7 +10,6 @@
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "mojo/gles2/command_buffer_client_impl.h"
#include "mojo/public/c/gles2/gles2.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
struct MojoGLES2ContextPrivate {};
@@ -29,7 +28,7 @@ class GLES2Context : public CommandBufferDelegate,
public MojoGLES2ContextPrivate {
public:
explicit GLES2Context(MojoAsyncWaiter* async_waiter,
- ScopedCommandBufferHandle command_buffer_handle,
+ ScopedMessagePipeHandle command_buffer_handle,
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure);
diff --git a/mojo/gles2/gles2_support_impl.cc b/mojo/gles2/gles2_support_impl.cc
index 888cfde..c348219 100644
--- a/mojo/gles2/gles2_support_impl.cc
+++ b/mojo/gles2/gles2_support_impl.cc
@@ -63,7 +63,7 @@ MojoGLES2Context GLES2SupportImpl::CreateContext(
MojoGLES2ContextLost lost_callback,
MojoGLES2DrawAnimationFrame animation_callback,
void* closure) {
- ScopedCommandBufferHandle scoped_handle(CommandBufferHandle(handle.value()));
+ ScopedMessagePipeHandle scoped_handle(handle);
scoped_ptr<GLES2Context> client(new GLES2Context(async_waiter_,
scoped_handle.Pass(),
lost_callback,
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 8eea547..491d8ab 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -75,6 +75,12 @@
'mojo_test_apk',
],
}],
+ ['OS == "linux"', {
+ 'dependencies': [
+ 'mojo_dbus_echo',
+ 'mojo_dbus_echo_service',
+ ],
+ }],
]
},
{
@@ -521,6 +527,7 @@
'mojo_gles2',
'mojo_shell_client',
'mojo_view_manager',
+ 'mojo_view_manager_bindings',
],
}, { # use_aura==0
'sources!': [
diff --git a/mojo/mojo_public.gypi b/mojo/mojo_public.gypi
index f3a8a1d..2e17c30 100644
--- a/mojo/mojo_public.gypi
+++ b/mojo/mojo_public.gypi
@@ -130,10 +130,11 @@
'public/cpp/bindings/tests/buffer_unittest.cc',
'public/cpp/bindings/tests/connector_unittest.cc',
'public/cpp/bindings/tests/handle_passing_unittest.cc',
- 'public/cpp/bindings/tests/remote_ptr_unittest.cc',
+ 'public/cpp/bindings/tests/interface_ptr_unittest.cc',
'public/cpp/bindings/tests/request_response_unittest.cc',
'public/cpp/bindings/tests/router_unittest.cc',
'public/cpp/bindings/tests/sample_service_unittest.cc',
+ 'public/cpp/bindings/tests/test_bindings_utils.h',
'public/cpp/bindings/tests/type_conversion_unittest.cc',
'public/cpp/bindings/tests/validation_unittest.cc',
],
@@ -223,10 +224,11 @@
'public/cpp/bindings/buffer.h',
'public/cpp/bindings/callback.h',
'public/cpp/bindings/error_handler.h',
- 'public/cpp/bindings/interface.h',
+ 'public/cpp/bindings/interface_ptr.h',
+ 'public/cpp/bindings/interface_server.h',
'public/cpp/bindings/message.h',
+ 'public/cpp/bindings/no_interface.h',
'public/cpp/bindings/passable.h',
- 'public/cpp/bindings/remote_ptr.h',
'public/cpp/bindings/sync_dispatcher.h',
'public/cpp/bindings/type_converter.h',
'public/cpp/bindings/lib/array.cc',
@@ -241,7 +243,8 @@
'public/cpp/bindings/lib/connector.h',
'public/cpp/bindings/lib/fixed_buffer.cc',
'public/cpp/bindings/lib/fixed_buffer.h',
- 'public/cpp/bindings/lib/interface.cc',
+ 'public/cpp/bindings/lib/interface_ptr_internal.h',
+ 'public/cpp/bindings/lib/interface_server_internal.h',
'public/cpp/bindings/lib/message.cc',
'public/cpp/bindings/lib/message_builder.cc',
'public/cpp/bindings/lib/message_builder.h',
@@ -250,6 +253,7 @@
'public/cpp/bindings/lib/message_internal.h',
'public/cpp/bindings/lib/message_queue.cc',
'public/cpp/bindings/lib/message_queue.h',
+ 'public/cpp/bindings/lib/no_interface.cc',
'public/cpp/bindings/lib/router.cc',
'public/cpp/bindings/lib/router.h',
'public/cpp/bindings/lib/scratch_buffer.cc',
diff --git a/mojo/public/cpp/bindings/BUILD.gn b/mojo/public/cpp/bindings/BUILD.gn
index 66b8733..9753c73 100644
--- a/mojo/public/cpp/bindings/BUILD.gn
+++ b/mojo/public/cpp/bindings/BUILD.gn
@@ -9,10 +9,10 @@ source_set("bindings") {
"buffer.h",
"callback.h",
"error_handler.h",
- "interface.h",
+ "interface_ptr.h",
"message.h",
+ "no_interface.h",
"passable.h",
- "remote_ptr.h",
"sync_dispatcher.h",
"type_converter.h",
"lib/array.cc",
@@ -27,13 +27,13 @@ source_set("bindings") {
"lib/connector.h",
"lib/fixed_buffer.cc",
"lib/fixed_buffer.h",
- "lib/interface.cc",
"lib/message.cc",
"lib/message_builder.cc",
"lib/message_builder.h",
"lib/message_internal.h",
"lib/message_queue.cc",
"lib/message_queue.h",
+ "lib/no_interface.cc",
"lib/router.cc",
"lib/router.h",
"lib/scratch_buffer.cc",
diff --git a/mojo/public/cpp/bindings/error_handler.h b/mojo/public/cpp/bindings/error_handler.h
index 25c0d65..a6f0a4a 100644
--- a/mojo/public/cpp/bindings/error_handler.h
+++ b/mojo/public/cpp/bindings/error_handler.h
@@ -7,10 +7,20 @@
namespace mojo {
+// This interface is used to report connection errors.
class ErrorHandler {
public:
virtual ~ErrorHandler() {}
- virtual void OnError() = 0;
+ virtual void OnConnectionError() = 0;
+};
+
+// Used when you'd like to extend a base class with the same method signature
+// as ErrorHandler.
+template <typename Base>
+class WithErrorHandler : public Base {
+ public:
+ virtual ~WithErrorHandler() {}
+ virtual void OnConnectionError() = 0;
};
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/interface.h b/mojo/public/cpp/bindings/interface.h
deleted file mode 100644
index bba8fef..0000000
--- a/mojo/public/cpp/bindings/interface.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_
-
-#include <assert.h>
-
-#include "mojo/public/cpp/bindings/message.h"
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-
-
-// NoInterface is for use in cases when a non-existent or empty interface is
-// needed (e.g., when the Mojom "Peer" attribute is not present).
-
-class NoInterface;
-
-class NoInterfaceStub : public MessageReceiver {
- public:
- NoInterfaceStub(NoInterface* unused) {}
- virtual bool Accept(Message* message) MOJO_OVERRIDE;
- virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
- MOJO_OVERRIDE;
-};
-
-class NoInterface {
- public:
- typedef NoInterfaceStub _Stub;
- typedef NoInterface _Peer;
-};
-
-
-// AnyInterface is for use in cases where any interface would do (e.g., see the
-// Shell::Connect method).
-
-typedef NoInterface AnyInterface;
-
-
-// InterfaceHandle<S>
-
-template <typename S>
-class InterfaceHandle : public MessagePipeHandle {
- public:
- InterfaceHandle() {}
- explicit InterfaceHandle(MojoHandle value) : MessagePipeHandle(value) {}
-};
-
-
-// Interface<S>
-
-template <typename S>
-struct Interface {
- typedef InterfaceHandle<S> Handle;
- typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle;
-};
-
-template <>
-struct Interface<mojo::NoInterface> {
- typedef MessagePipeHandle Handle;
- typedef ScopedMessagePipeHandle ScopedHandle;
-};
-
-
-// InterfacePipe<S,P> is used to construct a MessagePipe with typed interfaces
-// on either end.
-
-template <typename S, typename P = typename S::_Peer>
-class InterfacePipe {
- public:
- InterfacePipe() {
- typename Interface<S>::Handle h0;
- typename Interface<P>::Handle h1;
- MojoResult result MOJO_ALLOW_UNUSED =
- MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value());
- assert(result == MOJO_RESULT_OK);
- handle_to_self.reset(h0);
- handle_to_peer.reset(h1);
- }
-
- typename Interface<S>::ScopedHandle handle_to_self;
- typename Interface<P>::ScopedHandle handle_to_peer;
-};
-
-// TODO(darin): Once we have the ability to use C++11 features, consider
-// defining a template alias for ScopedInterfaceHandle<S>.
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_
diff --git a/mojo/public/cpp/bindings/interface_impl.h b/mojo/public/cpp/bindings/interface_impl.h
new file mode 100644
index 0000000..ec6bc91
--- /dev/null
+++ b/mojo/public/cpp/bindings/interface_impl.h
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
+
+#include "mojo/public/cpp/bindings/lib/interface_impl_internal.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+
+// InterfaceImpl<..> is designed to be the base class of an interface
+// implementation. It may be bound to a pipe or a proxy, see BindToPipe and
+// BindToProxy.
+//
+// NOTE: A base class of WithErrorHandler<Interface> is used to avoid multiple
+// inheritance. This base class inserts the signature of ErrorHandler into the
+// inheritance chain.
+template <typename Interface>
+class InterfaceImpl : public WithErrorHandler<Interface> {
+ public:
+ InterfaceImpl() : internal_state_(this) {}
+ virtual ~InterfaceImpl() {}
+
+ // Subclasses must handle connection errors.
+ virtual void OnConnectionError() = 0;
+
+ // DO NOT USE. Exposed only for internal use and for testing.
+ internal::InterfaceImplState<Interface>* internal_state() {
+ return &internal_state_;
+ }
+
+ private:
+ internal::InterfaceImplState<Interface> internal_state_;
+ MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl);
+};
+
+// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given
+// MessagePipe. The instance is returned for convenience in member initializer
+// lists, etc. If the pipe is closed, the instance's OnConnectionError method
+// will be called.
+//
+// The instance is also bound to the current thread. Its methods will only be
+// called on the current thread, and if the current thread exits, then it will
+// also be deleted, and along with it, its end point of the pipe will be closed.
+//
+// Before returning, the instance will receive a SetClient call, providing it
+// with a proxy to the client on the other end of the pipe.
+template <typename Impl>
+Impl* BindToPipe(Impl* instance,
+ ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ instance->internal_state()->Bind(handle.Pass(), waiter);
+ return instance;
+}
+
+// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given
+// InterfacePtr<..>. The instance is returned for convenience in member
+// initializer lists, etc. If the pipe is closed, the instance's
+// OnConnectionError method will be called.
+//
+// The instance is also bound to the current thread. Its methods will only be
+// called on the current thread, and if the current thread exits, then it will
+// also be deleted, and along with it, its end point of the pipe will be closed.
+//
+// Before returning, the instance will receive a SetClient call, providing it
+// with a proxy to the client on the other end of the pipe.
+template <typename Impl, typename Interface>
+Impl* BindToProxy(Impl* instance,
+ InterfacePtr<Interface>* ptr,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ instance->internal_state()->BindProxy(ptr, waiter);
+ return instance;
+}
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
diff --git a/mojo/public/cpp/bindings/interface_ptr.h b/mojo/public/cpp/bindings/interface_ptr.h
new file mode 100644
index 0000000..91bd6ba
--- /dev/null
+++ b/mojo/public/cpp/bindings/interface_ptr.h
@@ -0,0 +1,116 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
+
+#include <assert.h>
+
+#include <algorithm>
+
+#include "mojo/public/cpp/bindings/error_handler.h"
+#include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+class ErrorHandler;
+
+// InterfacePtr represents a proxy to a remote instance of an interface.
+template <typename Interface>
+class InterfacePtr {
+ MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InterfacePtr, RValue)
+ public:
+ InterfacePtr() {}
+
+ InterfacePtr(RValue other) {
+ other.object->internal_state_.Swap(&internal_state_);
+ }
+ InterfacePtr& operator=(RValue other) {
+ other.object->internal_state_.Swap(&internal_state_);
+ return *this;
+ }
+
+ ~InterfacePtr() {}
+
+ Interface* get() const {
+ return internal_state_.instance();
+ }
+ Interface* operator->() const { return get(); }
+ Interface* operator*() const { return get(); }
+
+ void reset() {
+ State doomed;
+ internal_state_.Swap(&doomed);
+ }
+
+ // This method configures the InterfacePtr<..> to be a proxy to a remote
+ // object on the other end of the given pipe.
+ //
+ // The proxy is bound to the current thread, which means its methods may
+ // only be called on the current thread.
+ //
+ // To move a bound InterfacePtr<..> to another thread, call
+ // ResetAndReturnMessagePipe. Then create a new InterfacePtr<..> on another
+ // thread, and bind the new InterfacePtr<..> to the message pipe on that
+ // thread.
+ void Bind(ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ reset();
+ internal_state_.ConfigureProxy(handle.Pass(), waiter);
+ }
+
+ // This method may be called to query if the underlying pipe has encountered
+ // an error. If true, this means method calls made on this interface will be
+ // dropped (and may have already been dropped) on the floor.
+ bool encountered_error() const {
+ assert(internal_state_.router());
+ return internal_state_.router()->encountered_error();
+ }
+
+ // This method may be called to register an ErrorHandler to observe a
+ // connection error on the underlying pipe. The callback runs asynchronously
+ // from the current message loop.
+ void set_error_handler(ErrorHandler* error_handler) {
+ assert(internal_state_.router());
+ internal_state_.router()->set_error_handler(error_handler);
+ }
+
+ // Returns the underlying message pipe handle (if any) and resets the
+ // InterfacePtr<..> to its uninitialized state. This method is helpful if you
+ // need to move a proxy to another thread. See related notes for Bind.
+ ScopedMessagePipeHandle ResetAndReturnMessagePipe() {
+ State state;
+ internal_state_.Swap(&state);
+ return state.router() ?
+ state.router()->ReleaseMessagePipe() : ScopedMessagePipeHandle();
+ }
+
+ // DO NOT USE. Exposed only for internal use and for testing.
+ internal::InterfacePtrState<Interface>* internal_state() {
+ return &internal_state_;
+ }
+
+ private:
+ typedef internal::InterfacePtrState<Interface> State;
+ State internal_state_;
+};
+
+// Takes a handle to the proxy end-point of a pipe. On the other end is
+// presumed to be an interface implementation of type |Interface|. Returns a
+// generated proxy to that interface, which may be used on the current thread.
+// It is valid to call SetClient on the returned Interface to set an instance
+// of Interface::Client.
+template <typename Interface>
+InterfacePtr<Interface> MakeProxy(
+ ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ InterfacePtr<Interface> ptr;
+ if (handle.is_valid())
+ ptr.Bind(handle.Pass(), waiter);
+ return ptr.Pass();
+}
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h
index 4ecad35..865bf1c 100644
--- a/mojo/public/cpp/bindings/lib/array_internal.h
+++ b/mojo/public/cpp/bindings/lib/array_internal.h
@@ -8,7 +8,6 @@
#include <new>
#include "mojo/public/cpp/bindings/buffer.h"
-#include "mojo/public/cpp/bindings/interface.h"
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
#include "mojo/public/cpp/bindings/passable.h"
diff --git a/mojo/public/cpp/bindings/lib/connector.cc b/mojo/public/cpp/bindings/lib/connector.cc
index aa6c45e..d9ce9d1 100644
--- a/mojo/public/cpp/bindings/lib/connector.cc
+++ b/mojo/public/cpp/bindings/lib/connector.cc
@@ -38,7 +38,17 @@ void Connector::CloseMessagePipe() {
Close(message_pipe_.Pass());
}
+ScopedMessagePipeHandle Connector::ReleaseMessagePipe() {
+ if (async_wait_id_) {
+ waiter_->CancelWait(waiter_, async_wait_id_);
+ async_wait_id_ = 0;
+ }
+ return message_pipe_.Pass();
+}
+
bool Connector::Accept(Message* message) {
+ assert(message_pipe_.is_valid());
+
if (error_)
return false;
@@ -99,7 +109,7 @@ void Connector::OnHandleReady(MojoResult result) {
}
if (error_ && error_handler_)
- error_handler_->OnError();
+ error_handler_->OnConnectionError();
}
void Connector::WaitToReadMore() {
diff --git a/mojo/public/cpp/bindings/lib/connector.h b/mojo/public/cpp/bindings/lib/connector.h
index f32a170..6e9c1b9 100644
--- a/mojo/public/cpp/bindings/lib/connector.h
+++ b/mojo/public/cpp/bindings/lib/connector.h
@@ -53,9 +53,14 @@ class Connector : public MessageReceiver {
// waiting to read from the pipe.
bool encountered_error() const { return error_; }
- // Closes the pipe, triggering the error state.
+ // Closes the pipe, triggering the error state. Connector is put into a
+ // quiescent state.
void CloseMessagePipe();
+ // Releases the pipe, not triggering the error state. Connector is put into
+ // a quiescent state.
+ ScopedMessagePipeHandle ReleaseMessagePipe();
+
// MessageReceiver implementation:
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
diff --git a/mojo/public/cpp/bindings/lib/interface_impl_internal.h b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
new file mode 100644
index 0000000..50fe566
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
+
+#include "mojo/public/cpp/bindings/error_handler.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace internal {
+
+template <typename Interface>
+class InterfaceImplState : public ErrorHandler {
+ public:
+ explicit InterfaceImplState(WithErrorHandler<Interface>* instance)
+ : router_(NULL),
+ proxy_(NULL) {
+ assert(instance);
+ stub_.set_sink(instance);
+ }
+
+ virtual ~InterfaceImplState() {
+ delete proxy_;
+ if (router_) {
+ router_->set_error_handler(NULL);
+ delete router_;
+ }
+ }
+
+ void BindProxy(
+ InterfacePtr<Interface>* ptr,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ MessagePipe pipe;
+ ptr->Bind(pipe.handle0.Pass(), waiter);
+ Bind(pipe.handle1.Pass(), waiter);
+ }
+
+ void Bind(ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter) {
+ assert(!router_);
+
+ router_ = new Router(handle.Pass(), waiter);
+ router_->set_incoming_receiver(&stub_);
+ router_->set_error_handler(this);
+
+ proxy_ = new typename Interface::Client_::Proxy_(router_);
+
+ stub_.sink()->SetClient(proxy_);
+ }
+
+ Router* router() { return router_; }
+
+ private:
+ virtual void OnConnectionError() MOJO_OVERRIDE {
+ static_cast<WithErrorHandler<Interface>*>(stub_.sink())->
+ OnConnectionError();
+ }
+
+ internal::Router* router_;
+ typename Interface::Client_::Proxy_* proxy_;
+ typename Interface::Stub_ stub_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_internal.h b/mojo/public/cpp/bindings/lib/interface_ptr_internal.h
new file mode 100644
index 0000000..041a31c
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/interface_ptr_internal.h
@@ -0,0 +1,108 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
+
+#include <stdio.h>
+
+#include "mojo/public/cpp/bindings/lib/router.h"
+
+namespace mojo {
+namespace internal {
+
+template <typename Interface>
+class InterfacePtrState {
+ public:
+ InterfacePtrState() : instance_(NULL), client_(NULL), router_(NULL) {}
+
+ ~InterfacePtrState() {
+ // Destruction order matters here. We delete |instance_| first, even though
+ // |router_| may have a reference to it, so that |~Interface| may have a
+ // shot at generating new outbound messages (ie, invoking client methods).
+ delete instance_;
+ delete router_;
+ delete client_;
+ }
+
+ Interface* instance() const { return instance_; }
+ void set_instance(Interface* instance) { instance_ = instance; }
+
+ Router* router() const { return router_; }
+
+ bool is_configured_as_proxy() const {
+ // This question only makes sense if we have a bound pipe.
+ return router_ && !client_;
+ }
+
+ void Swap(InterfacePtrState* other) {
+ std::swap(other->instance_, instance_);
+ std::swap(other->client_, client_);
+ std::swap(other->router_, router_);
+ }
+
+ void ConfigureProxy(ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ assert(!instance_);
+ assert(!router_);
+
+ router_ = new Router(handle.Pass(), waiter);
+ ProxyWithStub* proxy = new ProxyWithStub(router_);
+ router_->set_incoming_receiver(&proxy->stub);
+
+ instance_ = proxy;
+ }
+
+ void ConfigureStub(ScopedMessagePipeHandle handle,
+ MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
+ assert(instance_); // Should have already been set!
+ assert(!router_);
+
+ // Stub for binding to state_.instance
+ // Proxy for communicating to the client on the other end of the pipe.
+
+ router_ = new Router(handle.Pass(), waiter);
+ ClientProxyWithStub* proxy = new ClientProxyWithStub(router_);
+ proxy->stub.set_sink(instance_);
+ router_->set_incoming_receiver(&proxy->stub);
+
+ instance_->SetClient(proxy);
+ client_ = proxy;
+ }
+
+ private:
+ class ProxyWithStub : public Interface::Proxy_ {
+ public:
+ explicit ProxyWithStub(MessageReceiver* receiver)
+ : Interface::Proxy_(receiver) {
+ }
+ virtual void SetClient(typename Interface::Client_* client) MOJO_OVERRIDE {
+ stub.set_sink(client);
+ }
+ typename Interface::Client_::Stub_ stub;
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(ProxyWithStub);
+ };
+
+ class ClientProxyWithStub : public Interface::Client_::Proxy_ {
+ public:
+ explicit ClientProxyWithStub(MessageReceiver* receiver)
+ : Interface::Client_::Proxy_(receiver) {
+ }
+ typename Interface::Stub_ stub;
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(ClientProxyWithStub);
+ };
+
+ Interface* instance_;
+ typename Interface::Client_* client_;
+ Router* router_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState);
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
diff --git a/mojo/public/cpp/bindings/lib/interface.cc b/mojo/public/cpp/bindings/lib/no_interface.cc
index 3b552be..7ce223a 100644
--- a/mojo/public/cpp/bindings/lib/interface.cc
+++ b/mojo/public/cpp/bindings/lib/no_interface.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 "mojo/public/cpp/bindings/interface.h"
+#include "mojo/public/cpp/bindings/no_interface.h"
namespace mojo {
diff --git a/mojo/public/cpp/bindings/lib/router.h b/mojo/public/cpp/bindings/lib/router.h
index 08c184e..220af7d 100644
--- a/mojo/public/cpp/bindings/lib/router.h
+++ b/mojo/public/cpp/bindings/lib/router.h
@@ -43,6 +43,14 @@ class Router : public MessageReceiver {
// waiting to read from the pipe.
bool encountered_error() const { return connector_.encountered_error(); }
+ void CloseMessagePipe() {
+ connector_.CloseMessagePipe();
+ }
+
+ ScopedMessagePipeHandle ReleaseMessagePipe() {
+ return connector_.ReleaseMessagePipe();
+ }
+
// MessageReceiver implementation:
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
diff --git a/mojo/public/cpp/bindings/no_interface.h b/mojo/public/cpp/bindings/no_interface.h
new file mode 100644
index 0000000..02682d4
--- /dev/null
+++ b/mojo/public/cpp/bindings/no_interface.h
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_NO_INTERFACE_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_NO_INTERFACE_H_
+
+#include <assert.h>
+
+#include "mojo/public/cpp/bindings/message.h"
+#include "mojo/public/cpp/system/core.h"
+
+namespace mojo {
+
+// NoInterface is for use in cases when a non-existent or empty interface is
+// needed (e.g., when the Mojom "Peer" attribute is not present).
+
+class NoInterfaceProxy;
+class NoInterfaceStub;
+
+class NoInterface {
+ public:
+ typedef NoInterfaceProxy Proxy_;
+ typedef NoInterfaceStub Stub_;
+ typedef NoInterface Client_;
+ virtual ~NoInterface() {}
+ virtual void SetClient(NoInterface* client) {}
+};
+
+class NoInterfaceProxy : public NoInterface {
+ public:
+ explicit NoInterfaceProxy(MessageReceiver* receiver) {}
+};
+
+class NoInterfaceStub : public MessageReceiver {
+ public:
+ NoInterfaceStub() {}
+ void set_sink(NoInterface* sink) {}
+ virtual bool Accept(Message* message) MOJO_OVERRIDE;
+ virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
+ MOJO_OVERRIDE;
+};
+
+
+// AnyInterface is for use in cases where any interface would do (e.g., see the
+// Shell::Connect method).
+
+typedef NoInterface AnyInterface;
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_NO_INTERFACE_H_
diff --git a/mojo/public/cpp/bindings/remote_ptr.h b/mojo/public/cpp/bindings/remote_ptr.h
deleted file mode 100644
index e1b9a5b..0000000
--- a/mojo/public/cpp/bindings/remote_ptr.h
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_PUBLIC_CPP_BINDINGS_REMOTE_PTR_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_REMOTE_PTR_H_
-
-#include <assert.h>
-
-#include "mojo/public/cpp/bindings/interface.h"
-#include "mojo/public/cpp/bindings/lib/router.h"
-#include "mojo/public/cpp/system/macros.h"
-
-namespace mojo {
-
-// A RemotePtr is a smart-pointer for managing the connection of a message pipe
-// to an interface proxy.
-//
-// EXAMPLE:
-//
-// Given foo.mojom containing the following interfaces:
-//
-// [Peer=FooClient]
-// interface Foo {
-// void Ping();
-// };
-//
-// [Peer=Foo]
-// interface FooClient {
-// void Pong();
-// };
-//
-// On the client side of a service, RemotePtr might be used like so:
-//
-// class FooClientImpl : public FooClient {
-// public:
-// explicit FooClientImpl(ScopedFooHandle handle)
-// : foo_(handle.Pass(), this) {
-// foo_.Ping();
-// }
-// virtual void Pong() {
-// ...
-// }
-// private:
-// mojo::RemotePtr<Foo> foo_;
-// };
-//
-// On the implementation side of a service, RemotePtr might be used like so:
-//
-// class FooImpl : public Foo {
-// public:
-// explicit FooImpl(ScopedFooClientHandle handle)
-// : client_(handle.Pass(), this) {
-// }
-// virtual void Ping() {
-// client_->Pong();
-// }
-// private:
-// mojo::RemotePtr<FooClient> client_;
-// };
-//
-// NOTE:
-//
-// 1- It is valid to pass NULL for the peer if you are not interested in
-// receiving incoming messages. Those messages will still be consumed.
-//
-// 2- You may optionally register an ErrorHandler on the RemotePtr to be
-// notified if the peer has gone away. Alternatively, you may poll the
-// |encountered_error()| method to check if the peer has gone away.
-//
-template <typename S>
-class RemotePtr {
- struct State;
- MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(RemotePtr, RValue)
-
- public:
- RemotePtr() : state_(NULL) {}
- explicit RemotePtr(typename Interface<S>::ScopedHandle interface_handle,
- typename S::_Peer* peer,
- ErrorHandler* error_handler = NULL,
- MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter())
- : state_(new State(ScopedMessagePipeHandle(interface_handle.Pass()), peer,
- error_handler, waiter)) {
- }
-
- // Move-only constructor and operator=.
- RemotePtr(RValue other) : state_(other.object->release()) {}
- RemotePtr& operator=(RValue other) {
- delete state_;
- state_ = other.object->release();
- return *this;
- }
-
- ~RemotePtr() {
- delete state_;
- }
-
- bool is_null() const {
- return !state_;
- }
-
- S* get() {
- assert(state_);
- return &state_->proxy;
- }
-
- S* operator->() {
- return get();
- }
-
- void reset() {
- delete state_;
- state_ = NULL;
- }
-
- void reset(typename Interface<S>::ScopedHandle interface_handle,
- typename S::_Peer* peer,
- ErrorHandler* error_handler = NULL,
- MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
- delete state_;
- state_ = new State(ScopedMessagePipeHandle(interface_handle.Pass()), peer,
- error_handler, waiter);
- }
-
- bool encountered_error() const {
- assert(state_);
- return state_->router.encountered_error();
- }
-
- internal::Router* router_for_testing() {
- return &state_->router;
- }
-
- private:
- struct State {
- State(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer,
- ErrorHandler* error_handler, MojoAsyncWaiter* waiter)
- : router(message_pipe.Pass(), waiter),
- proxy(&router),
- stub(peer) {
- router.set_error_handler(error_handler);
- if (peer)
- router.set_incoming_receiver(&stub);
- }
- internal::Router router;
- typename S::_Proxy proxy;
- typename S::_Peer::_Stub stub;
- };
-
- State* release() {
- State* state = state_;
- state_ = NULL;
- return state;
- }
-
- State* state_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_REMOTE_PTR_H_
diff --git a/mojo/public/cpp/bindings/sync_dispatcher.h b/mojo/public/cpp/bindings/sync_dispatcher.h
index e267a17..7521180 100644
--- a/mojo/public/cpp/bindings/sync_dispatcher.h
+++ b/mojo/public/cpp/bindings/sync_dispatcher.h
@@ -16,11 +16,11 @@ class MessageReceiver;
bool WaitForMessageAndDispatch(MessagePipeHandle handle,
mojo::MessageReceiver* receiver);
-template<typename S> class SyncDispatcher {
+template<typename Interface> class SyncDispatcher {
public:
- SyncDispatcher(ScopedMessagePipeHandle message_pipe, S* sink)
- : message_pipe_(message_pipe.Pass()),
- stub_(sink) {
+ SyncDispatcher(ScopedMessagePipeHandle message_pipe, Interface* sink)
+ : message_pipe_(message_pipe.Pass()) {
+ stub_.set_sink(sink);
}
bool WaitAndDispatchOneMessage() {
@@ -29,7 +29,7 @@ template<typename S> class SyncDispatcher {
private:
ScopedMessagePipeHandle message_pipe_;
- typename S::_Stub stub_;
+ typename Interface::Stub_ stub_;
};
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/tests/array_unittest.cc b/mojo/public/cpp/bindings/tests/array_unittest.cc
index dccd716..4bef4cd 100644
--- a/mojo/public/cpp/bindings/tests/array_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/array_unittest.cc
@@ -4,7 +4,6 @@
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/bindings/array.h"
-#include "mojo/public/cpp/bindings/interface.h"
#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "mojo/public/cpp/bindings/lib/scratch_buffer.h"
#include "mojo/public/cpp/environment/environment.h"
@@ -141,31 +140,6 @@ TEST(ArrayTest, MessagePipeHandlesAreClosed) {
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe1_value));
}
-// Tests that Array<InterfaceHandle<S>> supports closing handles.
-TEST(ArrayTest, InterfaceHandlesAreClosed) {
- Environment env;
-
- InterfacePipe<sample::Port, sample::Port> pipe;
-
- MojoHandle pipe0_value = pipe.handle_to_self.get().value();
- MojoHandle pipe1_value = pipe.handle_to_peer.get().value();
-
- {
- AllocationScope scope;
-
- Array<sample::PortHandle>::Builder handles_builder(2);
- handles_builder[0] = pipe.handle_to_self.Pass();
- handles_builder[1].reset(pipe.handle_to_peer.release());
-
- MOJO_ALLOW_UNUSED Array<sample::PortHandle> handles =
- handles_builder.Finish();
- }
-
- // We expect the pipes to have been closed.
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe0_value));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe1_value));
-}
-
} // namespace
} // namespace test
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
index 7df6db6..2cbd789 100644
--- a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/cpp/utility/run_loop.h"
@@ -17,10 +16,14 @@ namespace {
const char kText1[] = "hello";
const char kText2[] = "world";
-class SampleFactoryImpl : public sample::Factory {
+class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
public:
- explicit SampleFactoryImpl(sample::ScopedFactoryClientHandle handle)
- : client_(handle.Pass(), this) {
+ virtual void OnConnectionError() MOJO_OVERRIDE {
+ delete this;
+ }
+
+ virtual void SetClient(sample::FactoryClient* client) MOJO_OVERRIDE {
+ client_ = client;
}
virtual void DoStuff(const sample::Request& request,
@@ -70,69 +73,17 @@ class SampleFactoryImpl : public sample::Factory {
}
private:
- RemotePtr<sample::FactoryClient> client_;
+ sample::FactoryClient* client_;
ScopedMessagePipeHandle pipe1_;
};
class SampleFactoryClientImpl : public sample::FactoryClient {
public:
- explicit SampleFactoryClientImpl(sample::ScopedFactoryHandle handle)
- : factory_(handle.Pass(), this),
- got_response_(false) {
- }
-
- void Start() {
- expected_text_reply_ = kText1;
-
- ScopedMessagePipeHandle pipe0;
- CreateMessagePipe(&pipe0, &pipe1_);
-
- EXPECT_TRUE(WriteTextMessage(pipe1_.get(), kText1));
-
- ScopedMessagePipeHandle pipe2;
- CreateMessagePipe(&pipe2, &pipe3_);
-
- EXPECT_TRUE(WriteTextMessage(pipe3_.get(), kText2));
-
- AllocationScope scope;
- sample::Request::Builder request;
- request.set_x(1);
- request.set_pipe(pipe2.Pass());
- factory_->DoStuff(request.Finish(), pipe0.Pass());
- }
-
- void StartNoPipes() {
- expected_text_reply_.clear();
-
- AllocationScope scope;
- sample::Request::Builder request;
- request.set_x(1);
- factory_->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass());
+ SampleFactoryClientImpl() : got_response_(false) {
}
- // Writes a string to a data pipe and passes the data pipe (consumer) to the
- // factory.
- void StartDataPipe() {
- expected_text_reply_.clear();
-
- ScopedDataPipeProducerHandle producer_handle;
- ScopedDataPipeConsumerHandle consumer_handle;
- MojoCreateDataPipeOptions options = {
- sizeof(MojoCreateDataPipeOptions),
- MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
- 1,
- 1024};
- ASSERT_EQ(MOJO_RESULT_OK,
- CreateDataPipe(&options, &producer_handle, &consumer_handle));
- expected_text_reply_ = "got it";
- // +1 for \0.
- uint32_t data_size = static_cast<uint32_t>(expected_text_reply_.size() + 1);
- ASSERT_EQ(MOJO_RESULT_OK,
- WriteDataRaw(producer_handle.get(), expected_text_reply_.c_str(),
- &data_size, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
-
- AllocationScope scope;
- factory_->DoStuff2(consumer_handle.Pass());
+ void set_expected_text_reply(const std::string& expected_text_reply) {
+ expected_text_reply_ = expected_text_reply;
}
bool got_response() const {
@@ -167,7 +118,6 @@ class SampleFactoryClientImpl : public sample::FactoryClient {
}
private:
- RemotePtr<sample::Factory> factory_;
ScopedMessagePipeHandle pipe1_;
ScopedMessagePipeHandle pipe3_;
std::string expected_text_reply_;
@@ -176,6 +126,10 @@ class SampleFactoryClientImpl : public sample::FactoryClient {
class HandlePassingTest : public testing::Test {
public:
+ virtual void TearDown() {
+ PumpMessages();
+ }
+
void PumpMessages() {
loop_.RunUntilIdle();
}
@@ -186,12 +140,31 @@ class HandlePassingTest : public testing::Test {
};
TEST_F(HandlePassingTest, Basic) {
- InterfacePipe<sample::Factory> pipe;
+ sample::FactoryPtr factory;
+ BindToProxy(new SampleFactoryImpl(), &factory);
+
+ SampleFactoryClientImpl factory_client;
+ factory_client.set_expected_text_reply(kText1);
+
+ factory->SetClient(&factory_client);
+
+ ScopedMessagePipeHandle pipe0, pipe1;
+ CreateMessagePipe(&pipe0, &pipe1);
+
+ EXPECT_TRUE(WriteTextMessage(pipe1.get(), kText1));
+
+ ScopedMessagePipeHandle pipe2, pipe3;
+ CreateMessagePipe(&pipe2, &pipe3);
- SampleFactoryImpl factory(pipe.handle_to_peer.Pass());
- SampleFactoryClientImpl factory_client(pipe.handle_to_self.Pass());
+ EXPECT_TRUE(WriteTextMessage(pipe3.get(), kText2));
- factory_client.Start();
+ {
+ AllocationScope scope;
+ sample::Request::Builder request;
+ request.set_x(1);
+ request.set_pipe(pipe2.Pass());
+ factory->DoStuff(request.Finish(), pipe0.Pass());
+ }
EXPECT_FALSE(factory_client.got_response());
@@ -201,12 +174,18 @@ TEST_F(HandlePassingTest, Basic) {
}
TEST_F(HandlePassingTest, PassInvalid) {
- InterfacePipe<sample::Factory> pipe;
+ sample::FactoryPtr factory;
+ BindToProxy(new SampleFactoryImpl(), &factory);
- SampleFactoryImpl factory(pipe.handle_to_peer.Pass());
- SampleFactoryClientImpl factory_client(pipe.handle_to_self.Pass());
+ SampleFactoryClientImpl factory_client;
+ factory->SetClient(&factory_client);
- factory_client.StartNoPipes();
+ {
+ AllocationScope scope;
+ sample::Request::Builder request;
+ request.set_x(1);
+ factory->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass());
+ }
EXPECT_FALSE(factory_client.got_response());
@@ -217,12 +196,35 @@ TEST_F(HandlePassingTest, PassInvalid) {
// Verifies DataPipeConsumer can be passed and read from.
TEST_F(HandlePassingTest, DataPipe) {
- InterfacePipe<sample::Factory> pipe;
+ sample::FactoryPtr factory;
+ BindToProxy(new SampleFactoryImpl(), &factory);
+
+ SampleFactoryClientImpl factory_client;
+ factory->SetClient(&factory_client);
- SampleFactoryImpl factory(pipe.handle_to_peer.Pass());
- SampleFactoryClientImpl factory_client(pipe.handle_to_self.Pass());
+ // Writes a string to a data pipe and passes the data pipe (consumer) to the
+ // factory.
+ ScopedDataPipeProducerHandle producer_handle;
+ ScopedDataPipeConsumerHandle consumer_handle;
+ MojoCreateDataPipeOptions options = {
+ sizeof(MojoCreateDataPipeOptions),
+ MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
+ 1,
+ 1024};
+ ASSERT_EQ(MOJO_RESULT_OK,
+ CreateDataPipe(&options, &producer_handle, &consumer_handle));
+ std::string expected_text_reply = "got it";
+ factory_client.set_expected_text_reply(expected_text_reply);
+ // +1 for \0.
+ uint32_t data_size = static_cast<uint32_t>(expected_text_reply.size() + 1);
+ ASSERT_EQ(MOJO_RESULT_OK,
+ WriteDataRaw(producer_handle.get(), expected_text_reply.c_str(),
+ &data_size, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
- ASSERT_NO_FATAL_FAILURE(factory_client.StartDataPipe());
+ {
+ AllocationScope scope;
+ factory->DoStuff2(consumer_handle.Pass());
+ }
EXPECT_FALSE(factory_client.got_response());
@@ -232,8 +234,11 @@ TEST_F(HandlePassingTest, DataPipe) {
}
TEST_F(HandlePassingTest, PipesAreClosed) {
- InterfacePipe<sample::Factory> pipe;
- RemotePtr<sample::Factory> factory(pipe.handle_to_self.Pass(), NULL);
+ sample::FactoryPtr factory;
+ BindToProxy(new SampleFactoryImpl(), &factory);
+
+ SampleFactoryClientImpl factory_client;
+ factory->SetClient(&factory_client);
MessagePipe extra_pipe;
diff --git a/mojo/public/cpp/bindings/tests/remote_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index 13311d4..3f9a80d 100644
--- a/mojo/public/cpp/bindings/tests/remote_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h"
@@ -21,7 +20,7 @@ class ErrorObserver : public ErrorHandler {
bool encountered_error() const { return encountered_error_; }
- virtual void OnError() MOJO_OVERRIDE {
+ virtual void OnConnectionError() MOJO_OVERRIDE {
encountered_error_ = true;
}
@@ -29,13 +28,19 @@ class ErrorObserver : public ErrorHandler {
bool encountered_error_;
};
-class MathCalculatorImpl : public math::Calculator {
+class MathCalculatorImpl : public InterfaceImpl<math::Calculator> {
public:
virtual ~MathCalculatorImpl() {}
- explicit MathCalculatorImpl(math::ScopedCalculatorUIHandle ui_handle)
- : ui_(ui_handle.Pass(), this),
- total_(0.0) {
+ MathCalculatorImpl() : total_(0.0) {
+ }
+
+ virtual void OnConnectionError() MOJO_OVERRIDE {
+ delete this;
+ }
+
+ virtual void SetClient(math::CalculatorUI* ui) MOJO_OVERRIDE {
+ ui_ = ui;
}
virtual void Clear() MOJO_OVERRIDE {
@@ -53,16 +58,16 @@ class MathCalculatorImpl : public math::Calculator {
}
private:
- RemotePtr<math::CalculatorUI> ui_;
+ math::CalculatorUI* ui_;
double total_;
};
class MathCalculatorUIImpl : public math::CalculatorUI {
public:
- explicit MathCalculatorUIImpl(math::ScopedCalculatorHandle calculator_handle,
- ErrorHandler* error_handler = NULL)
- : calculator_(calculator_handle.Pass(), this, error_handler),
+ explicit MathCalculatorUIImpl(math::CalculatorPtr calculator)
+ : calculator_(calculator.Pass()),
output_(0.0) {
+ calculator_->SetClient(this);
}
bool encountered_error() const {
@@ -95,30 +100,31 @@ class MathCalculatorUIImpl : public math::CalculatorUI {
output_ = value;
}
- RemotePtr<math::Calculator> calculator_;
+ math::CalculatorPtr calculator_;
double output_;
};
-class RemotePtrTest : public testing::Test {
+class InterfacePtrTest : public testing::Test {
public:
- void PumpMessages() {
+ virtual ~InterfacePtrTest() {
loop_.RunUntilIdle();
}
- protected:
- InterfacePipe<math::CalculatorUI> pipe_;
+ void PumpMessages() {
+ loop_.RunUntilIdle();
+ }
private:
Environment env_;
RunLoop loop_;
};
-TEST_F(RemotePtrTest, EndToEnd) {
- // Suppose this is instantiated in a process that has pipe0_.
- MathCalculatorImpl calculator(pipe_.handle_to_self.Pass());
+TEST_F(InterfacePtrTest, EndToEnd) {
+ math::CalculatorPtr calc;
+ BindToProxy(new MathCalculatorImpl(), &calc);
// Suppose this is instantiated in a process that has pipe1_.
- MathCalculatorUIImpl calculator_ui(pipe_.handle_to_peer.Pass());
+ MathCalculatorUIImpl calculator_ui(calc.Pass());
calculator_ui.Add(2.0);
calculator_ui.Multiply(5.0);
@@ -128,43 +134,48 @@ TEST_F(RemotePtrTest, EndToEnd) {
EXPECT_EQ(10.0, calculator_ui.GetOutput());
}
-TEST_F(RemotePtrTest, Movable) {
- RemotePtr<math::Calculator> a;
- RemotePtr<math::Calculator> b(pipe_.handle_to_peer.Pass(), NULL);
+TEST_F(InterfacePtrTest, Movable) {
+ math::CalculatorPtr a;
+ math::CalculatorPtr b;
+ BindToProxy(new MathCalculatorImpl(), &b);
- EXPECT_TRUE(a.is_null());
- EXPECT_FALSE(b.is_null());
+ EXPECT_TRUE(!a.get());
+ EXPECT_FALSE(!b.get());
a = b.Pass();
- EXPECT_FALSE(a.is_null());
- EXPECT_TRUE(b.is_null());
+ EXPECT_FALSE(!a.get());
+ EXPECT_TRUE(!b.get());
}
-TEST_F(RemotePtrTest, Resettable) {
- RemotePtr<math::Calculator> a;
+TEST_F(InterfacePtrTest, Resettable) {
+ math::CalculatorPtr a;
- EXPECT_TRUE(a.is_null());
+ EXPECT_TRUE(!a.get());
- math::CalculatorHandle handle = pipe_.handle_to_peer.get();
+ MessagePipe pipe;
- a.reset(pipe_.handle_to_peer.Pass(), NULL);
+ // Save this so we can test it later.
+ Handle handle = pipe.handle0.get();
- EXPECT_FALSE(a.is_null());
+ a = MakeProxy<math::Calculator>(pipe.handle0.Pass());
+
+ EXPECT_FALSE(!a.get());
a.reset();
- EXPECT_TRUE(a.is_null());
+ EXPECT_TRUE(!a.get());
+ EXPECT_FALSE(a.internal_state()->router());
// Test that handle was closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, CloseRaw(handle));
}
-TEST_F(RemotePtrTest, EncounteredError) {
- MathCalculatorImpl* calculator =
- new MathCalculatorImpl(pipe_.handle_to_self.Pass());
+TEST_F(InterfacePtrTest, EncounteredError) {
+ math::CalculatorPtr proxy;
+ MathCalculatorImpl* server = BindToProxy(new MathCalculatorImpl(), &proxy);
- MathCalculatorUIImpl calculator_ui(pipe_.handle_to_peer.Pass());
+ MathCalculatorUIImpl calculator_ui(proxy.Pass());
calculator_ui.Add(2.0);
PumpMessages();
@@ -174,8 +185,8 @@ TEST_F(RemotePtrTest, EncounteredError) {
calculator_ui.Multiply(5.0);
EXPECT_FALSE(calculator_ui.encountered_error());
- // Close the other side of the pipe.
- delete calculator;
+ // Close the server.
+ server->internal_state()->router()->CloseMessagePipe();
// The state change isn't picked up locally yet.
EXPECT_FALSE(calculator_ui.encountered_error());
@@ -186,13 +197,14 @@ TEST_F(RemotePtrTest, EncounteredError) {
EXPECT_TRUE(calculator_ui.encountered_error());
}
-TEST_F(RemotePtrTest, EncounteredErrorCallback) {
- MathCalculatorImpl* calculator =
- new MathCalculatorImpl(pipe_.handle_to_self.Pass());
+TEST_F(InterfacePtrTest, EncounteredErrorCallback) {
+ math::CalculatorPtr proxy;
+ MathCalculatorImpl* server = BindToProxy(new MathCalculatorImpl(), &proxy);
ErrorObserver error_observer;
- MathCalculatorUIImpl calculator_ui(pipe_.handle_to_peer.Pass(),
- &error_observer);
+ proxy.set_error_handler(&error_observer);
+
+ MathCalculatorUIImpl calculator_ui(proxy.Pass());
calculator_ui.Add(2.0);
PumpMessages();
@@ -202,8 +214,8 @@ TEST_F(RemotePtrTest, EncounteredErrorCallback) {
calculator_ui.Multiply(5.0);
EXPECT_FALSE(calculator_ui.encountered_error());
- // Close the other side of the pipe.
- delete calculator;
+ // Close the server.
+ server->internal_state()->router()->CloseMessagePipe();
// The state change isn't picked up locally yet.
EXPECT_FALSE(calculator_ui.encountered_error());
@@ -218,11 +230,12 @@ TEST_F(RemotePtrTest, EncounteredErrorCallback) {
EXPECT_TRUE(error_observer.encountered_error());
}
-TEST_F(RemotePtrTest, NoPeerAttribute) {
+TEST_F(InterfacePtrTest, NoClientAttribute) {
// This is a test to ensure the following compiles. The sample::Port interface
- // does not have an explicit Peer attribute.
- InterfacePipe<sample::Port, NoInterface> pipe;
- RemotePtr<sample::Port> port(pipe.handle_to_self.Pass(), NULL);
+ // does not have an explicit Client attribute.
+ sample::PortPtr port;
+ MessagePipe pipe;
+ port.Bind(pipe.handle0.Pass());
}
} // namespace
diff --git a/mojo/public/cpp/bindings/tests/request_response_unittest.cc b/mojo/public/cpp/bindings/tests/request_response_unittest.cc
index 94ed91f..d163f7d 100644
--- a/mojo/public/cpp/bindings/tests/request_response_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/request_response_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/cpp/utility/run_loop.h"
@@ -15,10 +14,14 @@ namespace mojo {
namespace test {
namespace {
-class ProviderImpl : public sample::Provider {
+class ProviderImpl : public InterfaceImpl<sample::Provider> {
public:
- explicit ProviderImpl(sample::ScopedProviderClientHandle handle)
- : client_(handle.Pass(), this) {
+ virtual void OnConnectionError() MOJO_OVERRIDE {
+ delete this;
+ }
+
+ virtual void SetClient(sample::ProviderClient* client) MOJO_OVERRIDE {
+ // Ignored. TODO(darin): Eliminate ProviderClient.
}
virtual void EchoString(
@@ -51,9 +54,6 @@ class ProviderImpl : public sample::Provider {
MOJO_OVERRIDE {
callback.Run(a);
}
-
- private:
- RemotePtr<sample::ProviderClient> client_;
};
class StringRecorder {
@@ -94,6 +94,10 @@ class MessagePipeWriter {
class RequestResponseTest : public testing::Test {
public:
+ virtual ~RequestResponseTest() {
+ loop_.RunUntilIdle();
+ }
+
void PumpMessages() {
loop_.RunUntilIdle();
}
@@ -104,9 +108,8 @@ class RequestResponseTest : public testing::Test {
};
TEST_F(RequestResponseTest, EchoString) {
- InterfacePipe<sample::Provider> pipe;
- ProviderImpl provider_impl(pipe.handle_to_peer.Pass());
- RemotePtr<sample::Provider> provider(pipe.handle_to_self.Pass(), NULL);
+ sample::ProviderPtr provider;
+ BindToProxy(new ProviderImpl(), &provider);
std::string buf;
{
@@ -120,9 +123,8 @@ TEST_F(RequestResponseTest, EchoString) {
}
TEST_F(RequestResponseTest, EchoStrings) {
- InterfacePipe<sample::Provider> pipe;
- ProviderImpl provider_impl(pipe.handle_to_peer.Pass());
- RemotePtr<sample::Provider> provider(pipe.handle_to_self.Pass(), NULL);
+ sample::ProviderPtr provider;
+ BindToProxy(new ProviderImpl(), &provider);
std::string buf;
{
@@ -136,9 +138,8 @@ TEST_F(RequestResponseTest, EchoStrings) {
}
TEST_F(RequestResponseTest, EchoMessagePipeHandle) {
- InterfacePipe<sample::Provider> pipe;
- ProviderImpl provider_impl(pipe.handle_to_peer.Pass());
- RemotePtr<sample::Provider> provider(pipe.handle_to_self.Pass(), NULL);
+ sample::ProviderPtr provider;
+ BindToProxy(new ProviderImpl(), &provider);
MessagePipe pipe2;
{
@@ -156,9 +157,8 @@ TEST_F(RequestResponseTest, EchoMessagePipeHandle) {
}
TEST_F(RequestResponseTest, EchoEnum) {
- InterfacePipe<sample::Provider> pipe;
- ProviderImpl provider_impl(pipe.handle_to_peer.Pass());
- RemotePtr<sample::Provider> provider(pipe.handle_to_self.Pass(), NULL);
+ sample::ProviderPtr provider;
+ BindToProxy(new ProviderImpl(), &provider);
sample::Enum value;
{
diff --git a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
index 9a4cf36..c13517d 100644
--- a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
@@ -266,7 +266,14 @@ void DumpHex(const uint8_t* bytes, uint32_t num_bytes) {
class ServiceImpl : public Service {
public:
- virtual void Frobinate(const Foo& foo, BazOptions baz, ScopedPortHandle port)
+ ServiceImpl() : client_(NULL) {
+ }
+
+ virtual void SetClient(ServiceClient* client) MOJO_OVERRIDE {
+ client_ = client;
+ }
+
+ virtual void Frobinate(const Foo& foo, BazOptions baz, PortPtr port)
MOJO_OVERRIDE {
// Users code goes here to handle the incoming Frobinate message.
@@ -283,6 +290,20 @@ class ServiceImpl : public Service {
Print(depth, "port", port.get());
}
}
+
+ private:
+ ServiceClient* client_;
+};
+
+class ServiceProxyImpl : public ServiceProxy {
+ public:
+ explicit ServiceProxyImpl(mojo::MessageReceiver* receiver)
+ : ServiceProxy(receiver) {
+ }
+
+ virtual void SetClient(ServiceClient* client) MOJO_OVERRIDE {
+ assert(false);
+ }
};
class SimpleMessageReceiver : public mojo::MessageReceiver {
@@ -299,7 +320,8 @@ class SimpleMessageReceiver : public mojo::MessageReceiver {
// the system. It receives the incoming message.
ServiceImpl impl;
- ServiceStub stub(&impl);
+ ServiceStub stub;
+ stub.set_sink(&impl);
return stub.Accept(message);
}
@@ -315,7 +337,7 @@ TEST(BindingsSampleTest, Basic) {
SimpleMessageReceiver receiver;
// User has a proxy to a Service somehow.
- Service* service = new ServiceProxy(&receiver);
+ Service* service = new ServiceProxyImpl(&receiver);
// User constructs a message to send.
@@ -328,8 +350,8 @@ TEST(BindingsSampleTest, Basic) {
Foo foo = MakeFoo();
CheckFoo(foo);
- mojo::InterfacePipe<Port, mojo::AnyInterface> pipe;
- service->Frobinate(foo, Service::BAZ_EXTRA, pipe.handle_to_self.Pass());
+ PortPtr port;
+ service->Frobinate(foo, Service::BAZ_EXTRA, port.Pass());
}
TEST(BindingsSampleTest, DefaultValues) {
diff --git a/mojo/public/cpp/shell/application.h b/mojo/public/cpp/shell/application.h
index ffca7fe..933077b 100644
--- a/mojo/public/cpp/shell/application.h
+++ b/mojo/public/cpp/shell/application.h
@@ -7,7 +7,6 @@
#include <vector>
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/shell/service.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
@@ -16,7 +15,7 @@ namespace mojo {
class Application : public internal::ServiceConnectorBase::Owner {
public:
- explicit Application(ScopedShellHandle shell_handle);
+ explicit Application(ScopedMessagePipeHandle shell_handle);
explicit Application(MojoHandle shell_handle);
virtual ~Application();
@@ -27,6 +26,11 @@ class Application : public internal::ServiceConnectorBase::Owner {
virtual void RemoveServiceConnector(
internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE;
+ template <typename Interface>
+ void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) {
+ mojo::ConnectTo(shell(), url, ptr);
+ }
+
protected:
// ShellClient methods.
virtual void AcceptConnection(const mojo::String& url,
diff --git a/mojo/public/cpp/shell/lib/application.cc b/mojo/public/cpp/shell/lib/application.cc
index 3224202..161e4e0 100644
--- a/mojo/public/cpp/shell/lib/application.cc
+++ b/mojo/public/cpp/shell/lib/application.cc
@@ -6,13 +6,13 @@
namespace mojo {
-Application::Application(ScopedShellHandle shell_handle)
+Application::Application(ScopedMessagePipeHandle shell_handle)
: internal::ServiceConnectorBase::Owner(shell_handle.Pass()) {
}
Application::Application(MojoHandle shell_handle)
: internal::ServiceConnectorBase::Owner(
- mojo::MakeScopedHandle(ShellHandle(shell_handle)).Pass()) {}
+ mojo::MakeScopedHandle(MessagePipeHandle(shell_handle)).Pass()) {}
Application::~Application() {
for (ServiceConnectorList::iterator it = service_connectors_.begin();
diff --git a/mojo/public/cpp/shell/lib/service.cc b/mojo/public/cpp/shell/lib/service.cc
index e408481..2f2e542 100644
--- a/mojo/public/cpp/shell/lib/service.cc
+++ b/mojo/public/cpp/shell/lib/service.cc
@@ -7,8 +7,9 @@
namespace mojo {
namespace internal {
-ServiceConnectorBase::Owner::Owner(ScopedShellHandle shell_handle)
- : shell_(shell_handle.Pass(), this) {
+ServiceConnectorBase::Owner::Owner(ScopedMessagePipeHandle shell_handle)
+ : shell_(MakeProxy<Shell>(shell_handle.Pass())) {
+ shell_->SetClient(this);
}
ServiceConnectorBase::Owner::~Owner() {}
diff --git a/mojo/public/cpp/shell/service.h b/mojo/public/cpp/shell/service.h
index 7dd08ff..c546289 100644
--- a/mojo/public/cpp/shell/service.h
+++ b/mojo/public/cpp/shell/service.h
@@ -5,11 +5,11 @@
#ifndef MOJO_PUBLIC_SHELL_SERVICE_H_
#define MOJO_PUBLIC_SHELL_SERVICE_H_
+#include <assert.h>
+
#include <vector>
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
-#include "mojo/public/cpp/system/core.h"
+#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
// Utility classes for creating ShellClients that vend service instances.
@@ -19,11 +19,9 @@
// class FooImpl : public Foo {
// public:
// FooImpl();
-// void Initialize(ServiceConnector<FooImpl>* service_connector,
-// ScopedMessagePipeHandle client_handle
+// void Initialize();
// private:
// ServiceConnector<FooImpl>* service_connector_;
-// RemotePtr<FooPeer> client_;
// };
//
//
@@ -66,8 +64,8 @@ class ServiceConnectorBase {
public:
class Owner : public ShellClient {
public:
- Owner(ScopedShellHandle shell_handle);
- ~Owner();
+ Owner(ScopedMessagePipeHandle shell_handle);
+ virtual ~Owner();
Shell* shell() { return shell_.get(); }
virtual void AddServiceConnector(
internal::ServiceConnectorBase* service_connector) = 0;
@@ -79,7 +77,7 @@ class ServiceConnectorBase {
Owner* owner) {
service_connector->owner_ = owner;
}
- RemotePtr<Shell> shell_;
+ ShellPtr shell_;
};
ServiceConnectorBase() : owner_(NULL) {}
virtual ~ServiceConnectorBase();
@@ -98,27 +96,33 @@ class ServiceConnector : public internal::ServiceConnectorBase {
ServiceConnector(Context* context = NULL) : context_(context) {}
virtual ~ServiceConnector() {
- for (typename ServiceList::iterator it = services_.begin();
- it != services_.end(); ++it) {
+ ConnectionList doomed;
+ doomed.swap(connections_);
+ for (typename ConnectionList::iterator it = doomed.begin();
+ it != doomed.end(); ++it) {
delete *it;
}
+ assert(connections_.empty()); // No one should have added more!
}
virtual void AcceptConnection(const std::string& url,
- ScopedMessagePipeHandle client_handle)
- MOJO_OVERRIDE {
- ServiceImpl* service = new ServiceImpl();
- service->Initialize(this, client_handle.Pass());
- services_.push_back(service);
+ ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
+ ServiceImpl* impl = BindToPipe(new ServiceImpl(), handle.Pass());
+ impl->set_connector(this);
+
+ connections_.push_back(impl);
+
+ impl->Initialize();
}
- void RemoveService(ServiceImpl* service) {
- for (typename ServiceList::iterator it = services_.begin();
- it != services_.end(); ++it) {
- if (*it == service) {
- services_.erase(it);
- delete service;
- if (services_.empty())
+ void RemoveConnection(ServiceImpl* impl) {
+ // Called from ~ServiceImpl, in response to a connection error.
+ for (typename ConnectionList::iterator it = connections_.begin();
+ it != connections_.end(); ++it) {
+ if (*it == impl) {
+ delete impl;
+ connections_.erase(it);
+ if (connections_.empty())
owner_->RemoveServiceConnector(this);
return;
}
@@ -128,58 +132,63 @@ class ServiceConnector : public internal::ServiceConnectorBase {
Context* context() const { return context_; }
private:
- typedef std::vector<ServiceImpl*> ServiceList;
- ServiceList services_;
+ typedef std::vector<ServiceImpl*> ConnectionList;
+ ConnectionList connections_;
Context* context_;
};
// Specialization of ServiceConnection.
// ServiceInterface: Service interface.
-// ServiceImpl: Implementation of Service interface.
+// ServiceImpl: Subclass of ServiceConnection<...>.
// Context: Optional type of shared context.
template <class ServiceInterface, class ServiceImpl, typename Context=void>
-class ServiceConnection : public ServiceInterface {
- public:
+class ServiceConnection : public InterfaceImpl<ServiceInterface> {
+ protected:
+ // NOTE: shell() and context() are not available at construction time.
+ // Initialize() will be called once those are available.
+ ServiceConnection() : service_connector_(NULL) {}
+
virtual ~ServiceConnection() {}
- protected:
- ServiceConnection() : reaper_(this), service_connector_(NULL) {}
-
- void Initialize(ServiceConnector<ServiceImpl, Context>* service_connector,
- ScopedMessagePipeHandle client_handle) {
- service_connector_ = service_connector;
- client_.reset(
- MakeScopedHandle(
- InterfaceHandle<typename ServiceInterface::_Peer>(
- client_handle.release().value())).Pass(),
- this,
- &reaper_);
+ virtual void OnConnectionError() MOJO_OVERRIDE {
+ service_connector_->RemoveConnection(static_cast<ServiceImpl*>(this));
+ }
+
+ // Shadow this method in ServiceImpl to perform one-time initialization.
+ // At the time this is called, shell() and context() will be available.
+ // NOTE: No need to call the base class Initialize from your subclass. It
+ // will always be a no-op.
+ void Initialize() {}
+
+ Shell* shell() {
+ return service_connector_->shell();
}
- Shell* shell() { return service_connector_->shell(); }
- Context* context() const { return service_connector_->context(); }
- typename ServiceInterface::_Peer* client() { return client_.get(); }
+ Context* context() const {
+ return service_connector_->context();
+ }
private:
- // The Reaper class allows us to handle errors on the client proxy without
- // polluting the name space of the ServiceConnection<> class.
- class Reaper : public ErrorHandler {
- public:
- Reaper(ServiceConnection<ServiceInterface, ServiceImpl, Context>* service)
- : service_(service) {}
- virtual void OnError() {
- service_->service_connector_->RemoveService(
- static_cast<ServiceImpl*>(service_));
- }
- private:
- ServiceConnection<ServiceInterface, ServiceImpl, Context>* service_;
- };
friend class ServiceConnector<ServiceImpl, Context>;
- Reaper reaper_;
+
+ // Called shortly after this class is instantiated.
+ void set_connector(ServiceConnector<ServiceImpl, Context>* connector) {
+ service_connector_ = connector;
+ }
+
ServiceConnector<ServiceImpl, Context>* service_connector_;
- RemotePtr<typename ServiceInterface::_Peer> client_;
};
+template <typename Interface>
+inline void ConnectTo(Shell* shell, const std::string& url,
+ InterfacePtr<Interface>* ptr) {
+ MessagePipe pipe;
+ ptr->Bind(pipe.handle0.Pass());
+
+ AllocationScope scope;
+ shell->Connect(url, pipe.handle1.Pass());
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_SHELL_SERVICE_H_
diff --git a/mojo/public/interfaces/bindings/tests/math_calculator.mojom b/mojo/public/interfaces/bindings/tests/math_calculator.mojom
index e4a1c94..63b7a69 100644
--- a/mojo/public/interfaces/bindings/tests/math_calculator.mojom
+++ b/mojo/public/interfaces/bindings/tests/math_calculator.mojom
@@ -5,14 +5,13 @@
[JavaPackage="org.chromium.mojo.bindings.test"]
module math {
-[Peer=CalculatorUI]
+[Client=CalculatorUI]
interface Calculator {
Clear@0();
Add@1(double value @0);
Multiply@2(double value @0);
};
-[Peer=Calculator]
interface CalculatorUI {
Output@0(double value @0);
};
diff --git a/mojo/public/interfaces/bindings/tests/sample_factory.mojom b/mojo/public/interfaces/bindings/tests/sample_factory.mojom
index bad466f..33de19f 100644
--- a/mojo/public/interfaces/bindings/tests/sample_factory.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_factory.mojom
@@ -19,13 +19,12 @@ struct Response {
handle<message_pipe> pipe;
};
-[Peer=FactoryClient]
+[Client=FactoryClient]
interface Factory {
DoStuff(Request request, handle<message_pipe> pipe);
DoStuff2(handle<data_pipe_consumer> pipe);
};
-[Peer=Factory]
interface FactoryClient {
DidStuff(Response response, string text);
DidStuff2(string text);
diff --git a/mojo/public/interfaces/bindings/tests/sample_interfaces.mojom b/mojo/public/interfaces/bindings/tests/sample_interfaces.mojom
index 462e3cd..597fd0d 100644
--- a/mojo/public/interfaces/bindings/tests/sample_interfaces.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_interfaces.mojom
@@ -10,7 +10,7 @@ enum Enum {
ENUM_VALUE
};
-[Peer=ProviderClient]
+[Client=ProviderClient]
interface Provider {
EchoString(string a) => (string a);
EchoStrings(string a, string b) => (string a, string b);
@@ -18,7 +18,7 @@ interface Provider {
EchoEnum(Enum a) => (Enum a);
};
-[Peer=Provider]
+// TODO(darin): We shouldn't need this, but JS bindings don't work without it.
interface ProviderClient {
};
diff --git a/mojo/public/interfaces/bindings/tests/sample_service.mojom b/mojo/public/interfaces/bindings/tests/sample_service.mojom
index 0336998..c840709 100644
--- a/mojo/public/interfaces/bindings/tests/sample_service.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_service.mojom
@@ -53,7 +53,7 @@ struct DefaultsTest {
Bar.Type bar_type = Bar.TYPE_BOTH;
};
-[Peer=ServiceClient]
+[Client=ServiceClient]
interface Service {
enum BazOptions {
BAZ_REGULAR = 0,
@@ -62,7 +62,6 @@ interface Service {
Frobinate@0(Foo foo @0, BazOptions baz @1, Port port @2);
};
-[Peer=Service]
interface ServiceClient {
DidFrobinate@0(int32 result @0);
};
@@ -70,7 +69,7 @@ interface ServiceClient {
// This interface is referenced above where it is defined. It also refers to
// itself from a method.
interface Port {
- PostMessage@0(string message_text @0, Port[] extra_ports@1);
+ PostMessage@0(string message_text @0, Port port@1);
};
}
diff --git a/mojo/public/interfaces/shell/shell.mojom b/mojo/public/interfaces/shell/shell.mojom
index 39eae78..e5f6c39 100644
--- a/mojo/public/interfaces/shell/shell.mojom
+++ b/mojo/public/interfaces/shell/shell.mojom
@@ -4,14 +4,13 @@
module mojo {
-[Peer=ShellClient]
+[Client=ShellClient]
interface Shell {
// Loads url. mojo:{service} will result in the user of the value of the
// --origin flag to the shell being used.
Connect(string url, handle<message_pipe> client_handle);
};
-[Peer=Shell]
interface ShellClient {
AcceptConnection(string url, handle<message_pipe> client_handle);
};
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
index 60fbfc5..d1c7e53 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
@@ -1,18 +1,18 @@
{%- import "interface_macros.tmpl" as interface_macros %}
class {{interface.name}}Proxy;
class {{interface.name}}Stub;
-{% if interface.peer %}
-class {{interface.peer}};
+{% if interface.client %}
+class {{interface.client}};
{% endif %}
class {{interface.name}} {
public:
- typedef {{interface.name}}Proxy _Proxy;
- typedef {{interface.name}}Stub _Stub;
-{% if interface.peer %}
- typedef {{interface.peer}} _Peer;
+ typedef {{interface.name}}Proxy Proxy_;
+ typedef {{interface.name}}Stub Stub_;
+{% if interface.client %}
+ typedef {{interface.client}} Client_;
{% else %}
- typedef mojo::NoInterface _Peer;
+ typedef mojo::NoInterface Client_;
{% endif %}
{#--- Enums #}
@@ -22,6 +22,13 @@ class {{interface.name}} {
{%- endfor %}
{#--- Methods #}
+ virtual ~{{interface.name}}() {}
+{%- if interface.client %}
+ // Called once before any other method.
+ virtual void SetClient({{interface.client}}* client) = 0;
+{%- else %}
+ virtual void SetClient(mojo::NoInterface* client) {}
+{%- endif %}
{%- for method in interface.methods %}
virtual void {{method.name}}({{interface_macros.declare_request_params("", method)}}) = 0;
{%- endfor %}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl
index 7a03023..ccd4b42 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl
@@ -6,6 +6,8 @@
{%- for param in parameters %}
{%- if param.kind|is_object_kind -%}
mojo::internal::Wrap(params->{{param.name}}())
+{%- elif param.kind|is_interface_kind -%}
+mojo::MakeProxy<{{param.kind.name}}>(mojo::MakePassable(params->{{param.name}}()).Pass())
{%- elif param.kind|is_handle_kind -%}
mojo::MakePassable(params->{{param.name}}()).Pass()
{%- elif param.kind|is_enum_kind -%}
@@ -38,6 +40,14 @@ params->{{param.name}}()
if (!in_{{param.name}}.is_null())
params->set_{{param.name}}(
mojo::internal::Unwrap(in_{{param.name}})->Clone(builder.buffer()));
+{%- elif param.kind|is_interface_kind %}
+ if (!in_{{param.name}}.get()) {
+ params->set_{{param.name}}(mojo::MessagePipeHandle());
+ } else {
+ // Delegate handle.
+ params->set_{{param.name}}(
+ in_{{param.name}}.ResetAndReturnMessagePipe().release());
+ }
{%- elif param.kind|is_handle_kind %}
params->set_{{param.name}}(in_{{param.name}}.release());
{%- else %}
@@ -165,8 +175,8 @@ void {{class_name}}_{{method.name}}_ProxyToResponder::Run(
{%- endif -%}
{%- endfor %}
-{{class_name}}Stub::{{class_name}}Stub({{class_name}}* sink)
- : sink_(sink) {
+{{class_name}}Stub::{{class_name}}Stub()
+ : sink_(NULL) {
}
{#--- Stub definition #}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl
index c4a8bed..b9cf4bc 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl
@@ -3,6 +3,12 @@ class {{interface.name}}Proxy : public {{interface.name}} {
public:
explicit {{interface.name}}Proxy(mojo::MessageReceiver* receiver);
+{%- if interface.client %}
+ virtual void SetClient({{interface.client}}* client) = 0;
+{%- else %}
+ virtual void SetClient(mojo::NoInterface* client) {}
+{%- endif %}
+
{%- for method in interface.methods %}
virtual void {{method.name}}(
{{interface_macros.declare_request_params("", method)}}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
index 0e4b202..b435d5d 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
@@ -1,6 +1,8 @@
class {{interface.name}}Stub : public mojo::MessageReceiver {
public:
- explicit {{interface.name}}Stub({{interface.name}}* sink);
+ {{interface.name}}Stub();
+ void set_sink({{interface.name}}* sink) { sink_ = sink; }
+ {{interface.name}}* sink() { return sink_; }
virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(mojo::Message* message,
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
index 4c667ae..6a0f6cf 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
@@ -10,7 +10,9 @@
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/callback.h"
-#include "mojo/public/cpp/bindings/interface.h"
+#include "mojo/public/cpp/bindings/interface_impl.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+#include "mojo/public/cpp/bindings/no_interface.h"
#include "{{module.path}}-internal.h"
{%- for import in imports %}
#include "{{import.module.path}}.h"
@@ -28,10 +30,7 @@ namespace {{namespace}} {
{#--- Interface Forward Declarations -#}
{% for interface in interfaces %}
class {{interface.name}};
-// A typesafe variant of MessagePipeHandle:
-typedef mojo::Interface<{{interface.name}}>::Handle {{interface.name}}Handle;
-// A typesafe variant of ScopedMessagePipeHandle:
-typedef mojo::Interface<{{interface.name}}>::ScopedHandle Scoped{{interface.name}}Handle;
+typedef mojo::InterfacePtr<{{interface.name}}> {{interface.name}}Ptr;
{% endfor %}
{#--- Structs #}
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index 8f48f8e..3996d5e 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -50,7 +50,7 @@ def GetCppType(kind):
if isinstance(kind, mojom.Array):
return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "%sHandle" % kind.name
+ return "mojo::MessagePipeHandle"
if isinstance(kind, mojom.Enum):
return "int32_t"
if kind.spec == 's':
@@ -63,7 +63,7 @@ def GetCppArrayArgWrapperType(kind):
if isinstance(kind, mojom.Array):
return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "%sHandle" % kind.name
+ raise Exception("Arrays of interfaces not yet supported!")
if kind.spec == 's':
return "mojo::String"
return _kind_to_cpp_type[kind]
@@ -74,7 +74,7 @@ def GetCppResultWrapperType(kind):
if isinstance(kind, mojom.Array):
return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "Scoped%sHandle" % kind.name
+ return "%sPtr" % kind.name
if kind.spec == 's':
return "mojo::String"
if kind.spec == 'h':
@@ -95,7 +95,7 @@ def GetCppWrapperType(kind):
if isinstance(kind, mojom.Array):
return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "mojo::Passable<%sHandle>" % kind.name
+ return "mojo::Passable<mojo::MessagePipeHandle>"
if kind.spec == 's':
return "mojo::String"
if generator.IsHandleKind(kind):
@@ -108,7 +108,7 @@ def GetCppConstWrapperType(kind):
if isinstance(kind, mojom.Array):
return "const mojo::Array<%s >&" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "Scoped%sHandle" % kind.name
+ return "%sPtr" % kind.name
if isinstance(kind, mojom.Enum):
return GetNameForKind(kind)
if kind.spec == 's':
@@ -134,7 +134,7 @@ def GetCppFieldType(kind):
if isinstance(kind, mojom.Array):
return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind)
if isinstance(kind, mojom.Interface):
- return "%sHandle" % kind.name
+ return "mojo::MessagePipeHandle"
if isinstance(kind, mojom.Enum):
return GetNameForKind(kind)
if kind.spec == 's':
@@ -180,6 +180,7 @@ class Generator(generator.Generator):
"get_pad": pack.GetPad,
"is_enum_kind": generator.IsEnumKind,
"is_handle_kind": generator.IsHandleKind,
+ "is_interface_kind": generator.IsInterfaceKind,
"is_object_kind": generator.IsObjectKind,
"is_string_kind": generator.IsStringKind,
"is_array_kind": lambda kind: isinstance(kind, mojom.Array),
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/data.py b/mojo/public/tools/bindings/pylib/mojom/generate/data.py
index 1f2f808..2199782 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/data.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/data.py
@@ -221,7 +221,7 @@ def MethodFromData(module, data, interface):
def InterfaceToData(interface):
return {
istr(0, 'name'): interface.name,
- istr(1, 'peer'): interface.peer,
+ istr(1, 'client'): interface.client,
istr(2, 'methods'): map(MethodToData, interface.methods)
}
@@ -229,7 +229,7 @@ def InterfaceFromData(module, data):
interface = mojom.Interface(module=module)
interface.name = data['name']
interface.spec = 'x:' + module.namespace + '.' + interface.name
- interface.peer = data['peer'] if data.has_key('peer') else None
+ interface.client = data['client'] if data.has_key('client') else None
module.kinds[interface.spec] = interface
interface.enums = map(lambda enum:
EnumFromData(module, enum, interface), data['enums'])
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/data_tests.py b/mojo/public/tools/bindings/pylib/mojom/generate/data_tests.py
index bca7ed8..096554c 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/data_tests.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/data_tests.py
@@ -44,7 +44,7 @@ test_dict = {
{'name': 'testfield2', 'kind': 'a:i32', 'ordinal': 42}]}],
'interfaces': [{
'name': 'Server',
- 'peer': None,
+ 'client': None,
'methods': [{
'name': 'Foo',
'parameters': [
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
index 709aa2a..76e5998 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/generator.py
@@ -46,6 +46,9 @@ def IsObjectKind(kind):
def IsHandleKind(kind):
return kind.spec.startswith('h') or isinstance(kind, mojom.Interface)
+def IsInterfaceKind(kind):
+ return isinstance(kind, mojom.Interface)
+
def StudlyCapsToCamel(studly):
return studly[0].lower() + studly[1:]
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/module.py b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
index 4abe690..875ede9 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
@@ -139,7 +139,7 @@ class Method(object):
class Interface(Kind):
- def __init__(self, name=None, peer=None, module=None):
+ def __init__(self, name=None, client=None, module=None):
self.module = module
self.name = name
if name != None:
@@ -147,7 +147,7 @@ class Interface(Kind):
else:
spec = None
Kind.__init__(self, spec)
- self.peer = peer
+ self.client = client
self.methods = []
def AddMethod(self, name, ordinal=None):
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
index 2300cb6..b363d9c 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
@@ -88,7 +88,7 @@ def _MapStruct(tree):
def _MapInterface(tree):
interface = {}
interface['name'] = tree[1]
- interface['peer'] = _GetAttribute(tree[2], 'Peer')
+ interface['client'] = _GetAttribute(tree[2], 'Client')
interface['methods'] = _MapTree(_MapMethod, tree[3], 'METHOD')
interface['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM')
return interface
diff --git a/mojo/service_manager/background_service_loader.cc b/mojo/service_manager/background_service_loader.cc
index ba365b0..d4dcd4a 100644
--- a/mojo/service_manager/background_service_loader.cc
+++ b/mojo/service_manager/background_service_loader.cc
@@ -16,7 +16,7 @@ class BackgroundServiceLoader::BackgroundLoader {
void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle shell_handle) {
+ ScopedMessagePipeHandle shell_handle) {
loader_->LoadService(manager, url, shell_handle.Pass());
}
@@ -48,16 +48,18 @@ BackgroundServiceLoader::~BackgroundServiceLoader() {
thread_.Stop();
}
-void BackgroundServiceLoader::LoadService(ServiceManager* manager,
- const GURL& url,
- ScopedShellHandle service_handle) {
+void BackgroundServiceLoader::LoadService(
+ ServiceManager* manager,
+ const GURL& url,
+ ScopedMessagePipeHandle service_handle) {
if (!thread_.IsRunning())
thread_.Start();
thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread,
base::Unretained(this), manager, url,
- base::Owned(new ScopedShellHandle(service_handle.Pass()))));
+ base::Owned(
+ new ScopedMessagePipeHandle(service_handle.Pass()))));
}
void BackgroundServiceLoader::OnServiceError(ServiceManager* manager,
@@ -73,7 +75,7 @@ void BackgroundServiceLoader::OnServiceError(ServiceManager* manager,
void BackgroundServiceLoader::LoadServiceOnBackgroundThread(
ServiceManager* manager,
const GURL& url,
- ScopedShellHandle* shell_handle) {
+ ScopedMessagePipeHandle* shell_handle) {
if (!background_loader_)
background_loader_ = new BackgroundLoader(loader_.get());
background_loader_->LoadService(manager, url, shell_handle->Pass());
diff --git a/mojo/service_manager/background_service_loader.h b/mojo/service_manager/background_service_loader.h
index b505941..bdfae0c 100644
--- a/mojo/service_manager/background_service_loader.h
+++ b/mojo/service_manager/background_service_loader.h
@@ -25,7 +25,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
// ServiceLoader overrides:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) OVERRIDE;
+ ScopedMessagePipeHandle service_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE;
@@ -38,7 +38,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
// thread safe).
void LoadServiceOnBackgroundThread(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle* shell_handle);
+ ScopedMessagePipeHandle* shell_handle);
void OnServiceErrorOnBackgroundThread(ServiceManager* manager,
const GURL& url);
void ShutdownOnBackgroundThread();
diff --git a/mojo/service_manager/service_loader.h b/mojo/service_manager/service_loader.h
index 7567ad3..4053957 100644
--- a/mojo/service_manager/service_loader.h
+++ b/mojo/service_manager/service_loader.h
@@ -20,7 +20,7 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceLoader {
virtual ~ServiceLoader() {}
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) = 0;
+ ScopedMessagePipeHandle service_handle) = 0;
virtual void OnServiceError(ServiceManager* manager, const GURL& url) = 0;
protected:
diff --git a/mojo/service_manager/service_manager.cc b/mojo/service_manager/service_manager.cc
index b62c6e14b..0a526fa 100644
--- a/mojo/service_manager/service_manager.cc
+++ b/mojo/service_manager/service_manager.cc
@@ -11,8 +11,6 @@
#include "base/macros.h"
#include "base/stl_util.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/service_manager/service_loader.h"
namespace mojo {
@@ -22,74 +20,74 @@ namespace {
bool has_created_instance = false;
}
-class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
+class ServiceManager::ServiceFactory : public InterfaceImpl<Shell> {
public:
ServiceFactory(ServiceManager* manager, const GURL& url)
: manager_(manager),
- url_(url) {
- InterfacePipe<Shell> pipe;
- shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
- manager_->GetLoaderForURL(url)->LoadService(manager_,
- url,
- pipe.handle_to_self.Pass());
+ url_(url),
+ client_(NULL) {
}
- virtual ~ServiceFactory() {}
+ virtual ~ServiceFactory() {
+ }
void ConnectToClient(ScopedMessagePipeHandle handle) {
- if (handle.is_valid()) {
- AllocationScope scope;
- shell_client_->AcceptConnection(url_.spec(), handle.Pass());
+ if (!handle.is_valid()) {
+ assert(false);
+ return;
}
+ AllocationScope scope;
+ client_->AcceptConnection(url_.spec(), handle.Pass());
}
+ // Shell implementation:
+ virtual void SetClient(ShellClient* client) OVERRIDE {
+ client_ = client;
+ }
virtual void Connect(const String& url,
ScopedMessagePipeHandle client_pipe) OVERRIDE {
manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
}
- virtual void OnError() OVERRIDE {
- manager_->OnServiceFactoryError(this);
- }
-
const GURL& url() const { return url_; }
private:
+ virtual void OnConnectionError() OVERRIDE {
+ manager_->OnServiceFactoryError(this);
+ }
+
ServiceManager* const manager_;
const GURL url_;
- RemotePtr<ShellClient> shell_client_;
+ ShellClient* client_;
DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
};
class ServiceManager::TestAPI::TestShellConnection
- : public Shell,
- public ErrorHandler {
+ : public InterfaceImpl<Shell> {
public:
- explicit TestShellConnection(ServiceManager* manager) : manager_(manager) {
- InterfacePipe<Shell> pipe;
- shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
- shell_handle_ = pipe.handle_to_self.Pass();
+ explicit TestShellConnection(ServiceManager* manager)
+ : manager_(manager),
+ client_(NULL) {
}
virtual ~TestShellConnection() {}
- ScopedShellHandle GetShellHandle() {
- return shell_handle_.Pass();
+ virtual void OnConnectionError() OVERRIDE {
+ // TODO(darin): How should we handle this error?
}
// Shell:
+ virtual void SetClient(ShellClient* client) OVERRIDE {
+ client_ = client;
+ }
virtual void Connect(const String& url,
ScopedMessagePipeHandle client_pipe) OVERRIDE {
manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
}
- virtual void OnError() OVERRIDE {
- }
-
private:
ServiceManager* manager_;
- RemotePtr<ShellClient> shell_client_;
- ScopedShellHandle shell_handle_;
+ ShellClient* client_;
DISALLOW_COPY_AND_ASSIGN(TestShellConnection);
};
@@ -105,15 +103,16 @@ bool ServiceManager::TestAPI::HasCreatedInstance() {
return has_created_instance;
}
-ScopedShellHandle ServiceManager::TestAPI::GetShellHandle() {
- if (!shell_connection_.get())
- shell_connection_.reset(new TestShellConnection(manager_));
- return shell_connection_->GetShellHandle().Pass();
+ScopedMessagePipeHandle ServiceManager::TestAPI::GetShellHandle() {
+ MessagePipe pipe;
+ shell_.reset(
+ BindToPipe(new TestShellConnection(manager_), pipe.handle0.Pass()));
+ return pipe.handle1.Pass();
}
bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
return manager_->url_to_service_factory_.find(url) !=
- manager_->url_to_service_factory_.end();
+ manager_->url_to_service_factory_.end();
}
ServiceManager::ServiceManager()
@@ -142,7 +141,12 @@ void ServiceManager::Connect(const GURL& url,
if (service_it != url_to_service_factory_.end()) {
service_factory = service_it->second;
} else {
- service_factory = new ServiceFactory(this, url);
+ MessagePipe pipe;
+ GetLoaderForURL(url)->LoadService(this, url, pipe.handle0.Pass());
+
+ service_factory =
+ BindToPipe(new ServiceFactory(this, url), pipe.handle1.Pass());
+
url_to_service_factory_[url] = service_factory;
}
if (interceptor_) {
@@ -186,6 +190,7 @@ ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) {
}
void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
+ // Called from ~ServiceFactory, so we do not need to call Destroy here.
const GURL url = service_factory->url();
URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
DCHECK(it != url_to_service_factory_.end());
diff --git a/mojo/service_manager/service_manager.h b/mojo/service_manager/service_manager.h
index 1e3fcbd..81e129a 100644
--- a/mojo/service_manager/service_manager.h
+++ b/mojo/service_manager/service_manager.h
@@ -25,8 +25,8 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
explicit TestAPI(ServiceManager* manager);
~TestAPI();
- // Returns a handle to the shell.
- ScopedShellHandle GetShellHandle();
+ // Returns a handle to a unique shell instance.
+ ScopedMessagePipeHandle GetShellHandle();
// Returns true if the shared instance has been created.
static bool HasCreatedInstance();
@@ -37,8 +37,7 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
class TestShellConnection;
ServiceManager* manager_;
-
- scoped_ptr<TestShellConnection> shell_connection_;
+ scoped_ptr<TestShellConnection> shell_;
DISALLOW_COPY_AND_ASSIGN(TestAPI);
};
@@ -85,7 +84,7 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
// then one that's been specified for a scheme, then the default.
ServiceLoader* GetLoaderForURL(const GURL& url);
- // Removes a ServiceFactory when it no longer has any connections.
+ // Removes a ServiceFactory when it encounters an error.
void OnServiceFactoryError(ServiceFactory* service_factory);
// Loader management.
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc
index 54a6b7d..a371f95 100644
--- a/mojo/service_manager/service_manager_unittest.cc
+++ b/mojo/service_manager/service_manager_unittest.cc
@@ -4,7 +4,6 @@
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
@@ -28,33 +27,37 @@ struct TestContext {
class TestServiceImpl :
public ServiceConnection<TestService, TestServiceImpl, TestContext> {
public:
- TestServiceImpl() {}
+ TestServiceImpl() : client_(NULL) {}
virtual ~TestServiceImpl() {
if (context())
--context()->num_impls;
}
+ void Initialize() {
+ if (context())
+ ++context()->num_impls;
+ }
+
+ // TestService implementation:
+ virtual void SetClient(TestClient* client) OVERRIDE {
+ client_ = client;
+ }
virtual void Test(const mojo::String& test_string) OVERRIDE {
context()->last_test_string = test_string.To<std::string>();
- client()->AckTest();
+ client_->AckTest();
}
- void Initialize(
- ServiceConnector<TestServiceImpl, TestContext>* service_factory,
- ScopedMessagePipeHandle client_handle) {
- ServiceConnection<TestService, TestServiceImpl, TestContext>::Initialize(
- service_factory, client_handle.Pass());
- if (context())
- ++context()->num_impls;
- }
+ private:
+ TestClient* client_;
};
class TestClientImpl : public TestClient {
public:
- explicit TestClientImpl(ScopedTestServiceHandle service_handle)
- : service_(service_handle.Pass(), this),
+ explicit TestClientImpl(TestServicePtr service)
+ : service_(service.Pass()),
quit_after_ack_(false) {
+ service_->SetClient(this);
}
virtual ~TestClientImpl() {}
@@ -67,11 +70,11 @@ class TestClientImpl : public TestClient {
void Test(std::string test_string) {
AllocationScope scope;
quit_after_ack_ = true;
- service_->Test(mojo::String(test_string));
+ service_->Test(test_string);
}
private:
- RemotePtr<TestService> service_;
+ TestServicePtr service_;
bool quit_after_ack_;
DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
};
@@ -100,7 +103,7 @@ class TestServiceLoader : public ServiceLoader {
private:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle shell_handle) OVERRIDE {
+ ScopedMessagePipeHandle shell_handle) OVERRIDE {
++num_loads_;
test_app_.reset(new Application(shell_handle.Pass()));
test_app_->AddServiceConnector(
@@ -162,14 +165,17 @@ class ServiceManagerTest : public testing::Test {
GURL test_url(kTestURLString);
service_manager_.reset(new ServiceManager);
- InterfacePipe<TestService, AnyInterface> pipe;
- test_client_.reset(new TestClientImpl(pipe.handle_to_self.Pass()));
+ MessagePipe pipe;
+ TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass());
+ test_client_.reset(new TestClientImpl(service_proxy.Pass()));
+
TestServiceLoader* default_loader = new TestServiceLoader;
default_loader->set_context(&context_);
default_loader->set_quit_after_error(true);
service_manager_->set_default_loader(
scoped_ptr<ServiceLoader>(default_loader));
- service_manager_->Connect(test_url, pipe.handle_to_peer.Pass());
+
+ service_manager_->Connect(test_url, pipe.handle1.Pass());
}
virtual void TearDown() OVERRIDE {
@@ -243,22 +249,22 @@ TEST_F(ServiceManagerTest, SetLoaders) {
sm.SetLoaderForScheme(scoped_ptr<ServiceLoader>(scheme_loader), "test");
// test::test1 should go to url_loader.
- InterfacePipe<TestService, AnyInterface> pipe1;
- sm.Connect(GURL("test:test1"), pipe1.handle_to_peer.Pass());
+ MessagePipe pipe1;
+ sm.Connect(GURL("test:test1"), pipe1.handle0.Pass());
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(0, scheme_loader->num_loads());
EXPECT_EQ(0, default_loader->num_loads());
// test::test2 should go to scheme loader.
- InterfacePipe<TestService, AnyInterface> pipe2;
- sm.Connect(GURL("test:test2"), pipe2.handle_to_peer.Pass());
+ MessagePipe pipe2;
+ sm.Connect(GURL("test:test2"), pipe2.handle0.Pass());
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(1, scheme_loader->num_loads());
EXPECT_EQ(0, default_loader->num_loads());
// http::test1 should go to default loader.
- InterfacePipe<TestService, AnyInterface> pipe3;
- sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass());
+ MessagePipe pipe3;
+ sm.Connect(GURL("http:test1"), pipe3.handle0.Pass());
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(1, scheme_loader->num_loads());
EXPECT_EQ(1, default_loader->num_loads());
@@ -272,8 +278,8 @@ TEST_F(ServiceManagerTest, Interceptor) {
sm.SetInterceptor(&interceptor);
std::string url("test:test3");
- InterfacePipe<TestService, AnyInterface> pipe1;
- sm.Connect(GURL(url), pipe1.handle_to_peer.Pass());
+ MessagePipe pipe1;
+ sm.Connect(GURL(url), pipe1.handle0.Pass());
EXPECT_EQ(1, interceptor.call_count());
EXPECT_EQ(url, interceptor.url_spec());
EXPECT_EQ(1, default_loader->num_loads());
diff --git a/mojo/service_manager/test.mojom b/mojo/service_manager/test.mojom
index 59ebfa9..1aff920 100644
--- a/mojo/service_manager/test.mojom
+++ b/mojo/service_manager/test.mojom
@@ -4,12 +4,11 @@
module mojo {
-[Peer=TestClient]
+[Client=TestClient]
interface TestService {
Test(string test_string);
};
-[Peer=TestService]
interface TestClient {
AckTest();
};
diff --git a/mojo/services/dbus_echo/dbus_echo_service.cc b/mojo/services/dbus_echo/dbus_echo_service.cc
index 70762f6..f1f5ced 100644
--- a/mojo/services/dbus_echo/dbus_echo_service.cc
+++ b/mojo/services/dbus_echo/dbus_echo_service.cc
@@ -12,13 +12,12 @@
#include "mojo/common/channel_init.h"
#include "mojo/dbus/dbus_external_service.h"
#include "mojo/embedder/embedder.h"
-#include "mojo/public/cpp/bindings/interface.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/services/dbus_echo/echo.mojom.h"
namespace {
-class EchoServiceImpl : public mojo::ServiceConnection<mojo::EchoService,
- EchoServiceImpl> {
+class EchoServiceImpl
+ : public mojo::ServiceConnection<mojo::EchoService, EchoServiceImpl> {
public:
EchoServiceImpl() {}
virtual ~EchoServiceImpl() {}
diff --git a/mojo/services/dbus_echo/echo.mojom b/mojo/services/dbus_echo/echo.mojom
index c2ad42a..937737c 100644
--- a/mojo/services/dbus_echo/echo.mojom
+++ b/mojo/services/dbus_echo/echo.mojom
@@ -4,13 +4,8 @@
module mojo {
-[Peer=EchoClient]
interface EchoService {
Echo(string to_echo) => (string echoed);
};
-[Peer=EchoService]
-interface EchoClient {
-};
-
}
diff --git a/mojo/services/gles2/command_buffer.mojom b/mojo/services/gles2/command_buffer.mojom
index c10a9a3..1f91362 100644
--- a/mojo/services/gles2/command_buffer.mojom
+++ b/mojo/services/gles2/command_buffer.mojom
@@ -19,7 +19,7 @@ interface CommandBufferSyncClient {
DidMakeProgress(CommandBufferState state);
};
-[Peer=CommandBufferClient]
+[Client=CommandBufferClient]
interface CommandBuffer {
Initialize(CommandBufferSyncClient sync_client,
handle<shared_buffer> shared_state);
@@ -38,7 +38,6 @@ interface CommandBuffer {
// TODO(piman): sync points
};
-[Peer=CommandBuffer]
interface CommandBufferClient {
DidDestroy();
LostContext(int32 lost_reason); // TODO(piman): enum
@@ -48,4 +47,3 @@ interface CommandBufferClient {
};
}
-
diff --git a/mojo/services/gles2/command_buffer_impl.cc b/mojo/services/gles2/command_buffer_impl.cc
index bbeb393..0e39837 100644
--- a/mojo/services/gles2/command_buffer_impl.cc
+++ b/mojo/services/gles2/command_buffer_impl.cc
@@ -48,10 +48,9 @@ class MemoryTrackerStub : public gpu::gles2::MemoryTracker {
} // anonymous namespace
-CommandBufferImpl::CommandBufferImpl(ScopedCommandBufferClientHandle client,
- gfx::AcceleratedWidget widget,
+CommandBufferImpl::CommandBufferImpl(gfx::AcceleratedWidget widget,
const gfx::Size& size)
- : client_(client.Pass(), this), widget_(widget), size_(size) {}
+ : widget_(widget), size_(size) {}
CommandBufferImpl::~CommandBufferImpl() {
client_->DidDestroy();
@@ -61,10 +60,18 @@ CommandBufferImpl::~CommandBufferImpl() {
}
}
+void CommandBufferImpl::OnConnectionError() {
+ // TODO(darin): How should we handle this error?
+}
+
+void CommandBufferImpl::SetClient(CommandBufferClient* client) {
+ client_ = client;
+}
+
void CommandBufferImpl::Initialize(
- ScopedCommandBufferSyncClientHandle sync_client,
+ CommandBufferSyncClientPtr sync_client,
mojo::ScopedSharedBufferHandle shared_state) {
- sync_client_.reset(sync_client.Pass(), NULL);
+ sync_client_ = sync_client.Pass();
sync_client_->DidInitialize(DoInitialize(shared_state.Pass()));
}
diff --git a/mojo/services/gles2/command_buffer_impl.h b/mojo/services/gles2/command_buffer_impl.h
index 3a461e5..e76a3d2 100644
--- a/mojo/services/gles2/command_buffer_impl.h
+++ b/mojo/services/gles2/command_buffer_impl.h
@@ -7,7 +7,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/services/gles2/command_buffer.mojom.h"
#include "ui/gfx/native_widget_types.h"
@@ -25,14 +24,15 @@ class GLES2Decoder;
namespace mojo {
namespace services {
-class CommandBufferImpl : public CommandBuffer {
+class CommandBufferImpl : public InterfaceImpl<CommandBuffer> {
public:
- CommandBufferImpl(ScopedCommandBufferClientHandle client,
- gfx::AcceleratedWidget widget,
+ CommandBufferImpl(gfx::AcceleratedWidget widget,
const gfx::Size& size);
virtual ~CommandBufferImpl();
- virtual void Initialize(ScopedCommandBufferSyncClientHandle sync_client,
+ virtual void OnConnectionError() OVERRIDE;
+ virtual void SetClient(CommandBufferClient* client) OVERRIDE;
+ virtual void Initialize(CommandBufferSyncClientPtr sync_client,
mojo::ScopedSharedBufferHandle shared_state) OVERRIDE;
virtual void SetGetBuffer(int32_t buffer) OVERRIDE;
virtual void Flush(int32_t put_offset) OVERRIDE;
@@ -54,8 +54,8 @@ class CommandBufferImpl : public CommandBuffer {
void DrawAnimationFrame();
- RemotePtr<CommandBufferClient> client_;
- RemotePtr<CommandBufferSyncClient> sync_client_;
+ CommandBufferClient* client_;
+ CommandBufferSyncClientPtr sync_client_;
gfx::AcceleratedWidget widget_;
gfx::Size size_;
diff --git a/mojo/services/native_viewport/native_viewport.mojom b/mojo/services/native_viewport/native_viewport.mojom
index 189ba12..eef750c 100644
--- a/mojo/services/native_viewport/native_viewport.mojom
+++ b/mojo/services/native_viewport/native_viewport.mojom
@@ -37,7 +37,7 @@ struct Event {
TouchData touch_data;
};
-[Peer=NativeViewportClient]
+[Client=NativeViewportClient]
interface NativeViewport {
Create(Rect bounds);
Show();
@@ -47,7 +47,6 @@ interface NativeViewport {
CreateGLES2Context(handle<message_pipe> gles2_client);
};
-[Peer=NativeViewport]
interface NativeViewportClient {
OnCreated();
OnBoundsChanged(Rect bounds);
diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc
index 9585ae7..faba578 100644
--- a/mojo/services/native_viewport/native_viewport_service.cc
+++ b/mojo/services/native_viewport/native_viewport_service.cc
@@ -34,7 +34,8 @@ class NativeViewportImpl
public NativeViewportDelegate {
public:
NativeViewportImpl()
- : widget_(gfx::kNullAcceleratedWidget),
+ : client_(NULL),
+ widget_(gfx::kNullAcceleratedWidget),
waiting_for_event_ack_(false) {}
virtual ~NativeViewportImpl() {
// Destroy the NativeViewport early on as it may call us back during
@@ -42,11 +43,15 @@ class NativeViewportImpl
native_viewport_.reset();
}
+ virtual void SetClient(NativeViewportClient* client) OVERRIDE {
+ client_ = client;
+ }
+
virtual void Create(const Rect& bounds) OVERRIDE {
native_viewport_ =
services::NativeViewport::Create(context(), this);
native_viewport_->Init(bounds);
- client()->OnCreated();
+ client_->OnCreated();
OnBoundsChanged(bounds);
}
@@ -72,17 +77,13 @@ class NativeViewportImpl
virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle)
OVERRIDE {
- if (command_buffer_ || command_buffer_handle_.is_valid()) {
+ if (command_buffer_.get() || command_buffer_handle_.is_valid()) {
LOG(ERROR) << "Can't create multiple contexts on a NativeViewport";
return;
}
- // TODO(darin):
- // CreateGLES2Context should accept a ScopedCommandBufferClientHandle once
- // it is possible to import interface definitions from another module. For
- // now, we just kludge it.
- command_buffer_handle_.reset(
- InterfaceHandle<CommandBufferClient>(client_handle.release().value()));
+ // TODO(darin): CreateGLES2Context should accept a |CommandBufferPtr*|.
+ command_buffer_handle_ = client_handle.Pass();
CreateCommandBufferIfNeeded();
}
@@ -100,8 +101,9 @@ class NativeViewportImpl
gfx::Size size = native_viewport_->GetSize();
if (size.IsEmpty())
return;
- command_buffer_.reset(new CommandBufferImpl(
- command_buffer_handle_.Pass(), widget_, native_viewport_->GetSize()));
+ command_buffer_.reset(
+ BindToPipe(new CommandBufferImpl(widget_, native_viewport_->GetSize()),
+ command_buffer_handle_.Pass()));
}
virtual bool OnEvent(ui::Event* ui_event) OVERRIDE {
@@ -151,9 +153,9 @@ class NativeViewportImpl
event.set_key_data(key_data.Finish());
}
- client()->OnEvent(event.Finish(),
- base::Bind(&NativeViewportImpl::AckEvent,
- base::Unretained(this)));
+ client_->OnEvent(event.Finish(),
+ base::Bind(&NativeViewportImpl::AckEvent,
+ base::Unretained(this)));
waiting_for_event_ack_ = true;
return false;
}
@@ -167,19 +169,20 @@ class NativeViewportImpl
virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE {
CreateCommandBufferIfNeeded();
AllocationScope scope;
- client()->OnBoundsChanged(bounds);
+ client_->OnBoundsChanged(bounds);
}
virtual void OnDestroyed() OVERRIDE {
command_buffer_.reset();
- client()->OnDestroyed();
+ client_->OnDestroyed();
base::MessageLoop::current()->Quit();
}
private:
+ NativeViewportClient* client_;
gfx::AcceleratedWidget widget_;
scoped_ptr<services::NativeViewport> native_viewport_;
- ScopedCommandBufferClientHandle command_buffer_handle_;
+ ScopedMessagePipeHandle command_buffer_handle_;
scoped_ptr<CommandBufferImpl> command_buffer_;
bool waiting_for_event_ack_;
};
@@ -190,7 +193,7 @@ class NativeViewportImpl
MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
CreateNativeViewportService(mojo::shell::Context* context,
- mojo::ScopedShellHandle shell_handle) {
+ mojo::ScopedMessagePipeHandle shell_handle) {
mojo::Application* app = new mojo::Application(shell_handle.Pass());
app->AddServiceConnector(
new mojo::ServiceConnector<mojo::services::NativeViewportImpl,
diff --git a/mojo/services/native_viewport/native_viewport_service.h b/mojo/services/native_viewport/native_viewport_service.h
index e56935c..d2a71eb 100644
--- a/mojo/services/native_viewport/native_viewport_service.h
+++ b/mojo/services/native_viewport/native_viewport_service.h
@@ -6,13 +6,12 @@
#define MOJO_SERVICES_NATIVE_VIEWPORT_SERVICE_H_
#include "base/memory/scoped_vector.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/shell/application.h"
#include "mojo/services/native_viewport/native_viewport_export.h"
#include "mojo/shell/context.h"
MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
CreateNativeViewportService(mojo::shell::Context* context,
- mojo::ScopedShellHandle shell_handle);
+ mojo::ScopedMessagePipeHandle shell_handle);
#endif // MOJO_SERVICES_NATIVE_VIEWPORT_SERVICE_H_
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
index 793255c..886b5fd 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc
@@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "mojo/public/cpp/bindings/allocation_scope.h"
+#include "mojo/public/cpp/shell/service.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
@@ -187,17 +187,16 @@ ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager)
next_change_id_(0),
sync_factory_(this),
init_loop_(NULL) {
- InterfacePipe<services::view_manager::IViewManager, AnyInterface>
- view_manager_pipe;
+ ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager",
+ &service_);
+ service_->SetClient(this);
+
AllocationScope scope;
- MessagePipeHandle client_handle = view_manager_pipe.handle_to_peer.get();
- ViewManagerPrivate(view_manager_).shell()->Connect(
- "mojo:mojo_view_manager", view_manager_pipe.handle_to_peer.Pass());
- service_.reset(view_manager_pipe.handle_to_self.Pass(), this);
service_->GetNodeTree(
1,
base::Bind(&ViewManagerSynchronizer::OnRootTreeReceived,
base::Unretained(this)));
+
base::RunLoop loop;
init_loop_ = &loop;
init_loop_->Run();
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
index 78ae300..7540d1b 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h
@@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
@@ -94,7 +93,7 @@ class ViewManagerSynchronizer : public IViewManagerClient {
// construction.
base::RunLoop* init_loop_;
- RemotePtr<IViewManager> service_;
+ IViewManagerPtr service_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer);
};
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index ebc82cb..bbe577b 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -21,7 +21,7 @@ struct INode {
// uint16 as the connection id of the originating connection is used.
//
// The root node is identified with a connection id of 0, and value of 1.
-[Peer=IViewManagerClient]
+[Client=IViewManagerClient]
interface IViewManager {
// Creates a new node with the specified id. It is up to the client to ensure
// the id is unique to the connection (the id need not be globally unique).
@@ -60,7 +60,6 @@ interface IViewManager {
uint32 buffer_size);
};
-[Peer=IViewManager]
interface IViewManagerClient {
// Invoked once the connection has been established. |connection_id| is the id
// used to uniquely identify the connection.
diff --git a/mojo/services/view_manager/main.cc b/mojo/services/view_manager/main.cc
index 1fd4528..7754a1e 100644
--- a/mojo/services/view_manager/main.cc
+++ b/mojo/services/view_manager/main.cc
@@ -26,10 +26,10 @@ extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
base::MessageLoop loop;
mojo::Application app(shell_handle);
mojo::services::view_manager::RootNodeManager root_node_manager(app.shell());
- app.AddServiceConnector(new mojo::ServiceConnector
- <mojo::services::view_manager::ViewManagerConnection,
- mojo::services::view_manager::RootNodeManager>(
- &root_node_manager));
+ app.AddServiceConnector(
+ new mojo::ServiceConnector<
+ mojo::services::view_manager::ViewManagerConnection,
+ mojo::services::view_manager::RootNodeManager>(&root_node_manager));
loop.Run();
return MOJO_RESULT_OK;
diff --git a/mojo/services/view_manager/root_view_manager.cc b/mojo/services/view_manager/root_view_manager.cc
index 791d1b9..2721fed 100644
--- a/mojo/services/view_manager/root_view_manager.cc
+++ b/mojo/services/view_manager/root_view_manager.cc
@@ -7,7 +7,7 @@
#include "base/auto_reset.h"
#include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h"
-#include "mojo/public/cpp/bindings/allocation_scope.h"
+#include "mojo/public/cpp/shell/service.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/services/view_manager/root_node_manager.h"
#include "ui/aura/client/default_capture_client.h"
@@ -53,12 +53,10 @@ RootViewManager::RootViewManager(Shell* shell, RootNodeManager* root_node)
in_setup_(false) {
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
- InterfacePipe<NativeViewport, AnyInterface> pipe;
- mojo::AllocationScope scope;
- shell_->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
+ NativeViewportPtr viewport;
+ ConnectTo(shell, "mojo:mojo_native_viewport_service", &viewport);
window_tree_host_.reset(new WindowTreeHostMojo(
- pipe.handle_to_self.Pass(),
+ viewport.Pass(),
gfx::Rect(800, 600),
base::Bind(&RootViewManager::OnCompositorCreated,
base::Unretained(this))));
diff --git a/mojo/services/view_manager/view_manager_connection.cc b/mojo/services/view_manager/view_manager_connection.cc
index e1a4650..6b92323 100644
--- a/mojo/services/view_manager/view_manager_connection.cc
+++ b/mojo/services/view_manager/view_manager_connection.cc
@@ -58,7 +58,7 @@ void NodeToINode(Node* node,
} // namespace
-ViewManagerConnection::ViewManagerConnection() : id_(0) {
+ViewManagerConnection::ViewManagerConnection() : client_(NULL), id_(0) {
}
ViewManagerConnection::~ViewManagerConnection() {
@@ -80,15 +80,11 @@ ViewManagerConnection::~ViewManagerConnection() {
context()->RemoveConnection(this);
}
-void ViewManagerConnection::Initialize(
- ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory,
- ScopedMessagePipeHandle client_handle) {
+void ViewManagerConnection::Initialize() {
DCHECK_EQ(0, id_); // Should only get Initialize() once.
- ServiceConnection<IViewManager, ViewManagerConnection, RootNodeManager>::
- Initialize(service_factory, client_handle.Pass());
id_ = context()->GetAndAdvanceNextConnectionId();
context()->AddConnection(this);
- client()->OnConnectionEstablished(id_);
+ client_->OnConnectionEstablished(id_);
}
Node* ViewManagerConnection::GetNode(const NodeId& id) {
@@ -112,7 +108,7 @@ void ViewManagerConnection::NotifyNodeHierarchyChanged(
const NodeId& new_parent,
const NodeId& old_parent,
TransportChangeId change_id) {
- client()->OnNodeHierarchyChanged(NodeIdToTransportId(node),
+ client_->OnNodeHierarchyChanged(NodeIdToTransportId(node),
NodeIdToTransportId(new_parent),
NodeIdToTransportId(old_parent),
change_id);
@@ -123,7 +119,7 @@ void ViewManagerConnection::NotifyNodeViewReplaced(
const ViewId& new_view_id,
const ViewId& old_view_id,
TransportChangeId change_id) {
- client()->OnNodeViewReplaced(NodeIdToTransportId(node),
+ client_->OnNodeViewReplaced(NodeIdToTransportId(node),
ViewIdToTransportId(new_view_id),
ViewIdToTransportId(old_view_id),
change_id);
@@ -131,7 +127,7 @@ void ViewManagerConnection::NotifyNodeViewReplaced(
void ViewManagerConnection::NotifyNodeDeleted(const NodeId& node,
TransportChangeId change_id) {
- client()->OnNodeDeleted(NodeIdToTransportId(node), change_id);
+ client_->OnNodeDeleted(NodeIdToTransportId(node), change_id);
}
bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source,
@@ -183,6 +179,10 @@ bool ViewManagerConnection::SetViewImpl(const NodeId& node_id,
return true;
}
+void ViewManagerConnection::SetClient(IViewManagerClient* client) {
+ client_ = client;
+}
+
void ViewManagerConnection::CreateNode(
TransportConnectionSpecificNodeId node_id,
const Callback<void(bool)>& callback) {
diff --git a/mojo/services/view_manager/view_manager_connection.h b/mojo/services/view_manager/view_manager_connection.h
index 2dc31d8..51f1642 100644
--- a/mojo/services/view_manager/view_manager_connection.h
+++ b/mojo/services/view_manager/view_manager_connection.h
@@ -33,10 +33,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
TransportConnectionId id() const { return id_; }
- // Invoked from Service when connection is established.
- void Initialize(
- ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory,
- ScopedMessagePipeHandle client_handle);
+ // Invoked when connection is established.
+ void Initialize();
// Returns the Node with the specified id.
Node* GetNode(const NodeId& id);
@@ -77,6 +75,7 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
TransportChangeId change_id);
// Overridden from IViewManager:
+ virtual void SetClient(IViewManagerClient* client) OVERRIDE;
virtual void CreateNode(TransportConnectionSpecificNodeId node_id,
const Callback<void(bool)>& callback) OVERRIDE;
virtual void DeleteNode(TransportNodeId transport_node_id,
@@ -114,6 +113,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
const ViewId& new_view_id,
const ViewId& old_view_id) OVERRIDE;
+ IViewManagerClient* client_;
+
// Id of this connection as assigned by RootNodeManager. Assigned in
// Initialize().
TransportConnectionId id_;
diff --git a/mojo/services/view_manager/view_manager_connection_unittest.cc b/mojo/services/view_manager/view_manager_connection_unittest.cc
index 48c520d..6c71f39 100644
--- a/mojo/services/view_manager/view_manager_connection_unittest.cc
+++ b/mojo/services/view_manager/view_manager_connection_unittest.cc
@@ -12,6 +12,7 @@
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/environment/environment.h"
+#include "mojo/public/cpp/shell/service.h"
#include "mojo/services/public/cpp/view_manager/util.h"
#include "mojo/services/public/cpp/view_manager/view_manager_types.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
@@ -252,14 +253,10 @@ class ViewManagerConnectionTest : public testing::Test {
ViewManagerConnectionTest() {}
virtual void SetUp() OVERRIDE {
- AllocationScope allocation_scope;
-
test_helper_.Init();
- InterfacePipe<IViewManager, AnyInterface> pipe;
- test_helper_.shell()->Connect("mojo:mojo_view_manager",
- pipe.handle_to_peer.Pass());
- view_manager_.reset(pipe.handle_to_self.Pass(), &client_);
+ ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager_);
+ view_manager_->SetClient(&client_);
client_.WaitForId();
}
@@ -267,11 +264,8 @@ class ViewManagerConnectionTest : public testing::Test {
protected:
// Creates a second connection to the viewmanager.
void EstablishSecondConnection() {
- AllocationScope allocation_scope;
- InterfacePipe<IViewManager, AnyInterface> pipe;
- test_helper_.shell()->Connect("mojo:mojo_view_manager",
- pipe.handle_to_peer.Pass());
- view_manager2_.reset(pipe.handle_to_self.Pass(), &client2_);
+ ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager2_);
+ view_manager2_->SetClient(&client2_);
client2_.WaitForId();
}
@@ -284,10 +278,10 @@ class ViewManagerConnectionTest : public testing::Test {
shell::ShellTestHelper test_helper_;
ViewManagerClientImpl client_;
- RemotePtr<IViewManager> view_manager_;
+ IViewManagerPtr view_manager_;
ViewManagerClientImpl client2_;
- RemotePtr<IViewManager> view_manager2_;
+ IViewManagerPtr view_manager2_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest);
};
diff --git a/mojo/shell/app_child_process.cc b/mojo/shell/app_child_process.cc
index 7909d83..492a667 100644
--- a/mojo/shell/app_child_process.cc
+++ b/mojo/shell/app_child_process.cc
@@ -20,7 +20,6 @@
#include "base/threading/thread_checker.h"
#include "mojo/common/message_pump_mojo.h"
#include "mojo/embedder/embedder.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/shell/app_child_process.mojom.h"
@@ -82,6 +81,9 @@ class Blocker {
class AppChildControllerImpl;
+static void DestroyController(scoped_ptr<AppChildControllerImpl> controller) {
+}
+
// Should be created and initialized on the main thread.
class AppContext {
public:
@@ -111,6 +113,12 @@ class AppContext {
CHECK(controller_runner_);
}
+ void Shutdown() {
+ controller_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&DestroyController, base::Passed(&controller_)));
+ }
+
base::SingleThreadTaskRunner* io_runner() const {
return io_runner_.get();
}
@@ -145,10 +153,14 @@ class AppContext {
// AppChildControllerImpl ------------------------------------------------------
-class AppChildControllerImpl : public mojo_shell::AppChildController {
+class AppChildControllerImpl : public InterfaceImpl<AppChildController> {
public:
virtual ~AppChildControllerImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
+
+ // TODO(vtl): Pass in the result from |MainMain()|.
+ if (controller_client_)
+ controller_client_->AppCompleted(MOJO_RESULT_UNIMPLEMENTED);
}
// To be executed on the controller thread. Creates the |AppChildController|,
@@ -161,31 +173,39 @@ class AppChildControllerImpl : public mojo_shell::AppChildController {
DCHECK(platform_channel.is_valid());
DCHECK(!app_context->controller());
- app_context->set_controller(
- make_scoped_ptr(new AppChildControllerImpl(app_context, unblocker)));
- app_context->controller()->CreateChannel(platform_channel.Pass());
- }
- void Shutdown() {
- DVLOG(2) << "AppChildControllerImpl::Shutdown()";
- DCHECK(thread_checker_.CalledOnValidThread());
+ scoped_ptr<AppChildControllerImpl> impl(
+ new AppChildControllerImpl(app_context, unblocker));
- // TODO(vtl): Pass in the result from |MainMain()|.
- controller_client_->AppCompleted(MOJO_RESULT_UNIMPLEMENTED);
+ ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
+ platform_channel.Pass(),
+ app_context->io_runner(),
+ base::Bind(&AppChildControllerImpl::DidCreateChannel,
+ base::Unretained(impl.get())),
+ base::MessageLoopProxy::current()));
- // TODO(vtl): Drain then destroy the channel (on the I/O thread).
+ BindToPipe(impl.get(), host_message_pipe.Pass());
- // This will destroy this object.
- app_context_->set_controller(scoped_ptr<AppChildControllerImpl>());
+ app_context->set_controller(impl.Pass());
+ }
+
+ virtual void OnConnectionError() OVERRIDE {
+ // TODO(darin): How should we handle a connection error here?
+ }
+
+ // |AppChildController| methods:
+
+ virtual void SetClient(AppChildControllerClient* client) OVERRIDE {
+ controller_client_ = client;
}
- // |AppChildController| method:
virtual void StartApp(const String& app_path,
ScopedMessagePipeHandle service) OVERRIDE {
DVLOG(2) << "AppChildControllerImpl::StartApp("
<< app_path.To<std::string>() << ", ...)";
DCHECK(thread_checker_.CalledOnValidThread());
+ // TODO(darin): Add TypeConverter for FilePath <-> mojo::String.
unblocker_.Unblock(base::Bind(&AppChildControllerImpl::StartAppOnMainThread,
base::FilePath::FromUTF8Unsafe(
app_path.To<std::string>()),
@@ -197,25 +217,10 @@ class AppChildControllerImpl : public mojo_shell::AppChildController {
const Blocker::Unblocker& unblocker)
: app_context_(app_context),
unblocker_(unblocker),
+ controller_client_(NULL),
channel_info_(NULL) {
}
- void CreateChannel(embedder::ScopedPlatformHandle platform_channel) {
- DVLOG(2) << "AppChildControllerImpl::CreateChannel()";
- DCHECK(thread_checker_.CalledOnValidThread());
-
- ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
- platform_channel.Pass(),
- app_context_->io_runner(),
- base::Bind(&AppChildControllerImpl::DidCreateChannel,
- base::Unretained(this)),
- base::MessageLoopProxy::current()));
- controller_client_.reset(
- mojo_shell::ScopedAppChildControllerClientHandle(
- mojo_shell::AppChildControllerClientHandle(
- host_message_pipe.release().value())), this);
- }
-
// Callback for |embedder::CreateChannel()|.
void DidCreateChannel(embedder::ChannelInfo* channel_info) {
DVLOG(2) << "AppChildControllerImpl::DidCreateChannel()";
@@ -262,7 +267,7 @@ class AppChildControllerImpl : public mojo_shell::AppChildController {
AppContext* const app_context_;
Blocker::Unblocker unblocker_;
- RemotePtr<mojo_shell::AppChildControllerClient> controller_client_;
+ AppChildControllerClient* controller_client_;
embedder::ChannelInfo* channel_info_;
DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl);
@@ -292,10 +297,7 @@ void AppChildProcess::Main() {
// This will block, then run whatever the controller wants.
blocker.Block();
- app_context.controller_runner()->PostTask(
- FROM_HERE,
- base::Bind(&AppChildControllerImpl::Shutdown,
- base::Unretained(app_context.controller())));
+ app_context.Shutdown();
}
} // namespace shell
diff --git a/mojo/shell/app_child_process.mojom b/mojo/shell/app_child_process.mojom
index feb9ece..5b0f180 100644
--- a/mojo/shell/app_child_process.mojom
+++ b/mojo/shell/app_child_process.mojom
@@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TODO(vtl): mojom currently doesn't support nested modules. :(
-module mojo_shell {
+module mojo.shell {
-[Peer=AppChildControllerClient]
+[Client=AppChildControllerClient]
interface AppChildController {
// TODO(vtl): |service| should be of a more specific type.
StartApp(string app_path, handle<message_pipe> service);
};
-[Peer=AppChildController]
interface AppChildControllerClient {
AppCompleted(int32 result);
};
-} // module mojo_shell
+} // module mojo.shell
diff --git a/mojo/shell/app_child_process_host.cc b/mojo/shell/app_child_process_host.cc
index d35da8e..b514ce6 100644
--- a/mojo/shell/app_child_process_host.cc
+++ b/mojo/shell/app_child_process_host.cc
@@ -16,7 +16,7 @@ namespace shell {
AppChildProcessHost::AppChildProcessHost(
Context* context,
- mojo_shell::AppChildControllerClient* controller_client)
+ AppChildControllerClient* controller_client)
: ChildProcessHost(context, this, ChildProcess::TYPE_APP),
controller_client_(controller_client),
channel_info_(NULL) {
@@ -28,16 +28,15 @@ AppChildProcessHost::~AppChildProcessHost() {
void AppChildProcessHost::WillStart() {
DCHECK(platform_channel()->is_valid());
- mojo::ScopedMessagePipeHandle child_message_pipe(embedder::CreateChannel(
+ mojo::ScopedMessagePipeHandle handle(embedder::CreateChannel(
platform_channel()->Pass(),
context()->task_runners()->io_runner(),
base::Bind(&AppChildProcessHost::DidCreateChannel,
base::Unretained(this)),
base::MessageLoop::current()->message_loop_proxy()));
- controller_.reset(
- mojo_shell::ScopedAppChildControllerHandle(
- mojo_shell::AppChildControllerHandle(
- child_message_pipe.release().value())), controller_client_);
+
+ controller_.Bind(handle.Pass());
+ controller_->SetClient(controller_client_);
}
void AppChildProcessHost::DidStart(bool success) {
diff --git a/mojo/shell/app_child_process_host.h b/mojo/shell/app_child_process_host.h
index 04dc4c7..30e6b79 100644
--- a/mojo/shell/app_child_process_host.h
+++ b/mojo/shell/app_child_process_host.h
@@ -6,7 +6,6 @@
#define MOJO_SHELL_APP_CHILD_PROCESS_HOST_H_
#include "base/macros.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/shell/app_child_process.mojom.h"
#include "mojo/shell/child_process_host.h"
@@ -27,10 +26,10 @@ class AppChildProcessHost : public ChildProcessHost,
public ChildProcessHost::Delegate {
public:
AppChildProcessHost(Context* context,
- mojo_shell::AppChildControllerClient* controller_client);
+ AppChildControllerClient* controller_client);
virtual ~AppChildProcessHost();
- mojo_shell::AppChildController* controller() {
+ AppChildController* controller() {
return controller_.get();
}
@@ -42,9 +41,9 @@ class AppChildProcessHost : public ChildProcessHost,
// Callback for |embedder::CreateChannel()|.
void DidCreateChannel(embedder::ChannelInfo* channel_info);
- mojo_shell::AppChildControllerClient* const controller_client_;
+ AppChildControllerClient* const controller_client_;
- RemotePtr<mojo_shell::AppChildController> controller_;
+ AppChildControllerPtr controller_;
embedder::ChannelInfo* channel_info_;
DISALLOW_COPY_AND_ASSIGN(AppChildProcessHost);
diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc
index 9879a17..960fcfe 100644
--- a/mojo/shell/context.cc
+++ b/mojo/shell/context.cc
@@ -61,7 +61,7 @@ class Context::NativeViewportServiceLoader : public ServiceLoader {
private:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) OVERRIDE {
+ ScopedMessagePipeHandle service_handle) OVERRIDE {
app_.reset(::CreateNativeViewportService(context_, service_handle.Pass()));
}
diff --git a/mojo/shell/dbus_service_loader_linux.cc b/mojo/shell/dbus_service_loader_linux.cc
index 6485496..f2ecbcf 100644
--- a/mojo/shell/dbus_service_loader_linux.cc
+++ b/mojo/shell/dbus_service_loader_linux.cc
@@ -20,8 +20,6 @@
#include "mojo/dbus/dbus_external_service.h"
#include "mojo/embedder/platform_channel_pair.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/bindings/interface.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/shell/context.h"
#include "mojo/shell/external_service.mojom.h"
#include "mojo/shell/keep_alive.h"
@@ -30,7 +28,7 @@ namespace mojo {
namespace shell {
// Manages the connection to a single externally-running service.
-class DBusServiceLoader::LoadContext : public mojo::ExternalServiceHost {
+class DBusServiceLoader::LoadContext {
public:
// Kicks off the attempt to bootstrap a connection to the externally-running
// service specified by url_.
@@ -39,7 +37,7 @@ class DBusServiceLoader::LoadContext : public mojo::ExternalServiceHost {
LoadContext(DBusServiceLoader* loader,
const scoped_refptr<dbus::Bus>& bus,
const GURL& url,
- ScopedShellHandle shell_handle)
+ ScopedMessagePipeHandle shell_handle)
: loader_(loader),
bus_(bus),
service_dbus_proxy_(NULL),
@@ -73,9 +71,7 @@ class DBusServiceLoader::LoadContext : public mojo::ExternalServiceHost {
loader_->context_->task_runners()->io_runner());
CHECK(bootstrap_message_pipe.is_valid());
- external_service_.reset(
- mojo::ScopedExternalServiceHandle::From(bootstrap_message_pipe.Pass()),
- this);
+ external_service_.Bind(bootstrap_message_pipe.Pass());
scoped_ptr<dbus::FileDescriptor> client_fd(new dbus::FileDescriptor);
client_fd->PutValue(channel_pair.PassClientHandle().release().fd);
@@ -136,10 +132,10 @@ class DBusServiceLoader::LoadContext : public mojo::ExternalServiceHost {
scoped_refptr<dbus::Bus> bus_;
dbus::ObjectProxy* service_dbus_proxy_; // Owned by bus_;
const GURL url_;
- ScopedShellHandle shell_handle_;
+ ScopedMessagePipeHandle shell_handle_;
KeepAlive keep_alive_;
scoped_ptr<common::ChannelInit> channel_init_;
- mojo::RemotePtr<mojo::ExternalService> external_service_;
+ ExternalServicePtr external_service_;
DISALLOW_COPY_AND_ASSIGN(LoadContext);
};
@@ -157,7 +153,7 @@ DBusServiceLoader::~DBusServiceLoader() {
void DBusServiceLoader::LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) {
+ ScopedMessagePipeHandle service_handle) {
DCHECK(url.SchemeIs("dbus"));
DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end());
url_to_load_context_[url] =
diff --git a/mojo/shell/dbus_service_loader_linux.h b/mojo/shell/dbus_service_loader_linux.h
index 8cb3f53..c23dcde 100644
--- a/mojo/shell/dbus_service_loader_linux.h
+++ b/mojo/shell/dbus_service_loader_linux.h
@@ -64,7 +64,7 @@ class DBusServiceLoader : public ServiceLoader {
// "/org/chromium/MojoImpl".
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) OVERRIDE;
+ ScopedMessagePipeHandle service_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager, const GURL& url)
OVERRIDE;
diff --git a/mojo/shell/dynamic_service_loader.cc b/mojo/shell/dynamic_service_loader.cc
index da87453..01b572b 100644
--- a/mojo/shell/dynamic_service_loader.cc
+++ b/mojo/shell/dynamic_service_loader.cc
@@ -34,7 +34,7 @@ class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate {
public:
LoadContext(DynamicServiceLoader* loader,
const GURL& url,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
scoped_ptr<DynamicServiceRunner> runner)
: loader_(loader),
url_(url),
@@ -79,7 +79,7 @@ class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate {
DynamicServiceLoader* const loader_;
const GURL url_;
scoped_ptr<mojo::shell::Loader::Job> request_;
- ScopedShellHandle service_handle_;
+ ScopedMessagePipeHandle service_handle_;
scoped_ptr<DynamicServiceRunner> runner_;
KeepAlive keep_alive_;
@@ -99,7 +99,7 @@ DynamicServiceLoader::~DynamicServiceLoader() {
void DynamicServiceLoader::LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) {
+ ScopedMessagePipeHandle service_handle) {
DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end());
url_to_load_context_[url] = new LoadContext(
this, url, service_handle.Pass(), runner_factory_->Create(context_));
diff --git a/mojo/shell/dynamic_service_loader.h b/mojo/shell/dynamic_service_loader.h
index 456295b..f2e480f 100644
--- a/mojo/shell/dynamic_service_loader.h
+++ b/mojo/shell/dynamic_service_loader.h
@@ -36,7 +36,7 @@ class DynamicServiceLoader : public ServiceLoader {
// host/port.
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle service_handle) OVERRIDE;
+ ScopedMessagePipeHandle service_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager, const GURL& url)
OVERRIDE;
diff --git a/mojo/shell/dynamic_service_runner.h b/mojo/shell/dynamic_service_runner.h
index b61f651..8234a67 100644
--- a/mojo/shell/dynamic_service_runner.h
+++ b/mojo/shell/dynamic_service_runner.h
@@ -29,7 +29,7 @@ class DynamicServiceRunner {
// runs it on some other thread/process. |app_completed_callback| is posted
// (to the thread on which |Start()| was called) after |MojoMain()| completes.
virtual void Start(const base::FilePath& app_path,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
const base::Closure& app_completed_callback) = 0;
};
diff --git a/mojo/shell/external_service.mojom b/mojo/shell/external_service.mojom
index f76f5fe..2b42365 100644
--- a/mojo/shell/external_service.mojom
+++ b/mojo/shell/external_service.mojom
@@ -4,13 +4,8 @@
module mojo {
-[Peer=ExternalServiceHost]
interface ExternalService {
Activate(handle<message_pipe> shell_handle);
};
-[Peer=ExternalService]
-interface ExternalServiceHost {
-};
-
}
diff --git a/mojo/shell/in_process_dynamic_service_runner.cc b/mojo/shell/in_process_dynamic_service_runner.cc
index 6604180..5b3c935 100644
--- a/mojo/shell/in_process_dynamic_service_runner.cc
+++ b/mojo/shell/in_process_dynamic_service_runner.cc
@@ -30,7 +30,7 @@ InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() {
void InProcessDynamicServiceRunner::Start(
const base::FilePath& app_path,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
const base::Closure& app_completed_callback) {
app_path_ = app_path;
diff --git a/mojo/shell/in_process_dynamic_service_runner.h b/mojo/shell/in_process_dynamic_service_runner.h
index 95cebb1..3a3faef 100644
--- a/mojo/shell/in_process_dynamic_service_runner.h
+++ b/mojo/shell/in_process_dynamic_service_runner.h
@@ -25,7 +25,7 @@ class InProcessDynamicServiceRunner
// |DynamicServiceRunner| method:
virtual void Start(const base::FilePath& app_path,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
const base::Closure& app_completed_callback) OVERRIDE;
private:
@@ -33,7 +33,7 @@ class InProcessDynamicServiceRunner
virtual void Run() OVERRIDE;
base::FilePath app_path_;
- ScopedShellHandle service_handle_;
+ ScopedMessagePipeHandle service_handle_;
base::Callback<bool(void)> app_completed_callback_runner_;
base::DelegateSimpleThread thread_;
diff --git a/mojo/shell/out_of_process_dynamic_service_runner.cc b/mojo/shell/out_of_process_dynamic_service_runner.cc
index a907c85..e75ba74 100644
--- a/mojo/shell/out_of_process_dynamic_service_runner.cc
+++ b/mojo/shell/out_of_process_dynamic_service_runner.cc
@@ -31,7 +31,7 @@ OutOfProcessDynamicServiceRunner::~OutOfProcessDynamicServiceRunner() {
void OutOfProcessDynamicServiceRunner::Start(
const base::FilePath& app_path,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
const base::Closure& app_completed_callback) {
app_path_ = app_path;
diff --git a/mojo/shell/out_of_process_dynamic_service_runner.h b/mojo/shell/out_of_process_dynamic_service_runner.h
index bee4e19..9b3c96d 100644
--- a/mojo/shell/out_of_process_dynamic_service_runner.h
+++ b/mojo/shell/out_of_process_dynamic_service_runner.h
@@ -19,24 +19,24 @@ namespace shell {
// (from the file system) in a separate process (of its own).
class OutOfProcessDynamicServiceRunner
: public DynamicServiceRunner,
- public mojo_shell::AppChildControllerClient {
+ public AppChildControllerClient {
public:
explicit OutOfProcessDynamicServiceRunner(Context* context);
virtual ~OutOfProcessDynamicServiceRunner();
// |DynamicServiceRunner| method:
virtual void Start(const base::FilePath& app_path,
- ScopedShellHandle service_handle,
+ ScopedMessagePipeHandle service_handle,
const base::Closure& app_completed_callback) OVERRIDE;
private:
- // |mojo_shell::AppChildControllerClient| method:
+ // |AppChildControllerClient| method:
virtual void AppCompleted(int32_t result) OVERRIDE;
Context* const context_;
base::FilePath app_path_;
- ScopedShellHandle service_handle_;
+ ScopedMessagePipeHandle service_handle_;
base::Closure app_completed_callback_;
scoped_ptr<AppChildProcessHost> app_child_process_host_;
diff --git a/mojo/shell/shell_test_helper.cc b/mojo/shell/shell_test_helper.cc
index e8f4bea..d1c77f9 100644
--- a/mojo/shell/shell_test_helper.cc
+++ b/mojo/shell/shell_test_helper.cc
@@ -19,7 +19,7 @@ namespace shell {
struct ShellTestHelper::State {
scoped_ptr<Context> context;
scoped_ptr<ServiceManager::TestAPI> test_api;
- ScopedShellHandle shell_handle;
+ ScopedMessagePipeHandle shell_handle;
};
namespace {
@@ -79,7 +79,8 @@ void ShellTestHelper::Init() {
void ShellTestHelper::OnShellStarted() {
DCHECK(state_);
shell_client_.reset(new TestShellClient);
- shell_.reset(state_->shell_handle.Pass(), shell_client_.get());
+ shell_.Bind(state_->shell_handle.Pass());
+ shell_->SetClient(shell_client_.get());
run_loop_->Quit();
}
diff --git a/mojo/shell/shell_test_helper.h b/mojo/shell/shell_test_helper.h
index 53d84a3..5d0df6e 100644
--- a/mojo/shell/shell_test_helper.h
+++ b/mojo/shell/shell_test_helper.h
@@ -9,7 +9,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
-#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
@@ -55,7 +54,7 @@ class ShellTestHelper {
// Client interface for the shell.
scoped_ptr<TestShellClient> shell_client_;
- RemotePtr<Shell> shell_;
+ ShellPtr shell_;
DISALLOW_COPY_AND_ASSIGN(ShellTestHelper);
};
diff --git a/mojo/shell/view_manager_loader.cc b/mojo/shell/view_manager_loader.cc
index a3d0cbd..05fea7a 100644
--- a/mojo/shell/view_manager_loader.cc
+++ b/mojo/shell/view_manager_loader.cc
@@ -19,7 +19,7 @@ ViewManagerLoader::~ViewManagerLoader() {
void ViewManagerLoader::LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle shell_handle) {
+ ScopedMessagePipeHandle shell_handle) {
scoped_ptr<Application> app(new Application(shell_handle.Pass()));
if (!root_node_manager_.get()) {
root_node_manager_.reset(
diff --git a/mojo/shell/view_manager_loader.h b/mojo/shell/view_manager_loader.h
index 021f2a4..7276835 100644
--- a/mojo/shell/view_manager_loader.h
+++ b/mojo/shell/view_manager_loader.h
@@ -30,7 +30,7 @@ class ViewManagerLoader : public ServiceLoader {
// ServiceLoader overrides:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedShellHandle shell_handle) OVERRIDE;
+ ScopedMessagePipeHandle shell_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE;