OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ | 5 #ifndef CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
6 #define CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ | 6 #define CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 // MojoChannelInit handle creation (and destruction) of the mojo channel. It is | 27 // MojoChannelInit handle creation (and destruction) of the mojo channel. It is |
28 // expected that this class is created and destroyed on the main thread. | 28 // expected that this class is created and destroyed on the main thread. |
29 class CONTENT_EXPORT MojoChannelInit { | 29 class CONTENT_EXPORT MojoChannelInit { |
30 public: | 30 public: |
31 MojoChannelInit(); | 31 MojoChannelInit(); |
32 ~MojoChannelInit(); | 32 ~MojoChannelInit(); |
33 | 33 |
| 34 // Initializes mojo. This is done implicitly when creating a MojoChannelInit, |
| 35 // but can be done explicitly as necessary. |
| 36 static void InitMojo(); |
| 37 |
34 // Inits the channel. This takes ownership of |file|. | 38 // Inits the channel. This takes ownership of |file|. |
35 void Init(base::PlatformFile file, | 39 void Init(base::PlatformFile file, |
36 scoped_refptr<base::TaskRunner> io_thread_task_runner); | 40 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
37 | 41 |
38 bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } | 42 bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } |
39 | 43 |
| 44 mojo::ScopedMessagePipeHandle bootstrap_message_pipe() { |
| 45 return bootstrap_message_pipe_.Pass(); |
| 46 } |
| 47 |
40 private: | 48 private: |
41 // Invoked on the main thread once the channel has been established. | 49 // Invoked on the main thread once the channel has been established. |
42 static void OnCreatedChannel( | 50 static void OnCreatedChannel( |
43 base::WeakPtr<MojoChannelInit> host, | 51 base::WeakPtr<MojoChannelInit> host, |
44 scoped_refptr<base::TaskRunner> io_thread, | 52 scoped_refptr<base::TaskRunner> io_thread, |
45 mojo::embedder::ChannelInfo* channel); | 53 mojo::embedder::ChannelInfo* channel); |
46 | 54 |
47 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | 55 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
48 | 56 |
49 // If non-null the channel has been established. | 57 // If non-null the channel has been established. |
50 mojo::embedder::ChannelInfo* channel_info_; | 58 mojo::embedder::ChannelInfo* channel_info_; |
51 | 59 |
52 // The handle from channel creation. | 60 // The handle from channel creation. |
53 mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; | 61 mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; |
54 | 62 |
55 base::WeakPtrFactory<MojoChannelInit> weak_factory_; | 63 base::WeakPtrFactory<MojoChannelInit> weak_factory_; |
56 | 64 |
57 DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); | 65 DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); |
58 }; | 66 }; |
59 | 67 |
60 } // namespace content | 68 } // namespace content |
61 | 69 |
62 #endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ | 70 #endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
OLD | NEW |