Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: ipc/ipc_channel_nacl.h

Issue 10174048: PPAPI/NaCl: Speculative implementation for ipc_channel_nacl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix some TODOs Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 IPC_IPC_CHANNEL_NACL_H_ 5 #ifndef IPC_IPC_CHANNEL_NACL_H_
6 #define IPC_IPC_CHANNEL_NACL_H_ 6 #define IPC_IPC_CHANNEL_NACL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <deque>
10 #include <string>
11
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/simple_thread.h"
9 #include "ipc/ipc_channel.h" 16 #include "ipc/ipc_channel.h"
10 #include "ipc/ipc_channel_reader.h" 17 #include "ipc/ipc_channel_reader.h"
11 18
12 namespace IPC { 19 namespace IPC {
13 20
14 // Similar to the Posix version of ChannelImpl but for Native Client code. 21 // Similar to the Posix version of ChannelImpl but for Native Client code.
15 // This is somewhat different because NaCl's send/recvmsg is slightly different 22 // This is somewhat different because sendmsg/recvmsg here do not follow POSIX
16 // and we don't need to worry about complicated set up and READWRITE mode for 23 // semantics. Instead, they are implemented by a custom embedding of
17 // sharing handles. 24 // NaClDescCustom. See NaClIPCAdapter for the trusted-side implementation.
25 //
26 // We don't need to worry about complicated set up and READWRITE mode for
27 // sharing handles. We also currently do not support passing file descriptors or
28 // named pipes, and we use background threads to emulate signaling when we can
29 // read or write without blocking.
18 class Channel::ChannelImpl : public internal::ChannelReader { 30 class Channel::ChannelImpl : public internal::ChannelReader {
19 public: 31 public:
32 // Mirror methods of Channel, see ipc_channel.h for description.
20 ChannelImpl(const IPC::ChannelHandle& channel_handle, 33 ChannelImpl(const IPC::ChannelHandle& channel_handle,
21 Mode mode, 34 Mode mode,
22 Listener* listener); 35 Listener* listener);
23 virtual ~ChannelImpl(); 36 virtual ~ChannelImpl();
24 37
25 // Channel implementation. 38 // Channel implementation.
26 bool Connect(); 39 bool Connect();
27 void Close(); 40 void Close();
28 bool Send(Message* message); 41 bool Send(Message* message);
29 int GetClientFileDescriptor() const;
30 int TakeClientFileDescriptor();
31 bool AcceptsConnections() const;
32 bool HasAcceptedConnection() const;
33 bool GetClientEuid(uid_t* client_euid) const;
34 void ResetToAcceptingConnectionState();
35 static bool IsNamedServerInitialized(const std::string& channel_id);
36 42
43 // Posted to the main thread by ReaderThreadRunner.
44 void DidRecvMsg(scoped_ptr<std::vector<char> > buffer);
45 void ReadDidFail();
46
47 private:
48 class ReaderThreadRunner;
49
50 bool CreatePipe(const IPC::ChannelHandle& channel_handle);
51 bool ProcessOutgoingMessages();
52
53 // ChannelReader implementation.
37 virtual ReadState ReadData(char* buffer, 54 virtual ReadState ReadData(char* buffer,
38 int buffer_len, 55 int buffer_len,
39 int* bytes_read) OVERRIDE; 56 int* bytes_read) OVERRIDE;
40 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE; 57 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE;
41 virtual bool DidEmptyInputBuffers() OVERRIDE; 58 virtual bool DidEmptyInputBuffers() OVERRIDE;
42 virtual void HandleHelloMessage(const Message& msg) OVERRIDE; 59 virtual void HandleHelloMessage(const Message& msg) OVERRIDE;
43 60
44 private: 61 Mode mode_;
62 base::ProcessId peer_pid_;
63 bool waiting_connect_;
64
65 // The pipe used for communication.
66 int pipe_;
67
68 // The "name" of our pipe. On Windows this is the global identifier for
69 // the pipe. On POSIX it's used as a key in a local map of file descriptors.
70 // For NaCl, we don't actually support looking up file descriptors by name,
71 // and it's only used for debug information.
72 std::string pipe_name_;
73
74 // We use a thread for reading, so that we can simply block on reading and
75 // post the received data back to the main thread to be properly interleaved
76 // with other tasks in the MessagePump.
77 //
78 // imc_recvmsg supports non-blocking reads, but there's no easy way to be
79 // informed when a write or read can be done without blocking (this is handled
80 // by libevent in Posix).
81 scoped_ptr<ReaderThreadRunner> reader_thread_runner_;
82 scoped_ptr<base::DelegateSimpleThread> reader_thread_;
83
84 // IPC::ChannelReader expects to be able to call ReadData on us to
85 // synchronously read data waiting in the pipe's buffer without blocking.
86 // Since we can't do that (see 1 and 2 above), the reader thread does blocking
87 // reads and posts the data over to the main thread in byte vectors. Each byte
88 // vector is the result of one call to "recvmsg". When ReadData is called, it
89 // pulls the bytes out of these vectors in order.
90 // TODO(dmichael): There's probably a more efficient way to emulate this with
91 // a circular buffer or something, so we don't have to do so
92 // many heap allocations. But it maybe isn't worth
93 // the trouble given that we probably want to implement 1 and
94 // 2 above in NaCl eventually.
95 std::deque<linked_ptr<std::vector<char> > > read_queue_;
96
97 // This queue is used when a message is sent prior to Connect having been
98 // called. Normally after we're connected, the queue is empty.
99 std::deque<linked_ptr<Message> > output_queue_;
100
101 base::WeakPtrFactory<ChannelImpl> weak_ptr_factory_;
102
45 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelImpl); 103 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelImpl);
46 }; 104 };
47 105
48 } // namespace IPC 106 } // namespace IPC
49 107
50 #endif // IPC_IPC_CHANNEL_NACL_H_ 108 #endif // IPC_IPC_CHANNEL_NACL_H_
OLDNEW
« no previous file with comments | « base/message_loop.cc ('k') | ipc/ipc_channel_nacl.cc » ('j') | ipc/ipc_channel_nacl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698