| 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 | |
| 38 // Inits the channel. This takes ownership of |file|. | 34 // Inits the channel. This takes ownership of |file|. |
| 39 void Init(base::PlatformFile file, | 35 void Init(base::PlatformFile file, |
| 40 scoped_refptr<base::TaskRunner> io_thread_task_runner); | 36 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| 41 | 37 |
| 42 bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } | 38 bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } |
| 43 | 39 |
| 44 mojo::ScopedMessagePipeHandle bootstrap_message_pipe() { | |
| 45 return bootstrap_message_pipe_.Pass(); | |
| 46 } | |
| 47 | |
| 48 private: | 40 private: |
| 49 // Invoked on the main thread once the channel has been established. | 41 // Invoked on the main thread once the channel has been established. |
| 50 static void OnCreatedChannel( | 42 static void OnCreatedChannel( |
| 51 base::WeakPtr<MojoChannelInit> host, | 43 base::WeakPtr<MojoChannelInit> host, |
| 52 scoped_refptr<base::TaskRunner> io_thread, | 44 scoped_refptr<base::TaskRunner> io_thread, |
| 53 mojo::embedder::ChannelInfo* channel); | 45 mojo::embedder::ChannelInfo* channel); |
| 54 | 46 |
| 55 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | 47 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
| 56 | 48 |
| 57 // If non-null the channel has been established. | 49 // If non-null the channel has been established. |
| 58 mojo::embedder::ChannelInfo* channel_info_; | 50 mojo::embedder::ChannelInfo* channel_info_; |
| 59 | 51 |
| 60 // The handle from channel creation. | 52 // The handle from channel creation. |
| 61 mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; | 53 mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; |
| 62 | 54 |
| 63 base::WeakPtrFactory<MojoChannelInit> weak_factory_; | 55 base::WeakPtrFactory<MojoChannelInit> weak_factory_; |
| 64 | 56 |
| 65 DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); | 57 DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); |
| 66 }; | 58 }; |
| 67 | 59 |
| 68 } // namespace content | 60 } // namespace content |
| 69 | 61 |
| 70 #endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ | 62 #endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
| OLD | NEW |