| 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 "jingle/notifier/base/xmpp_connection.h" | 5 #include "jingle/notifier/base/xmpp_connection.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "jingle/notifier/base/chrome_async_socket.h" | 11 #include "jingle/notifier/base/chrome_async_socket.h" |
| 12 #include "jingle/notifier/base/task_pump.h" | 12 #include "jingle/notifier/base/task_pump.h" |
| 13 #include "jingle/notifier/base/weak_xmpp_client.h" | 13 #include "jingle/notifier/base/weak_xmpp_client.h" |
| 14 #include "jingle/notifier/base/xmpp_client_socket_factory.h" | 14 #include "jingle/notifier/base/xmpp_client_socket_factory.h" |
| 15 #include "net/base/ssl_config_service.h" | 15 #include "net/base/ssl_config_service.h" |
| 16 #include "talk/xmpp/xmppclientsettings.h" | 16 #include "talk/xmpp/xmppclientsettings.h" |
| 17 | 17 |
| 18 namespace notifier { | 18 namespace notifier { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 buzz::AsyncSocket* CreateSocket( | 22 buzz::AsyncSocket* CreateSocket( |
| 23 const buzz::XmppClientSettings& xmpp_client_settings) { | 23 const buzz::XmppClientSettings& xmpp_client_settings, |
| 24 net::CertVerifier* cert_verifier) { |
| 24 bool use_fake_ssl_client_socket = | 25 bool use_fake_ssl_client_socket = |
| 25 (xmpp_client_settings.protocol() == cricket::PROTO_SSLTCP); | 26 (xmpp_client_settings.protocol() == cricket::PROTO_SSLTCP); |
| 26 net::ClientSocketFactory* const client_socket_factory = | 27 net::ClientSocketFactory* const client_socket_factory = |
| 27 new XmppClientSocketFactory( | 28 new XmppClientSocketFactory( |
| 28 net::ClientSocketFactory::GetDefaultFactory(), | 29 net::ClientSocketFactory::GetDefaultFactory(), |
| 29 use_fake_ssl_client_socket); | 30 use_fake_ssl_client_socket); |
| 30 // The default SSLConfig is good enough for us for now. | 31 // The default SSLConfig is good enough for us for now. |
| 31 const net::SSLConfig ssl_config; | 32 const net::SSLConfig ssl_config; |
| 32 // These numbers were taken from similar numbers in | 33 // These numbers were taken from similar numbers in |
| 33 // XmppSocketAdapter. | 34 // XmppSocketAdapter. |
| 34 const size_t kReadBufSize = 64U * 1024U; | 35 const size_t kReadBufSize = 64U * 1024U; |
| 35 const size_t kWriteBufSize = 64U * 1024U; | 36 const size_t kWriteBufSize = 64U * 1024U; |
| 36 // TODO(akalin): Use a real NetLog. | 37 // TODO(akalin): Use a real NetLog. |
| 37 net::NetLog* const net_log = NULL; | 38 net::NetLog* const net_log = NULL; |
| 38 return new ChromeAsyncSocket( | 39 return new ChromeAsyncSocket( |
| 39 client_socket_factory, ssl_config, | 40 client_socket_factory, ssl_config, cert_verifier, |
| 40 kReadBufSize, kWriteBufSize, net_log); | 41 kReadBufSize, kWriteBufSize, net_log); |
| 41 } | 42 } |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| 44 | 45 |
| 45 XmppConnection::XmppConnection( | 46 XmppConnection::XmppConnection( |
| 46 const buzz::XmppClientSettings& xmpp_client_settings, | 47 const buzz::XmppClientSettings& xmpp_client_settings, |
| 48 net::CertVerifier* cert_verifier, |
| 47 Delegate* delegate, buzz::PreXmppAuth* pre_xmpp_auth) | 49 Delegate* delegate, buzz::PreXmppAuth* pre_xmpp_auth) |
| 48 : task_pump_(new TaskPump()), | 50 : task_pump_(new TaskPump()), |
| 49 on_connect_called_(false), | 51 on_connect_called_(false), |
| 50 delegate_(delegate) { | 52 delegate_(delegate) { |
| 51 DCHECK(delegate_); | 53 DCHECK(delegate_); |
| 52 // Owned by |task_pump_|, but is guaranteed to live at least as long | 54 // Owned by |task_pump_|, but is guaranteed to live at least as long |
| 53 // as this function. | 55 // as this function. |
| 54 WeakXmppClient* weak_xmpp_client = new WeakXmppClient(task_pump_.get()); | 56 WeakXmppClient* weak_xmpp_client = new WeakXmppClient(task_pump_.get()); |
| 55 weak_xmpp_client->SignalStateChange.connect( | 57 weak_xmpp_client->SignalStateChange.connect( |
| 56 this, &XmppConnection::OnStateChange); | 58 this, &XmppConnection::OnStateChange); |
| 57 weak_xmpp_client->SignalLogInput.connect( | 59 weak_xmpp_client->SignalLogInput.connect( |
| 58 this, &XmppConnection::OnInputLog); | 60 this, &XmppConnection::OnInputLog); |
| 59 weak_xmpp_client->SignalLogOutput.connect( | 61 weak_xmpp_client->SignalLogOutput.connect( |
| 60 this, &XmppConnection::OnOutputLog); | 62 this, &XmppConnection::OnOutputLog); |
| 61 const char kLanguage[] = "en"; | 63 const char kLanguage[] = "en"; |
| 62 buzz::XmppReturnStatus connect_status = | 64 buzz::XmppReturnStatus connect_status = |
| 63 weak_xmpp_client->Connect(xmpp_client_settings, kLanguage, | 65 weak_xmpp_client->Connect(xmpp_client_settings, kLanguage, |
| 64 CreateSocket(xmpp_client_settings), | 66 CreateSocket(xmpp_client_settings, |
| 67 cert_verifier), |
| 65 pre_xmpp_auth); | 68 pre_xmpp_auth); |
| 66 // buzz::XmppClient::Connect() should never fail. | 69 // buzz::XmppClient::Connect() should never fail. |
| 67 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK); | 70 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK); |
| 68 weak_xmpp_client->Start(); | 71 weak_xmpp_client->Start(); |
| 69 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr(); | 72 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 XmppConnection::~XmppConnection() { | 75 XmppConnection::~XmppConnection() { |
| 73 DCHECK(non_thread_safe_.CalledOnValidThread()); | 76 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 74 ClearClient(); | 77 ClearClient(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 133 } |
| 131 | 134 |
| 132 void XmppConnection::ClearClient() { | 135 void XmppConnection::ClearClient() { |
| 133 if (weak_xmpp_client_.get()) { | 136 if (weak_xmpp_client_.get()) { |
| 134 weak_xmpp_client_->Invalidate(); | 137 weak_xmpp_client_->Invalidate(); |
| 135 DCHECK(!weak_xmpp_client_.get()); | 138 DCHECK(!weak_xmpp_client_.get()); |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 | 141 |
| 139 } // namespace notifier | 142 } // namespace notifier |
| OLD | NEW |