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

Unified Diff: content/browser/mojo/mojo_application_host.cc

Issue 1891043002: Revert of Use a token to initialise ChannelMojo and MojoApplication everywhere. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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: content/browser/mojo/mojo_application_host.cc
diff --git a/content/browser/mojo/mojo_application_host.cc b/content/browser/mojo/mojo_application_host.cc
index 1e5f1f439187268754d3c73a499e84208df1dea4..6456a943a53e2847ee157ee554a788a0d459a54c 100644
--- a/content/browser/mojo/mojo_application_host.cc
+++ b/content/browser/mojo/mojo_application_host.cc
@@ -6,9 +6,12 @@
#include <utility>
-#include "base/logging.h"
#include "build/build_config.h"
+#include "content/common/mojo/mojo_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "ipc/ipc_sender.h"
#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
namespace content {
namespace {
@@ -38,22 +41,70 @@
} // namespace
-MojoApplicationHost::MojoApplicationHost()
- : token_(mojo::edk::GenerateRandomToken()) {
+MojoApplicationHost::MojoApplicationHost() : did_activate_(false) {
#if defined(OS_ANDROID)
service_registry_android_ =
ServiceRegistryAndroid::Create(&service_registry_);
#endif
-
- mojo::ScopedMessagePipeHandle pipe =
- mojo::edk::CreateParentMessagePipe(token_);
- DCHECK(pipe.is_valid());
- application_setup_.reset(new ApplicationSetupImpl(
- &service_registry_,
- mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe))));
}
MojoApplicationHost::~MojoApplicationHost() {
}
+bool MojoApplicationHost::Init() {
+ DCHECK(!client_handle_.is_valid()) << "Already initialized!";
+
+ mojo::edk::PlatformChannelPair channel_pair;
+
+ scoped_refptr<base::TaskRunner> io_task_runner;
+ if (io_task_runner_override_) {
+ io_task_runner = io_task_runner_override_;
+ } else {
+ io_task_runner =
+ BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
+ ->task_runner();
+ }
+
+ // Forward this to the client once we know its process handle.
+ client_handle_ = channel_pair.PassClientHandle();
+ mojo::ScopedMessagePipeHandle pipe = channel_init_.Init(
+ channel_pair.PassServerHandle().release().handle, io_task_runner);
+ application_setup_.reset(new ApplicationSetupImpl(
+ &service_registry_,
+ mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe))));
+ return true;
+}
+
+void MojoApplicationHost::Activate(IPC::Sender* sender,
+ base::ProcessHandle process_handle) {
+ DCHECK(!did_activate_);
+ DCHECK(client_handle_.is_valid());
+
+ base::PlatformFile client_file = client_handle_.release().handle;
+ did_activate_ = sender->Send(new MojoMsg_Activate(
+ IPC::GetPlatformFileForTransit(client_file, true)));
+}
+
+std::string MojoApplicationHost::InitWithToken() {
+ DCHECK(!client_handle_.is_valid()) << "Already initialized!";
+ DCHECK(!did_activate_);
+
+ std::string token = mojo::edk::GenerateRandomToken();
+ mojo::ScopedMessagePipeHandle pipe =
+ mojo::edk::CreateParentMessagePipe(token);
+ DCHECK(pipe.is_valid());
+ application_setup_.reset(new ApplicationSetupImpl(
+ &service_registry_,
+ mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe))));
+
+ did_activate_ = true;
+ return token;
+}
+
+void MojoApplicationHost::OverrideIOTaskRunnerForTest(
+ scoped_refptr<base::TaskRunner> io_task_runner) {
+ io_task_runner_override_ = io_task_runner;
+}
+
+
} // namespace content
« no previous file with comments | « content/browser/mojo/mojo_application_host.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698