| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "remoting/host/client_connection.h" | 5 #include "remoting/host/client_connection.h" |
| 6 | 6 |
| 7 #include "google/protobuf/message.h" | 7 #include "google/protobuf/message.h" |
| 8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
| 9 #include "remoting/base/protocol_decoder.h" | 9 #include "remoting/base/protocol_decoder.h" |
| 10 #include "remoting/base/protocol_util.h" | 10 #include "remoting/base/protocol_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 DCHECK(loop_); | 28 DCHECK(loop_); |
| 29 DCHECK(decoder_.get()); | 29 DCHECK(decoder_.get()); |
| 30 DCHECK(handler_); | 30 DCHECK(handler_); |
| 31 } | 31 } |
| 32 | 32 |
| 33 ClientConnection::~ClientConnection() { | 33 ClientConnection::~ClientConnection() { |
| 34 // TODO(hclam): When we shut down the viewer we may have to close the | 34 // TODO(hclam): When we shut down the viewer we may have to close the |
| 35 // jingle channel. | 35 // jingle channel. |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static |
| 39 scoped_refptr<media::DataBuffer> |
| 40 ClientConnection::CreateWireFormatDataBuffer( |
| 41 const HostMessage* msg) { |
| 42 // TODO(hclam): Instead of serializing |msg| create an DataBuffer |
| 43 // object that wraps around it. |
| 44 scoped_ptr<const HostMessage> message_deleter(msg); |
| 45 return SerializeAndFrameMessage(*msg); |
| 46 } |
| 47 |
| 38 void ClientConnection::SendInitClientMessage(int width, int height) { | 48 void ClientConnection::SendInitClientMessage(int width, int height) { |
| 39 DCHECK_EQ(loop_, MessageLoop::current()); | 49 DCHECK_EQ(loop_, MessageLoop::current()); |
| 40 DCHECK(!update_stream_size_); | 50 DCHECK(!update_stream_size_); |
| 41 | 51 |
| 42 // If we are disconnected then return. | 52 // If we are disconnected then return. |
| 43 if (!channel_) | 53 if (!channel_) |
| 44 return; | 54 return; |
| 45 | 55 |
| 46 HostMessage msg; | 56 HostMessage msg; |
| 47 msg.mutable_init_client()->set_width(width); | 57 msg.mutable_init_client()->set_width(width); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 msg.mutable_begin_update_stream(); | 71 msg.mutable_begin_update_stream(); |
| 62 DCHECK(msg.IsInitialized()); | 72 DCHECK(msg.IsInitialized()); |
| 63 | 73 |
| 64 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); | 74 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); |
| 65 DCHECK(!update_stream_size_); | 75 DCHECK(!update_stream_size_); |
| 66 update_stream_size_ += data->GetDataSize(); | 76 update_stream_size_ += data->GetDataSize(); |
| 67 channel_->Write(data); | 77 channel_->Write(data); |
| 68 } | 78 } |
| 69 | 79 |
| 70 void ClientConnection::SendUpdateStreamPacketMessage( | 80 void ClientConnection::SendUpdateStreamPacketMessage( |
| 71 const UpdateStreamPacketHeader* header, | |
| 72 scoped_refptr<DataBuffer> data) { | 81 scoped_refptr<DataBuffer> data) { |
| 73 DCHECK_EQ(loop_, MessageLoop::current()); | 82 DCHECK_EQ(loop_, MessageLoop::current()); |
| 74 | 83 |
| 75 // If we are disconnected then return. | 84 // If we are disconnected then return. |
| 76 if (!channel_) | 85 if (!channel_) |
| 77 return; | 86 return; |
| 78 | 87 |
| 79 HostMessage msg; | |
| 80 msg.mutable_update_stream_packet()->mutable_header()->CopyFrom(*header); | |
| 81 // TODO(hclam): This introduce one memory copy. Eliminate it. | |
| 82 msg.mutable_update_stream_packet()->set_data( | |
| 83 data->GetData(), data->GetDataSize()); | |
| 84 DCHECK(msg.IsInitialized()); | |
| 85 | |
| 86 scoped_refptr<DataBuffer> encoded_data = SerializeAndFrameMessage(msg); | |
| 87 update_stream_size_ += data->GetDataSize(); | 88 update_stream_size_ += data->GetDataSize(); |
| 88 channel_->Write(encoded_data); | 89 channel_->Write(data); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void ClientConnection::SendEndUpdateStreamMessage() { | 92 void ClientConnection::SendEndUpdateStreamMessage() { |
| 92 DCHECK_EQ(loop_, MessageLoop::current()); | 93 DCHECK_EQ(loop_, MessageLoop::current()); |
| 93 | 94 |
| 94 // If we are disconnected then return. | 95 // If we are disconnected then return. |
| 95 if (!channel_) | 96 if (!channel_) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 HostMessage msg; | 99 HostMessage msg; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DCHECK(decoder_.get()); | 180 DCHECK(decoder_.get()); |
| 180 ClientMessageList list; | 181 ClientMessageList list; |
| 181 decoder_->ParseClientMessages(data, &list); | 182 decoder_->ParseClientMessages(data, &list); |
| 182 | 183 |
| 183 // Then submit the messages to the handler. | 184 // Then submit the messages to the handler. |
| 184 DCHECK(handler_); | 185 DCHECK(handler_); |
| 185 handler_->HandleMessages(this, &list); | 186 handler_->HandleMessages(this, &list); |
| 186 } | 187 } |
| 187 | 188 |
| 188 } // namespace remoting | 189 } // namespace remoting |
| OLD | NEW |