1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
6 #define CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
8 #include "base/files/file.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/common/content_export.h"
12 #include "ipc/mojo/scoped_ipc_support.h"
13 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h"
14 #include "third_party/mojo/src/mojo/public/cpp/system/message_pipe.h"
17 class MessageLoopProxy
;
23 // ChannelInit handles creation and destruction of the Mojo channel. It is not
24 // thread-safe, but may be used on any single thread with a MessageLoop.
25 class CONTENT_EXPORT ChannelInit
{
30 // Initializes the channel. This takes ownership of |file|. Returns the
31 // primordial MessagePipe for the channel.
32 mojo::ScopedMessagePipeHandle
Init(
33 base::PlatformFile file
,
34 scoped_refptr
<base::TaskRunner
> io_thread_task_runner
);
36 // Notifies the channel that we (hence it) will soon be destroyed.
37 void WillDestroySoon();
39 // Shuts down the channel. Must be called from the IO thread.
40 void ShutdownOnIOThread();
43 // Invoked on the thread on which this object lives once the channel has been
44 // established. This is a static method that takes a weak pointer to self,
45 // since we want to destroy the channel if we were destroyed first.
46 static void OnCreatedChannel(
47 base::WeakPtr
<ChannelInit
> self
,
48 scoped_ptr
<IPC::ScopedIPCSupport
> ipc_support
,
49 mojo::embedder::ChannelInfo
* channel
);
51 // If non-null the channel has been established.
52 mojo::embedder::ChannelInfo
* channel_info_
;
54 scoped_ptr
<IPC::ScopedIPCSupport
> ipc_support_
;
55 base::WeakPtrFactory
<ChannelInit
> weak_factory_
;
57 DISALLOW_COPY_AND_ASSIGN(ChannelInit
);
60 } // namespace content
62 #endif // CONTENT_COMMON_MOJO_CHANNEL_INIT_H_