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