OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_MESSAGE_PORT_H_ | 5 #ifndef CONTENT_COMMON_MESSAGE_PORT_H_ |
6 #define CONTENT_COMMON_MESSAGE_PORT_H_ | 6 #define CONTENT_COMMON_MESSAGE_PORT_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "mojo/public/cpp/system/message_pipe.h" | 15 #include "mojo/public/cpp/system/message_pipe.h" |
| 16 #include "mojo/public/cpp/system/watcher.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // MessagePort corresponds to a HTML MessagePort. It is a thin wrapper around a | 20 // MessagePort corresponds to a HTML MessagePort. It is a thin wrapper around a |
20 // Mojo MessagePipeHandle and provides methods for reading and writing messages. | 21 // Mojo MessagePipeHandle and provides methods for reading and writing messages. |
21 // | 22 // |
22 // A MessagePort is only actively listening for incoming messages once | 23 // A MessagePort is only actively listening for incoming messages once |
23 // SetCallback has been called with a valid callback. If ClearCallback is | 24 // SetCallback has been called with a valid callback. If ClearCallback is |
24 // called (or if SetCallback is called with a null callback), then the | 25 // called (or if SetCallback is called with a null callback), then the |
25 // MessagePort will stop listening for incoming messages. The callback runs on | 26 // MessagePort will stop listening for incoming messages. The callback runs on |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void ClearCallback(); | 76 void ClearCallback(); |
76 | 77 |
77 private: | 78 private: |
78 class State : public base::RefCountedThreadSafe<State> { | 79 class State : public base::RefCountedThreadSafe<State> { |
79 public: | 80 public: |
80 State(); | 81 State(); |
81 State(mojo::ScopedMessagePipeHandle handle); | 82 State(mojo::ScopedMessagePipeHandle handle); |
82 | 83 |
83 void AddWatch(); | 84 void AddWatch(); |
84 void CancelWatch(); | 85 void CancelWatch(); |
85 static void OnHandleReady(uintptr_t context, | |
86 MojoResult result, | |
87 MojoHandleSignalsState signals_state, | |
88 MojoWatchNotificationFlags flags); | |
89 | 86 |
| 87 mojo::ScopedWatcherHandle watcher_handle_; |
90 mojo::ScopedMessagePipeHandle handle_; | 88 mojo::ScopedMessagePipeHandle handle_; |
91 base::Closure callback_; | 89 base::Closure callback_; |
92 | 90 |
93 private: | 91 private: |
94 friend class base::RefCountedThreadSafe<State>; | 92 friend class base::RefCountedThreadSafe<State>; |
| 93 |
95 ~State(); | 94 ~State(); |
| 95 |
| 96 void ArmWatcher(); |
| 97 void OnHandleReady(MojoResult result); |
| 98 |
| 99 static void CallOnHandleReady(uintptr_t context, |
| 100 MojoResult result, |
| 101 MojoHandleSignalsState signals_state, |
| 102 MojoWatcherNotificationFlags flags); |
| 103 |
| 104 uintptr_t context_; |
96 }; | 105 }; |
97 mutable scoped_refptr<State> state_; | 106 mutable scoped_refptr<State> state_; |
98 }; | 107 }; |
99 | 108 |
100 } // namespace content | 109 } // namespace content |
101 | 110 |
102 #endif // CONTENT_COMMON_MESSAGE_PORT_H_ | 111 #endif // CONTENT_COMMON_MESSAGE_PORT_H_ |
OLD | NEW |