diff options
author | jamesr <jamesr@chromium.org> | 2014-10-02 21:26:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-03 04:27:07 +0000 |
commit | a03ae49d253d7d1f517e2f92146a6ba201c78aa6 (patch) | |
tree | df4eae1239d49490fa4e85d184b9000224a7a31c /mojo/edk/embedder/channel_init.cc | |
parent | 24b9789375c3c23d0d10e5197c6a7674946ea44b (diff) | |
download | chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.zip chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.tar.gz chromium_src-a03ae49d253d7d1f517e2f92146a6ba201c78aa6.tar.bz2 |
Move mojo edk into mojo/edk
This creates a mojo/edk directory which contains the "embedder developer
kit" aka the set of code needed to embed mojo code.
mojo/edk/embedder = code from mojo/embedder
mojo/edk/system = code from mojo/system
mojo/edk/test = code used to test the previous two, from mojo/common/test
mojo/edk/ can only depend on mojo/public/, base/ and itself.
R=viettrungluu@chromium.org
TBR=sky@chromium.org for file renames
Committed: https://chromium.googlesource.com/chromium/src/+/ee7ff197a98da4636f33bd713de784948b487bd4
Review URL: https://codereview.chromium.org/621153003
Cr-Commit-Position: refs/heads/master@{#297986}
Diffstat (limited to 'mojo/edk/embedder/channel_init.cc')
-rw-r--r-- | mojo/edk/embedder/channel_init.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/mojo/edk/embedder/channel_init.cc b/mojo/edk/embedder/channel_init.cc new file mode 100644 index 0000000..9ea984b --- /dev/null +++ b/mojo/edk/embedder/channel_init.cc @@ -0,0 +1,56 @@ +// 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. + +#include "mojo/edk/embedder/channel_init.h" + +#include "base/bind.h" +#include "base/message_loop/message_loop.h" +#include "mojo/edk/embedder/embedder.h" + +namespace mojo { +namespace embedder { + +ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) { +} + +ChannelInit::~ChannelInit() { + if (channel_info_) + DestroyChannel(channel_info_); +} + +ScopedMessagePipeHandle ChannelInit::Init( + base::PlatformFile file, + scoped_refptr<base::TaskRunner> io_thread_task_runner) { + DCHECK(!io_thread_task_runner_.get()); // Should only init once. + io_thread_task_runner_ = io_thread_task_runner; + ScopedMessagePipeHandle message_pipe = + CreateChannel(ScopedPlatformHandle(PlatformHandle(file)), + io_thread_task_runner, + base::Bind(&ChannelInit::OnCreatedChannel, + weak_factory_.GetWeakPtr(), + io_thread_task_runner), + base::MessageLoop::current()->message_loop_proxy()).Pass(); + return message_pipe.Pass(); +} + +void ChannelInit::WillDestroySoon() { + if (channel_info_) + WillDestroyChannelSoon(channel_info_); +} + +// static +void ChannelInit::OnCreatedChannel(base::WeakPtr<ChannelInit> self, + scoped_refptr<base::TaskRunner> io_thread, + ChannelInfo* channel) { + // If |self| was already destroyed, shut the channel down. + if (!self) { + DestroyChannel(channel); + return; + } + + self->channel_info_ = channel; +} + +} // namespace embedder +} // namespace mojo |