| OLD | NEW |
| 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 CHROME_NACL_NACL_IPC_ADAPTER_H_ | 5 #ifndef CHROME_NACL_NACL_IPC_ADAPTER_H_ |
| 6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ | 6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // Creates an adapter, using the thread associated with the given task | 53 // Creates an adapter, using the thread associated with the given task |
| 54 // runner for posting messages. In normal use, the task runner will post to | 54 // runner for posting messages. In normal use, the task runner will post to |
| 55 // the I/O thread of the process. | 55 // the I/O thread of the process. |
| 56 NaClIPCAdapter(const IPC::ChannelHandle& handle, base::TaskRunner* runner); | 56 NaClIPCAdapter(const IPC::ChannelHandle& handle, base::TaskRunner* runner); |
| 57 | 57 |
| 58 // Initializes with a given channel that's already created for testing | 58 // Initializes with a given channel that's already created for testing |
| 59 // purposes. This function will take ownership of the given channel. | 59 // purposes. This function will take ownership of the given channel. |
| 60 NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, base::TaskRunner* runner); | 60 NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, base::TaskRunner* runner); |
| 61 | 61 |
| 62 virtual ~NaClIPCAdapter(); | |
| 63 | |
| 64 // Implementation of sendmsg. Returns the number of bytes written or -1 on | 62 // Implementation of sendmsg. Returns the number of bytes written or -1 on |
| 65 // failure. | 63 // failure. |
| 66 int Send(const char* input_data, size_t input_data_len); | 64 int Send(const char* input_data, size_t input_data_len); |
| 67 | 65 |
| 68 // Implementation of recvmsg. Returns the number of bytes read or -1 on | 66 // Implementation of recvmsg. Returns the number of bytes read or -1 on |
| 69 // failure. This will block until there's an error or there is data to | 67 // failure. This will block until there's an error or there is data to |
| 70 // read. | 68 // read. |
| 71 int BlockingReceive(char* output_buffer, int output_buffer_size); | 69 int BlockingReceive(char* output_buffer, int output_buffer_size); |
| 72 | 70 |
| 73 // Closes the IPC channel. | 71 // Closes the IPC channel. |
| 74 void CloseChannel(); | 72 void CloseChannel(); |
| 75 | 73 |
| 76 // Listener implementation. | 74 // Listener implementation. |
| 77 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 76 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 79 virtual void OnChannelError() OVERRIDE; | 77 virtual void OnChannelError() OVERRIDE; |
| 80 | 78 |
| 81 private: | 79 private: |
| 80 friend class base::RefCountedThreadSafe<NaClIPCAdapter>; |
| 81 |
| 82 class RewrittenMessage; | 82 class RewrittenMessage; |
| 83 | 83 |
| 84 // This is the data that must only be accessed inside the lock. This struct | 84 // This is the data that must only be accessed inside the lock. This struct |
| 85 // just separates it so it's easier to see. | 85 // just separates it so it's easier to see. |
| 86 struct LockedData { | 86 struct LockedData { |
| 87 LockedData(); | 87 LockedData(); |
| 88 ~LockedData(); | 88 ~LockedData(); |
| 89 | 89 |
| 90 // Messages that we have read off of the Chrome IPC channel that are waiting | 90 // Messages that we have read off of the Chrome IPC channel that are waiting |
| 91 // to be received by the plugin. | 91 // to be received by the plugin. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 105 | 105 |
| 106 // This is the data that must only be accessed on the I/O thread (as defined | 106 // This is the data that must only be accessed on the I/O thread (as defined |
| 107 // by TaskRunner). This struct just separates it so it's easier to see. | 107 // by TaskRunner). This struct just separates it so it's easier to see. |
| 108 struct IOThreadData { | 108 struct IOThreadData { |
| 109 IOThreadData(); | 109 IOThreadData(); |
| 110 ~IOThreadData(); | 110 ~IOThreadData(); |
| 111 | 111 |
| 112 scoped_ptr<IPC::Channel> channel_; | 112 scoped_ptr<IPC::Channel> channel_; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 virtual ~NaClIPCAdapter(); |
| 116 |
| 115 // Reads up to the given amount of data. Returns 0 if nothing is waiting. | 117 // Reads up to the given amount of data. Returns 0 if nothing is waiting. |
| 116 int LockedReceive(char* output_buffer, int output_buffer_size); | 118 int LockedReceive(char* output_buffer, int output_buffer_size); |
| 117 | 119 |
| 118 // Sends a message that we know has been completed to the Chrome process. | 120 // Sends a message that we know has been completed to the Chrome process. |
| 119 bool SendCompleteMessage(const char* buffer, size_t buffer_len); | 121 bool SendCompleteMessage(const char* buffer, size_t buffer_len); |
| 120 | 122 |
| 121 // Clears the LockedData.to_be_sent_ structure in a way to make sure that | 123 // Clears the LockedData.to_be_sent_ structure in a way to make sure that |
| 122 // the memory is deleted. std::string can sometimes hold onto the buffer | 124 // the memory is deleted. std::string can sometimes hold onto the buffer |
| 123 // for future use which we don't want. | 125 // for future use which we don't want. |
| 124 void ClearToBeSent(); | 126 void ClearToBeSent(); |
| 125 | 127 |
| 126 void CloseChannelOnIOThread(); | 128 void CloseChannelOnIOThread(); |
| 127 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); | 129 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); |
| 128 | 130 |
| 129 base::Lock lock_; | 131 base::Lock lock_; |
| 130 base::ConditionVariable cond_var_; | 132 base::ConditionVariable cond_var_; |
| 131 | 133 |
| 132 scoped_refptr<base::TaskRunner> task_runner_; | 134 scoped_refptr<base::TaskRunner> task_runner_; |
| 133 | 135 |
| 134 // To be accessed inside of lock_ only. | 136 // To be accessed inside of lock_ only. |
| 135 LockedData locked_data_; | 137 LockedData locked_data_; |
| 136 | 138 |
| 137 // To be accessed on the I/O thread (via task runner) only. | 139 // To be accessed on the I/O thread (via task runner) only. |
| 138 IOThreadData io_thread_data_; | 140 IOThreadData io_thread_data_; |
| 139 | 141 |
| 140 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); | 142 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); |
| 141 }; | 143 }; |
| 142 | 144 |
| 143 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ | 145 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ |
| OLD | NEW |