OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ | 5 #ifndef CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ |
6 #define CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ | 6 #define CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | |
12 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
13 #include "ipc/mojo/scoped_ipc_support.h" | 12 #include "ipc/mojo/scoped_ipc_support.h" |
14 #include "mojo/public/cpp/system/message_pipe.h" | 13 #include "mojo/public/cpp/system/message_pipe.h" |
15 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h" | |
16 | 14 |
17 namespace base { | 15 namespace base { |
18 class TaskRunner; | 16 class TaskRunner; |
19 } | 17 } |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 | 20 |
23 // ChannelInit handles creation and destruction of the Mojo channel. It is not | 21 // 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. | 22 // thread-safe, but may be used on any single thread with a MessageLoop. |
25 class CONTENT_EXPORT ChannelInit { | 23 class CONTENT_EXPORT ChannelInit { |
26 public: | 24 public: |
27 ChannelInit(); | 25 ChannelInit(); |
28 ~ChannelInit(); | 26 ~ChannelInit(); |
29 | 27 |
30 // Initializes the channel. This takes ownership of |file|. | 28 // Initializes the channel. This takes ownership of |file|. |
31 mojo::ScopedMessagePipeHandle Init( | 29 mojo::ScopedMessagePipeHandle Init( |
32 base::PlatformFile file, | 30 base::PlatformFile file, |
33 scoped_refptr<base::TaskRunner> io_thread_task_runner); | 31 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
34 | 32 |
35 // Notifies the channel that we (hence it) will soon be destroyed. | |
36 void WillDestroySoon(); | |
37 | |
38 private: | 33 private: |
39 // Invoked on the thread on which this object lives once the channel has been | |
40 // established. This is a static method that takes a weak pointer to self, | |
41 // since we want to destroy the channel if we were destroyed first. | |
42 static void OnCreatedChannel( | |
43 base::WeakPtr<ChannelInit> self, | |
44 scoped_ptr<IPC::ScopedIPCSupport> ipc_support, | |
45 mojo::embedder::ChannelInfo* channel); | |
46 | |
47 // If non-null the channel has been established. | |
48 mojo::embedder::ChannelInfo* channel_info_; | |
49 | |
50 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_; | 34 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_; |
51 base::WeakPtrFactory<ChannelInit> weak_factory_; | |
52 | 35 |
53 DISALLOW_COPY_AND_ASSIGN(ChannelInit); | 36 DISALLOW_COPY_AND_ASSIGN(ChannelInit); |
54 }; | 37 }; |
55 | 38 |
56 } // namespace content | 39 } // namespace content |
57 | 40 |
58 #endif // CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ | 41 #endif // CONTENT_COMMON_MOJO_CHANNEL_INIT_H_ |
OLD | NEW |