| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ |
| 6 #define MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | 6 #define MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace embedder { | 21 namespace embedder { |
| 22 | 22 |
| 23 // |ChannelInit| handles creation (and destruction) of the Mojo channel. It is | 23 // |ChannelInit| handles creation (and destruction) of the Mojo channel. It is |
| 24 // not thread-safe, but may be used on any single thread (with a |MessageLoop|). | 24 // not thread-safe, but may be used on any single thread (with a |MessageLoop|). |
| 25 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit { | 25 class MOJO_SYSTEM_IMPL_EXPORT ChannelInit { |
| 26 public: | 26 public: |
| 27 ChannelInit(); | 27 ChannelInit(); |
| 28 ~ChannelInit(); | 28 ~ChannelInit(); |
| 29 | 29 |
| 30 // Initializes the channel. This takes ownership of |file|. Returns the | 30 // Initializes the channel. This takes ownership of |file|. Returns the |
| 31 // primordial |MessagePipe| for the channel. | 31 // primordial MessagePipe for the channel. |
| 32 mojo::ScopedMessagePipeHandle Init( | 32 mojo::ScopedMessagePipeHandle Init( |
| 33 base::PlatformFile file, | 33 base::PlatformFile file, |
| 34 scoped_refptr<base::TaskRunner> io_thread_task_runner); | 34 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| 35 | 35 |
| 36 // Notifies the channel that we (hence it) will soon be destroyed. | 36 // Notifies the channel that we (hence it) will soon be destroyed. |
| 37 void WillDestroySoon(); | 37 void WillDestroySoon(); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // Invoked on the thread on which this object lives once the channel has been | 40 // Invoked on the thread on which this object lives once the channel has been |
| 41 // established. (This is a static method that takes a weak pointer to self, | 41 // established. (This is a static method that takes a weak pointer to self, |
| 42 // since we want to destroy the channel even if we're destroyed.) | 42 // since we want to destroy the channel even if we're destroyed.) |
| 43 static void OnCreatedChannel(base::WeakPtr<ChannelInit> self, | 43 static void OnCreatedChannel(base::WeakPtr<ChannelInit> self, |
| 44 scoped_refptr<base::TaskRunner> io_thread, |
| 44 ChannelInfo* channel); | 45 ChannelInfo* channel); |
| 45 | 46 |
| 47 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
| 48 |
| 46 // If non-null the channel has been established. | 49 // If non-null the channel has been established. |
| 47 ChannelInfo* channel_info_; | 50 ChannelInfo* channel_info_; |
| 48 | 51 |
| 49 base::WeakPtrFactory<ChannelInit> weak_factory_; | 52 base::WeakPtrFactory<ChannelInit> weak_factory_; |
| 50 | 53 |
| 51 DISALLOW_COPY_AND_ASSIGN(ChannelInit); | 54 DISALLOW_COPY_AND_ASSIGN(ChannelInit); |
| 52 }; | 55 }; |
| 53 | 56 |
| 54 } // namespace embedder | 57 } // namespace embedder |
| 55 } // namespace mojo | 58 } // namespace mojo |
| 56 | 59 |
| 57 #endif // MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ | 60 #endif // MOJO_EDK_EMBEDDER_CHANNEL_INIT_H_ |
| OLD | NEW |