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" | |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 // MessagePort corresponds to a HTML MessagePort. It is a thin wrapper around a | 19 // MessagePort corresponds to a HTML MessagePort. It is a thin wrapper around a |
21 // Mojo MessagePipeHandle and provides methods for reading and writing messages. | 20 // Mojo MessagePipeHandle and provides methods for reading and writing messages. |
22 // | 21 // |
23 // A MessagePort is only actively listening for incoming messages once | 22 // A MessagePort is only actively listening for incoming messages once |
24 // SetCallback has been called with a valid callback. If ClearCallback is | 23 // SetCallback has been called with a valid callback. If ClearCallback is |
25 // called (or if SetCallback is called with a null callback), then the | 24 // called (or if SetCallback is called with a null callback), then the |
26 // MessagePort will stop listening for incoming messages. The callback runs on | 25 // MessagePort will stop listening for incoming messages. The callback runs on |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void ClearCallback(); | 75 void ClearCallback(); |
77 | 76 |
78 private: | 77 private: |
79 class State : public base::RefCountedThreadSafe<State> { | 78 class State : public base::RefCountedThreadSafe<State> { |
80 public: | 79 public: |
81 State(); | 80 State(); |
82 State(mojo::ScopedMessagePipeHandle handle); | 81 State(mojo::ScopedMessagePipeHandle handle); |
83 | 82 |
84 void AddWatch(); | 83 void AddWatch(); |
85 void CancelWatch(); | 84 void CancelWatch(); |
| 85 static void OnHandleReady(uintptr_t context, |
| 86 MojoResult result, |
| 87 MojoHandleSignalsState signals_state, |
| 88 MojoWatchNotificationFlags flags); |
86 | 89 |
87 mojo::ScopedWatcherHandle watcher_handle_; | |
88 mojo::ScopedMessagePipeHandle handle_; | 90 mojo::ScopedMessagePipeHandle handle_; |
89 base::Closure callback_; | 91 base::Closure callback_; |
90 | 92 |
91 private: | 93 private: |
92 friend class base::RefCountedThreadSafe<State>; | 94 friend class base::RefCountedThreadSafe<State>; |
93 | |
94 ~State(); | 95 ~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_; | |
105 }; | 96 }; |
106 mutable scoped_refptr<State> state_; | 97 mutable scoped_refptr<State> state_; |
107 }; | 98 }; |
108 | 99 |
109 } // namespace content | 100 } // namespace content |
110 | 101 |
111 #endif // CONTENT_COMMON_MESSAGE_PORT_H_ | 102 #endif // CONTENT_COMMON_MESSAGE_PORT_H_ |
OLD | NEW |