diff options
author | James Robinson <jamesr@chromium.org> | 2014-10-02 17:19:39 -0700 |
---|---|---|
committer | James Robinson <jamesr@chromium.org> | 2014-10-03 00:20:26 +0000 |
commit | ee7ff197a98da4636f33bd713de784948b487bd4 (patch) | |
tree | bde85518c9be483f1e0a32c98a6dbb5e9b93e62e /mojo/edk/embedder/channel_init.cc | |
parent | 20894f54fc1460d9f13210b427a077267ebe86ee (diff) | |
download | chromium_src-ee7ff197a98da4636f33bd713de784948b487bd4.zip chromium_src-ee7ff197a98da4636f33bd713de784948b487bd4.tar.gz chromium_src-ee7ff197a98da4636f33bd713de784948b487bd4.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
Review URL: https://codereview.chromium.org/621153003
Cr-Commit-Position: refs/heads/master@{#297958}
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 |