OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
kinuko
2017/01/24 12:32:55
nit: 2017 (for all new files) =)
darin (slow to review)
2017/01/26 22:20:03
Thanks
| |
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_MESSAGE_PORT_H_ | |
jam
2017/01/23 18:08:56
nit: CONTENT_PUBLIC
| |
6 #define CONTENT_COMMON_MESSAGE_PORT_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/strings/string16.h" | |
14 #include "content/common/content_export.h" | |
15 #include "mojo/public/cpp/system/message_pipe.h" | |
16 | |
17 namespace content { | |
18 | |
19 // 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 // | |
22 // TODO(darin): Make this class move-only once no longer used with Chrome IPC. | |
23 // | |
24 class CONTENT_EXPORT MessagePort { | |
jam
2017/01/23 18:08:56
I think none of these methods are used outside con
| |
25 public: | |
26 ~MessagePort(); | |
27 MessagePort(); | |
28 | |
29 // Shallow copy, resulting in multiple references to the same port. | |
30 MessagePort(const MessagePort& other); | |
31 MessagePort& operator=(const MessagePort& other); | |
32 | |
33 explicit MessagePort(mojo::ScopedMessagePipeHandle handle); | |
34 | |
35 const mojo::ScopedMessagePipeHandle& GetHandle() const; | |
36 mojo::ScopedMessagePipeHandle ReleaseHandle() const; | |
37 | |
38 static std::vector<mojo::ScopedMessagePipeHandle> ReleaseHandles( | |
39 const std::vector<MessagePort>& ports); | |
40 | |
41 // Sends an encoded message (along with ports to transfer) to this port's | |
42 // peer. | |
43 void PostMessage(const base::string16& encoded_message, | |
44 std::vector<MessagePort> ports); | |
45 | |
46 // Get the next available encoded message if any. Returns true if a message | |
47 // was read. | |
48 bool GetMessage(base::string16* encoded_message, | |
49 std::vector<MessagePort>* ports); | |
50 | |
51 // This callback will be invoked on a background thread when messages are | |
52 // available to be read via GetMessage. | |
53 void SetCallback(const base::Closure& callback); | |
54 | |
55 // Clears any callback specified by a prior call to SetCallback. | |
56 void ClearCallback(); | |
57 | |
58 private: | |
59 class State : public base::RefCountedThreadSafe<State> { | |
60 public: | |
61 State(); | |
62 State(mojo::ScopedMessagePipeHandle handle); | |
63 | |
64 void AddWatch(); | |
65 void CancelWatch(); | |
66 static void OnHandleReady(uintptr_t context, | |
67 MojoResult result, | |
68 MojoHandleSignalsState signals_state, | |
69 MojoWatchNotificationFlags flags); | |
70 | |
71 mojo::ScopedMessagePipeHandle handle_; | |
72 base::Closure callback_; | |
73 | |
74 private: | |
75 friend class base::RefCountedThreadSafe<State>; | |
76 ~State(); | |
77 }; | |
78 mutable scoped_refptr<State> state_; | |
79 }; | |
80 | |
81 } // namespace content | |
82 | |
83 #endif // CONTENT_COMMON_MESSAGE_PORT_H_ | |
OLD | NEW |