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/client/client_config.h" |
7 #include "remoting/client/jingle_host_connection.h" | 8 #include "remoting/client/jingle_host_connection.h" |
8 #include "remoting/jingle_glue/jingle_thread.h" | 9 #include "remoting/jingle_glue/jingle_thread.h" |
9 | 10 |
10 namespace remoting { | 11 namespace remoting { |
11 | 12 |
12 JingleHostConnection::JingleHostConnection(JingleThread* network_thread) | 13 JingleHostConnection::JingleHostConnection(ClientContext* context) |
13 : network_thread_(network_thread), | 14 : context_(context), |
14 event_callback_(NULL) { | 15 event_callback_(NULL) { |
15 } | 16 } |
16 | 17 |
17 JingleHostConnection::~JingleHostConnection() { | 18 JingleHostConnection::~JingleHostConnection() { |
18 } | 19 } |
19 | 20 |
20 void JingleHostConnection::Connect(const std::string& username, | 21 void JingleHostConnection::Connect(ClientConfig* config, |
21 const std::string& password, | |
22 const std::string& host_jid, | |
23 HostEventCallback* event_callback) { | 22 HostEventCallback* event_callback) { |
24 message_loop()->PostTask( | 23 message_loop()->PostTask( |
25 FROM_HERE, | 24 FROM_HERE, |
26 NewRunnableMethod(this, &JingleHostConnection::DoConnect, | 25 NewRunnableMethod(this, &JingleHostConnection::DoConnect, |
27 username, password, host_jid, | 26 config, event_callback)); |
28 event_callback)); | |
29 } | 27 } |
30 | 28 |
31 void JingleHostConnection::Disconnect() { | 29 void JingleHostConnection::Disconnect() { |
32 message_loop()->PostTask( | 30 message_loop()->PostTask( |
33 FROM_HERE, | 31 FROM_HERE, |
34 NewRunnableMethod(this, &JingleHostConnection::DoDisconnect)); | 32 NewRunnableMethod(this, &JingleHostConnection::DoDisconnect)); |
35 } | 33 } |
36 | 34 |
37 void JingleHostConnection::OnStateChange(JingleChannel* channel, | 35 void JingleHostConnection::OnStateChange(JingleChannel* channel, |
38 JingleChannel::State state) { | 36 JingleChannel::State state) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 JingleClient* client, | 96 JingleClient* client, |
99 scoped_refptr<JingleChannel> channel) { | 97 scoped_refptr<JingleChannel> channel) { |
100 DCHECK_EQ(message_loop(), MessageLoop::current()); | 98 DCHECK_EQ(message_loop(), MessageLoop::current()); |
101 | 99 |
102 // TODO(ajwong): Should we log more aggressively on this and above? We | 100 // TODO(ajwong): Should we log more aggressively on this and above? We |
103 // shouldn't be getting any inbound connections. | 101 // shouldn't be getting any inbound connections. |
104 NOTREACHED() << "Clients can't accept inbound connections."; | 102 NOTREACHED() << "Clients can't accept inbound connections."; |
105 } | 103 } |
106 | 104 |
107 MessageLoop* JingleHostConnection::message_loop() { | 105 MessageLoop* JingleHostConnection::message_loop() { |
108 return network_thread_->message_loop(); | 106 return context_->jingle_thread()->message_loop(); |
109 } | 107 } |
110 | 108 |
111 void JingleHostConnection::DoConnect(const std::string& username, | 109 void JingleHostConnection::DoConnect(ClientConfig* config, |
112 const std::string& auth_token, | |
113 const std::string& host_jid, | |
114 HostEventCallback* event_callback) { | 110 HostEventCallback* event_callback) { |
115 DCHECK_EQ(message_loop(), MessageLoop::current()); | 111 DCHECK_EQ(message_loop(), MessageLoop::current()); |
116 | 112 |
117 event_callback_ = event_callback; | 113 event_callback_ = event_callback; |
118 | 114 |
119 jingle_client_ = new JingleClient(network_thread_); | 115 jingle_client_ = new JingleClient(context_->jingle_thread()); |
120 jingle_client_->Init(username, auth_token, kChromotingTokenServiceName, this); | 116 jingle_client_->Init(config->username(), config->auth_token(), |
121 jingle_channel_ = jingle_client_->Connect(host_jid, this); | 117 kChromotingTokenServiceName, this); |
| 118 jingle_channel_ = jingle_client_->Connect(config->host_jid(), this); |
122 } | 119 } |
123 | 120 |
124 void JingleHostConnection::DoDisconnect() { | 121 void JingleHostConnection::DoDisconnect() { |
125 DCHECK_EQ(message_loop(), MessageLoop::current()); | 122 DCHECK_EQ(message_loop(), MessageLoop::current()); |
126 | 123 |
127 if (jingle_channel_.get()) { | 124 if (jingle_channel_.get()) { |
128 jingle_channel_->Close(); | 125 jingle_channel_->Close(); |
129 jingle_channel_ = NULL; | 126 jingle_channel_ = NULL; |
130 } | 127 } |
131 | 128 |
132 if (jingle_client_.get()) { | 129 if (jingle_client_.get()) { |
133 jingle_client_->Close(); | 130 jingle_client_->Close(); |
134 jingle_client_ = NULL; | 131 jingle_client_ = NULL; |
135 } | 132 } |
136 } | 133 } |
137 | 134 |
138 } // namespace remoting | 135 } // namespace remoting |
OLD | NEW |