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

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

Powered by Google App Engine
This is Rietveld 408576698