OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_EMBEDDER_CHANNEL_INIT_H_ | 5 #ifndef MOJO_EMBEDDER_CHANNEL_INIT_H_ |
6 #define MOJO_EMBEDDER_CHANNEL_INIT_H_ | 6 #define MOJO_EMBEDDER_CHANNEL_INIT_H_ |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
12 #include "mojo/system/system_impl_export.h" | 12 #include "mojo/system/system_impl_export.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class MessageLoopProxy; | 15 class MessageLoopProxy; |
16 class TaskRunner; | 16 class TaskRunner; |
17 } | 17 } |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace embedder { | 20 namespace embedder { |
21 struct ChannelInfo; | 21 struct ChannelInfo; |
22 } | 22 } |
23 | 23 |
24 namespace embedder { | 24 namespace embedder { |
25 | 25 |
26 // ChannelInit handle creation (and destruction) of the mojo channel. It is | 26 // |ChannelInit| handles creation (and destruction) of the Mojo channel. It is |
27 // expected that this class is created and destroyed on the main thread. | 27 // not thread-safe, but may be used on any single thread (with a |MessageLoop|). |
28 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit { | 28 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit { |
29 public: | 29 public: |
30 ChannelInit(); | 30 ChannelInit(); |
31 ~ChannelInit(); | 31 ~ChannelInit(); |
32 | 32 |
33 // Initializes the channel. This takes ownership of |file|. Returns the | 33 // Initializes the channel. This takes ownership of |file|. Returns the |
34 // primordial MessagePipe for the channel. | 34 // primordial MessagePipe for the channel. |
35 mojo::ScopedMessagePipeHandle Init( | 35 mojo::ScopedMessagePipeHandle Init( |
36 base::PlatformFile file, | 36 base::PlatformFile file, |
37 scoped_refptr<base::TaskRunner> io_thread_task_runner); | 37 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
38 | 38 |
39 // Notifies the channel that we (hence it) will soon be destroyed. | |
40 void WillDestroySoon(); | |
41 | |
39 private: | 42 private: |
40 // Invoked on the main thread once the channel has been established. | 43 // Invoked on the main thread once the channel has been established. (This is |
yzshen1
2014/08/13 19:44:10
nit: maybe it is good to clarify what main thread
| |
41 static void OnCreatedChannel(base::WeakPtr<ChannelInit> host, | 44 // a static method that takes a weak pointer to self, since we want to destroy |
45 // the channel even if we're destroyed.) | |
46 static void OnCreatedChannel(base::WeakPtr<ChannelInit> self, | |
42 scoped_refptr<base::TaskRunner> io_thread, | 47 scoped_refptr<base::TaskRunner> io_thread, |
43 embedder::ChannelInfo* channel); | 48 embedder::ChannelInfo* channel); |
44 | 49 |
45 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | 50 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
46 | 51 |
47 // If non-null the channel has been established. | 52 // If non-null the channel has been established. |
48 embedder::ChannelInfo* channel_info_; | 53 embedder::ChannelInfo* channel_info_; |
49 | 54 |
50 base::WeakPtrFactory<ChannelInit> weak_factory_; | 55 base::WeakPtrFactory<ChannelInit> weak_factory_; |
51 | 56 |
52 DISALLOW_COPY_AND_ASSIGN(ChannelInit); | 57 DISALLOW_COPY_AND_ASSIGN(ChannelInit); |
53 }; | 58 }; |
54 | 59 |
55 } // namespace embedder | 60 } // namespace embedder |
56 } // namespace mojo | 61 } // namespace mojo |
57 | 62 |
58 #endif // MOJO_EMBEDDER_CHANNEL_INIT_H_ | 63 #endif // MOJO_EMBEDDER_CHANNEL_INIT_H_ |
OLD | NEW |