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