OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
| 6 #define CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/platform_file.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "mojo/public/system/core_cpp.h" |
| 13 |
| 14 namespace base { |
| 15 class MessageLoopProxy; |
| 16 class TaskRunner; |
| 17 } |
| 18 |
| 19 namespace mojo { |
| 20 namespace embedder { |
| 21 struct ChannelInfo; |
| 22 } |
| 23 } |
| 24 |
| 25 namespace content { |
| 26 |
| 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. |
| 29 class CONTENT_EXPORT MojoChannelInit { |
| 30 public: |
| 31 MojoChannelInit(); |
| 32 ~MojoChannelInit(); |
| 33 |
| 34 // Inits the channel. This takes ownership of |file|. |
| 35 void Init(base::PlatformFile file, |
| 36 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| 37 |
| 38 bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } |
| 39 |
| 40 private: |
| 41 // Invoked on the IO thread once the channel has been established. |
| 42 static void OnCreatedChannelOnIOThread( |
| 43 base::WeakPtr<MojoChannelInit> host, |
| 44 scoped_refptr<base::TaskRunner> main_thread, |
| 45 scoped_refptr<base::TaskRunner> io_thread, |
| 46 mojo::embedder::ChannelInfo* channel); |
| 47 |
| 48 // Invoked on the main thread once the channel has been established. |
| 49 static void OnCreatedChannelOnMainThread( |
| 50 base::WeakPtr<MojoChannelInit> host, |
| 51 scoped_refptr<base::TaskRunner> io_thread, |
| 52 mojo::embedder::ChannelInfo* channel); |
| 53 |
| 54 // Thread where this object lives. |
| 55 scoped_refptr<base::TaskRunner> main_thread_; |
| 56 |
| 57 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
| 58 |
| 59 // If non-null the channel has been established. |
| 60 mojo::embedder::ChannelInfo* channel_info_; |
| 61 |
| 62 // The handle from channel creation. |
| 63 mojo::ScopedHandle bootstrap_message_pipe_; |
| 64 |
| 65 base::WeakPtrFactory<MojoChannelInit> weak_factory_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ |
OLD | NEW |