Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: jingle/notifier/base/xmpp_connection.cc

Issue 6833031: Changed the jingle network code in ChromeAsyncSocket to use the client socket pool. This also all... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Lint fix Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
15 #include "net/base/ssl_config_service.h" 14 #include "net/base/ssl_config_service.h"
15 #include "net/socket/client_socket_factory.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 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) {
25 bool use_fake_ssl_client_socket = 25 bool use_fake_ssl_client_socket =
26 (xmpp_client_settings.protocol() == cricket::PROTO_SSLTCP); 26 (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. 27 // The default SSLConfig is good enough for us for now.
32 const net::SSLConfig ssl_config; 28 const net::SSLConfig ssl_config;
33 // These numbers were taken from similar numbers in 29 // These numbers were taken from similar numbers in
34 // XmppSocketAdapter. 30 // XmppSocketAdapter.
35 const size_t kReadBufSize = 64U * 1024U; 31 const size_t kReadBufSize = 64U * 1024U;
36 const size_t kWriteBufSize = 64U * 1024U; 32 const size_t kWriteBufSize = 64U * 1024U;
37 // TODO(akalin): Use a real NetLog. 33 // TODO(akalin): Use a real NetLog.
38 net::NetLog* const net_log = NULL; 34 net::NetLog* const net_log = NULL;
39 return new ChromeAsyncSocket( 35 return new ChromeAsyncSocket(ssl_config, request_context_getter,
40 client_socket_factory, ssl_config, cert_verifier, 36 use_fake_ssl_client_socket,
41 kReadBufSize, kWriteBufSize, net_log); 37 kReadBufSize, kWriteBufSize, net_log);
42 } 38 }
43 39
44 } // namespace 40 } // namespace
45 41
46 XmppConnection::XmppConnection( 42 XmppConnection::XmppConnection(
47 const buzz::XmppClientSettings& xmpp_client_settings, 43 const buzz::XmppClientSettings& xmpp_client_settings,
48 net::CertVerifier* cert_verifier, 44 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
49 Delegate* delegate, buzz::PreXmppAuth* pre_xmpp_auth) 45 Delegate* delegate, buzz::PreXmppAuth* pre_xmpp_auth)
50 : task_pump_(new TaskPump()), 46 : task_pump_(new TaskPump()),
51 on_connect_called_(false), 47 on_connect_called_(false),
52 delegate_(delegate) { 48 delegate_(delegate) {
53 DCHECK(delegate_); 49 DCHECK(delegate_);
54 // Owned by |task_pump_|, but is guaranteed to live at least as long 50 // Owned by |task_pump_|, but is guaranteed to live at least as long
55 // as this function. 51 // as this function.
56 WeakXmppClient* weak_xmpp_client = new WeakXmppClient(task_pump_.get()); 52 WeakXmppClient* weak_xmpp_client = new WeakXmppClient(task_pump_.get());
57 weak_xmpp_client->SignalStateChange.connect( 53 weak_xmpp_client->SignalStateChange.connect(
58 this, &XmppConnection::OnStateChange); 54 this, &XmppConnection::OnStateChange);
59 weak_xmpp_client->SignalLogInput.connect( 55 weak_xmpp_client->SignalLogInput.connect(
60 this, &XmppConnection::OnInputLog); 56 this, &XmppConnection::OnInputLog);
61 weak_xmpp_client->SignalLogOutput.connect( 57 weak_xmpp_client->SignalLogOutput.connect(
62 this, &XmppConnection::OnOutputLog); 58 this, &XmppConnection::OnOutputLog);
63 const char kLanguage[] = "en"; 59 const char kLanguage[] = "en";
64 buzz::XmppReturnStatus connect_status = 60 buzz::XmppReturnStatus connect_status =
65 weak_xmpp_client->Connect(xmpp_client_settings, kLanguage, 61 weak_xmpp_client->Connect(xmpp_client_settings, kLanguage,
66 CreateSocket(xmpp_client_settings, 62 CreateSocket(xmpp_client_settings,
67 cert_verifier), 63 request_context_getter),
68 pre_xmpp_auth); 64 pre_xmpp_auth);
69 // buzz::XmppClient::Connect() should never fail. 65 // buzz::XmppClient::Connect() should never fail.
70 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK); 66 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK);
71 weak_xmpp_client->Start(); 67 weak_xmpp_client->Start();
72 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr(); 68 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr();
73 } 69 }
74 70
75 XmppConnection::~XmppConnection() { 71 XmppConnection::~XmppConnection() {
76 DCHECK(non_thread_safe_.CalledOnValidThread()); 72 DCHECK(non_thread_safe_.CalledOnValidThread());
77 ClearClient(); 73 ClearClient();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 129 }
134 130
135 void XmppConnection::ClearClient() { 131 void XmppConnection::ClearClient() {
136 if (weak_xmpp_client_.get()) { 132 if (weak_xmpp_client_.get()) {
137 weak_xmpp_client_->Invalidate(); 133 weak_xmpp_client_->Invalidate();
138 DCHECK(!weak_xmpp_client_.get()); 134 DCHECK(!weak_xmpp_client_.get());
139 } 135 }
140 } 136 }
141 137
142 } // namespace notifier 138 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698