OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | |
6 #define MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | |
7 | |
8 #include "base/files/file.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "mojo/edk/embedder/channel_info_forward.h" | |
12 #include "mojo/edk/system/system_impl_export.h" | |
13 #include "mojo/public/cpp/system/message_pipe.h" | |
14 | |
15 namespace base { | |
16 class MessageLoopProxy; | |
17 class TaskRunner; | |
18 } | |
19 | |
20 namespace mojo { | |
21 namespace embedder { | |
22 | |
23 // |ChannelInit| handles creation (and destruction) of the Mojo channel. It is | |
24 // not thread-safe, but may be used on any single thread (with a |MessageLoop|). | |
25 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit { | |
26 public: | |
27 ChannelInit(); | |
28 ~ChannelInit(); | |
29 | |
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); | |
35 | |
36 // Notifies the channel that we (hence it) will soon be destroyed. | |
37 void WillDestroySoon(); | |
38 | |
39 private: | |
40 // Invoked on the thread on which this object lives once the channel has been | |
41 // established. (This is a static method that takes a weak pointer to self, | |
42 // since we want to destroy the channel even if we're destroyed.) | |
43 static void OnCreatedChannel(base::WeakPtr<ChannelInit> self, | |
44 scoped_refptr<base::TaskRunner> io_thread, | |
45 ChannelInfo* channel); | |
46 | |
47 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | |
48 | |
49 // If non-null the channel has been established. | |
50 ChannelInfo* channel_info_; | |
51 | |
52 base::WeakPtrFactory<ChannelInit> weak_factory_; | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(ChannelInit); | |
55 }; | |
56 | |
57 } // namespace embedder | |
58 } // namespace mojo | |
59 | |
60 #endif // MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | |
OLD | NEW |