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

Unified Diff: mojo/shell/app_child_process.cc

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/shell/app_child_process.cc
diff --git a/mojo/shell/app_child_process.cc b/mojo/shell/app_child_process.cc
index 7909d83da23d502a4891c9662e6e58cb1ff64cfc..4c6ebee8ef59cec5634aa0cb7bd3da9016149003 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(AppChildControllerPtr 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();
}
@@ -119,11 +127,11 @@ class AppContext {
return controller_runner_.get();
}
- AppChildControllerImpl* controller() const {
+ AppChildController* controller() const {
return controller_.get();
}
- void set_controller(scoped_ptr<AppChildControllerImpl> controller) {
+ void set_controller(AppChildControllerPtr controller) {
controller_ = controller.Pass();
}
@@ -132,7 +140,7 @@ class AppContext {
// IMPORTANT: This must be BEFORE |controller_thread_|, so that the controller
// thread gets joined (and thus |controller_| reset) before |controller_| is
// destroyed.
- scoped_ptr<AppChildControllerImpl> controller_;
+ AppChildControllerPtr controller_;
base::Thread io_thread_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
@@ -145,10 +153,14 @@ class AppContext {
// AppChildControllerImpl ------------------------------------------------------
-class AppChildControllerImpl : public mojo_shell::AppChildController {
+class AppChildControllerImpl : public 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,36 @@ 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());
+ 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)),
+ base::MessageLoopProxy::current()));
+
+ AppChildControllerPtr controller(impl);
+ controller.ConfigureStub(host_message_pipe.Pass());
+
+ app_context->set_controller(controller.Pass());
+ }
- // TODO(vtl): Drain then destroy the channel (on the I/O thread).
+ // |AppChildController| methods:
- // This will destroy this object.
- app_context_->set_controller(scoped_ptr<AppChildControllerImpl>());
+ virtual void SetClient(AppChildControllerClient* client) {
+ 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 +214,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 +264,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 +294,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

Powered by Google App Engine
This is Rietveld 408576698