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 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 5 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "jingle/glue/chrome_async_socket.h" | |
11 #include "jingle/glue/task_pump.h" | |
12 #include "jingle/glue/xmpp_client_socket_factory.h" | |
10 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" | 13 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" |
11 #include "remoting/jingle_glue/jingle_thread.h" | 14 #include "net/socket/client_socket_factory.h" |
12 #include "remoting/jingle_glue/xmpp_socket_adapter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
13 #include "third_party/libjingle/source/talk/base/asyncsocket.h" | 16 #include "third_party/libjingle/source/talk/base/thread.h" |
14 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" | 17 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" |
15 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" | 18 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 const char kDefaultResourceName[] = "chromoting"; | 22 const char kDefaultResourceName[] = "chromoting"; |
20 | 23 |
21 // Use 58 seconds keep-alive interval, in case routers terminate | 24 // Use 58 seconds keep-alive interval, in case routers terminate |
22 // connections that are idle for more than a minute. | 25 // connections that are idle for more than a minute. |
23 const int kKeepAliveIntervalSeconds = 50; | 26 const int kKeepAliveIntervalSeconds = 50; |
24 | 27 |
28 // Read buffer size used by ChromeAsyncSocket for read and write buffers. Most | |
29 // of XMPP messages are smaller than 4kB. | |
30 const size_t kReadBufferSize = 4096; | |
31 const size_t kWriteBufferSize = 4096; | |
32 | |
25 void DisconnectXmppClient(buzz::XmppClient* client) { | 33 void DisconnectXmppClient(buzz::XmppClient* client) { |
26 client->Disconnect(); | 34 client->Disconnect(); |
27 } | 35 } |
28 | 36 |
29 } // namespace | 37 } // namespace |
30 | 38 |
31 namespace remoting { | 39 namespace remoting { |
32 | 40 |
33 XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread, | 41 XmppSignalStrategy::XmppSignalStrategy( |
34 const std::string& username, | 42 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
35 const std::string& auth_token, | 43 const std::string& username, |
36 const std::string& auth_token_service) | 44 const std::string& auth_token, |
37 : thread_(jingle_thread), | 45 const std::string& auth_token_service) |
46 : request_context_getter_(request_context_getter), | |
38 username_(username), | 47 username_(username), |
39 auth_token_(auth_token), | 48 auth_token_(auth_token), |
40 auth_token_service_(auth_token_service), | 49 auth_token_service_(auth_token_service), |
41 resource_name_(kDefaultResourceName), | 50 resource_name_(kDefaultResourceName), |
42 xmpp_client_(NULL), | 51 xmpp_client_(NULL), |
43 state_(DISCONNECTED), | 52 state_(DISCONNECTED), |
44 error_(OK) { | 53 error_(OK) { |
45 } | 54 } |
46 | 55 |
47 XmppSignalStrategy::~XmppSignalStrategy() { | 56 XmppSignalStrategy::~XmppSignalStrategy() { |
48 Disconnect(); | 57 Disconnect(); |
49 } | 58 } |
50 | 59 |
51 void XmppSignalStrategy::Connect() { | 60 void XmppSignalStrategy::Connect() { |
52 DCHECK(CalledOnValidThread()); | 61 DCHECK(CalledOnValidThread()); |
53 | 62 |
54 // Disconnect first if we are currently connected. | 63 // Disconnect first if we are currently connected. |
55 Disconnect(); | 64 Disconnect(); |
56 | 65 |
57 buzz::XmppClientSettings settings; | 66 buzz::XmppClientSettings settings; |
58 buzz::Jid login_jid(username_); | 67 buzz::Jid login_jid(username_); |
59 settings.set_user(login_jid.node()); | 68 settings.set_user(login_jid.node()); |
60 settings.set_host(login_jid.domain()); | 69 settings.set_host(login_jid.domain()); |
61 settings.set_resource(resource_name_); | 70 settings.set_resource(resource_name_); |
62 settings.set_use_tls(buzz::TLS_ENABLED); | 71 settings.set_use_tls(buzz::TLS_ENABLED); |
63 settings.set_token_service(auth_token_service_); | 72 settings.set_token_service(auth_token_service_); |
64 settings.set_auth_token(buzz::AUTH_MECHANISM_GOOGLE_TOKEN, auth_token_); | 73 settings.set_auth_token(buzz::AUTH_MECHANISM_GOOGLE_TOKEN, auth_token_); |
65 settings.set_server(talk_base::SocketAddress("talk.google.com", 5222)); | 74 settings.set_server(talk_base::SocketAddress("talk.google.com", 5222)); |
66 | 75 |
67 buzz::AsyncSocket* socket = new XmppSocketAdapter(settings, false); | 76 scoped_ptr<jingle_glue::XmppClientSocketFactory> socket_factory( |
77 new jingle_glue::XmppClientSocketFactory( | |
78 net::ClientSocketFactory::GetDefaultFactory(), | |
79 net::SSLConfig(), request_context_getter_, false)); | |
80 buzz::AsyncSocket* socket = new jingle_glue::ChromeAsyncSocket( | |
81 socket_factory.release(), kReadBufferSize, kWriteBufferSize); | |
Wez
2012/07/25 10:26:27
Isn't it a waste of resources to have a separate f
Sergey Ulanov
2012/07/25 18:50:49
We never need more than one XmppSignalStrategy, so
| |
68 | 82 |
69 xmpp_client_ = new buzz::XmppClient(thread_->task_pump()); | 83 task_runner_.reset(new jingle_glue::TaskPump()); |
84 xmpp_client_ = new buzz::XmppClient(task_runner_.get()); | |
70 xmpp_client_->Connect(settings, "", socket, CreatePreXmppAuth(settings)); | 85 xmpp_client_->Connect(settings, "", socket, CreatePreXmppAuth(settings)); |
71 xmpp_client_->SignalStateChange.connect( | 86 xmpp_client_->SignalStateChange.connect( |
72 this, &XmppSignalStrategy::OnConnectionStateChanged); | 87 this, &XmppSignalStrategy::OnConnectionStateChanged); |
73 xmpp_client_->engine()->AddStanzaHandler(this, buzz::XmppEngine::HL_TYPE); | 88 xmpp_client_->engine()->AddStanzaHandler(this, buzz::XmppEngine::HL_TYPE); |
74 xmpp_client_->Start(); | 89 xmpp_client_->Start(); |
75 | 90 |
76 SetState(CONNECTING); | 91 SetState(CONNECTING); |
77 } | 92 } |
78 | 93 |
79 void XmppSignalStrategy::Disconnect() { | 94 void XmppSignalStrategy::Disconnect() { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; | 233 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; |
219 if (settings.token_service() == "oauth2") { | 234 if (settings.token_service() == "oauth2") { |
220 mechanism = "X-OAUTH2"; | 235 mechanism = "X-OAUTH2"; |
221 } | 236 } |
222 | 237 |
223 return new notifier::GaiaTokenPreXmppAuth( | 238 return new notifier::GaiaTokenPreXmppAuth( |
224 jid.Str(), settings.auth_token(), settings.token_service(), mechanism); | 239 jid.Str(), settings.auth_token(), settings.token_service(), mechanism); |
225 } | 240 } |
226 | 241 |
227 } // namespace remoting | 242 } // namespace remoting |
OLD | NEW |