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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "remoting/base/constants.h" | 6 #include "remoting/base/constants.h" |
| 7 #include "remoting/base/protocol_util.h" |
7 #include "remoting/client/client_config.h" | 8 #include "remoting/client/client_config.h" |
8 #include "remoting/client/jingle_host_connection.h" | 9 #include "remoting/client/jingle_host_connection.h" |
9 #include "remoting/jingle_glue/jingle_thread.h" | 10 #include "remoting/jingle_glue/jingle_thread.h" |
10 | 11 |
11 namespace remoting { | 12 namespace remoting { |
12 | 13 |
13 JingleHostConnection::JingleHostConnection(ClientContext* context) | 14 JingleHostConnection::JingleHostConnection(ClientContext* context) |
14 : context_(context), | 15 : context_(context), |
15 event_callback_(NULL) { | 16 event_callback_(NULL) { |
16 } | 17 } |
17 | 18 |
18 JingleHostConnection::~JingleHostConnection() { | 19 JingleHostConnection::~JingleHostConnection() { |
19 } | 20 } |
20 | 21 |
21 void JingleHostConnection::Connect(const ClientConfig& config, | 22 void JingleHostConnection::Connect(const ClientConfig& config, |
22 HostEventCallback* event_callback) { | 23 HostEventCallback* event_callback) { |
23 message_loop()->PostTask( | 24 message_loop()->PostTask( |
24 FROM_HERE, | 25 FROM_HERE, |
25 NewRunnableMethod(this, &JingleHostConnection::DoConnect, | 26 NewRunnableMethod(this, &JingleHostConnection::DoConnect, |
26 config, event_callback)); | 27 config, event_callback)); |
27 } | 28 } |
28 | 29 |
29 void JingleHostConnection::Disconnect() { | 30 void JingleHostConnection::Disconnect() { |
30 message_loop()->PostTask( | 31 message_loop()->PostTask( |
31 FROM_HERE, | 32 FROM_HERE, |
32 NewRunnableMethod(this, &JingleHostConnection::DoDisconnect)); | 33 NewRunnableMethod(this, &JingleHostConnection::DoDisconnect)); |
33 } | 34 } |
34 | 35 |
| 36 void JingleHostConnection::SendEvent(const ChromotingClientMessage& msg) { |
| 37 if (message_loop() != MessageLoop::current()) { |
| 38 message_loop()->PostTask( |
| 39 FROM_HERE, |
| 40 NewRunnableMethod(this, &JingleHostConnection::SendEvent, msg)); |
| 41 return; |
| 42 } |
| 43 |
| 44 // Don't send messages if we're disconnected. |
| 45 if (jingle_channel_ == NULL) { |
| 46 return; |
| 47 } |
| 48 |
| 49 jingle_channel_->Write(SerializeAndFrameMessage(msg)); |
| 50 } |
| 51 |
35 void JingleHostConnection::OnStateChange(JingleChannel* channel, | 52 void JingleHostConnection::OnStateChange(JingleChannel* channel, |
36 JingleChannel::State state) { | 53 JingleChannel::State state) { |
37 DCHECK_EQ(message_loop(), MessageLoop::current()); | 54 DCHECK_EQ(message_loop(), MessageLoop::current()); |
38 DCHECK(event_callback_); | 55 DCHECK(event_callback_); |
39 | 56 |
40 switch (state) { | 57 switch (state) { |
41 case JingleChannel::FAILED: | 58 case JingleChannel::FAILED: |
42 event_callback_->OnConnectionFailed(this); | 59 event_callback_->OnConnectionFailed(this); |
43 break; | 60 break; |
44 | 61 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 jingle_channel_ = NULL; | 143 jingle_channel_ = NULL; |
127 } | 144 } |
128 | 145 |
129 if (jingle_client_.get()) { | 146 if (jingle_client_.get()) { |
130 jingle_client_->Close(); | 147 jingle_client_->Close(); |
131 jingle_client_ = NULL; | 148 jingle_client_ = NULL; |
132 } | 149 } |
133 } | 150 } |
134 | 151 |
135 } // namespace remoting | 152 } // namespace remoting |
OLD | NEW |