Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / embedder / channel_init.h
blob26a645288f977bb5f94c66152fda626b7ef75015
1 // Copyright 2014 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 MOJO_EMBEDDER_CHANNEL_INIT_H_
6 #define MOJO_EMBEDDER_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 "mojo/public/cpp/system/core.h"
12 #include "mojo/system/system_impl_export.h"
14 namespace base {
15 class MessageLoopProxy;
16 class TaskRunner;
19 namespace mojo {
20 namespace embedder {
21 struct ChannelInfo;
24 namespace embedder {
26 // |ChannelInit| handles creation (and destruction) of the Mojo channel. It is
27 // not thread-safe, but may be used on any single thread (with a |MessageLoop|).
28 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit {
29 public:
30 ChannelInit();
31 ~ChannelInit();
33 // Initializes the channel. This takes ownership of |file|. Returns the
34 // primordial MessagePipe for the channel.
35 mojo::ScopedMessagePipeHandle Init(
36 base::PlatformFile file,
37 scoped_refptr<base::TaskRunner> io_thread_task_runner);
39 // Notifies the channel that we (hence it) will soon be destroyed.
40 void WillDestroySoon();
42 private:
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 even if we're destroyed.)
46 static void OnCreatedChannel(base::WeakPtr<ChannelInit> self,
47 scoped_refptr<base::TaskRunner> io_thread,
48 ChannelInfo* channel);
50 scoped_refptr<base::TaskRunner> io_thread_task_runner_;
52 // If non-null the channel has been established.
53 ChannelInfo* channel_info_;
55 base::WeakPtrFactory<ChannelInit> weak_factory_;
57 DISALLOW_COPY_AND_ASSIGN(ChannelInit);
60 } // namespace embedder
61 } // namespace mojo
63 #endif // MOJO_EMBEDDER_CHANNEL_INIT_H_