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

Side by Side Diff: remoting/jingle_glue/xmpp_signal_strategy.cc

Issue 10829040: Revert 148418 - Always use chromium threads for IO in remoting host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « remoting/jingle_glue/xmpp_signal_strategy.h ('k') | remoting/jingle_glue/xmpp_socket_adapter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" 10 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h"
14 #include "net/socket/client_socket_factory.h" 11 #include "remoting/jingle_glue/jingle_thread.h"
15 #include "net/url_request/url_request_context_getter.h" 12 #include "remoting/jingle_glue/xmpp_socket_adapter.h"
16 #include "third_party/libjingle/source/talk/base/thread.h" 13 #include "third_party/libjingle/source/talk/base/asyncsocket.h"
17 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" 14 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h"
18 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" 15 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h"
19 16
20 namespace { 17 namespace {
21 18
22 const char kDefaultResourceName[] = "chromoting"; 19 const char kDefaultResourceName[] = "chromoting";
23 20
24 // Use 58 seconds keep-alive interval, in case routers terminate 21 // Use 58 seconds keep-alive interval, in case routers terminate
25 // connections that are idle for more than a minute. 22 // connections that are idle for more than a minute.
26 const int kKeepAliveIntervalSeconds = 50; 23 const int kKeepAliveIntervalSeconds = 50;
27 24
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
33 void DisconnectXmppClient(buzz::XmppClient* client) { 25 void DisconnectXmppClient(buzz::XmppClient* client) {
34 client->Disconnect(); 26 client->Disconnect();
35 } 27 }
36 28
37 } // namespace 29 } // namespace
38 30
39 namespace remoting { 31 namespace remoting {
40 32
41 XmppSignalStrategy::XmppSignalStrategy( 33 XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread,
42 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 34 const std::string& username,
43 const std::string& username, 35 const std::string& auth_token,
44 const std::string& auth_token, 36 const std::string& auth_token_service)
45 const std::string& auth_token_service) 37 : thread_(jingle_thread),
46 : request_context_getter_(request_context_getter),
47 username_(username), 38 username_(username),
48 auth_token_(auth_token), 39 auth_token_(auth_token),
49 auth_token_service_(auth_token_service), 40 auth_token_service_(auth_token_service),
50 resource_name_(kDefaultResourceName), 41 resource_name_(kDefaultResourceName),
51 xmpp_client_(NULL), 42 xmpp_client_(NULL),
52 state_(DISCONNECTED), 43 state_(DISCONNECTED),
53 error_(OK) { 44 error_(OK) {
54 } 45 }
55 46
56 XmppSignalStrategy::~XmppSignalStrategy() { 47 XmppSignalStrategy::~XmppSignalStrategy() {
57 Disconnect(); 48 Disconnect();
58 } 49 }
59 50
60 void XmppSignalStrategy::Connect() { 51 void XmppSignalStrategy::Connect() {
61 DCHECK(CalledOnValidThread()); 52 DCHECK(CalledOnValidThread());
62 53
63 // Disconnect first if we are currently connected. 54 // Disconnect first if we are currently connected.
64 Disconnect(); 55 Disconnect();
65 56
66 buzz::XmppClientSettings settings; 57 buzz::XmppClientSettings settings;
67 buzz::Jid login_jid(username_); 58 buzz::Jid login_jid(username_);
68 settings.set_user(login_jid.node()); 59 settings.set_user(login_jid.node());
69 settings.set_host(login_jid.domain()); 60 settings.set_host(login_jid.domain());
70 settings.set_resource(resource_name_); 61 settings.set_resource(resource_name_);
71 settings.set_use_tls(buzz::TLS_ENABLED); 62 settings.set_use_tls(buzz::TLS_ENABLED);
72 settings.set_token_service(auth_token_service_); 63 settings.set_token_service(auth_token_service_);
73 settings.set_auth_token(buzz::AUTH_MECHANISM_GOOGLE_TOKEN, auth_token_); 64 settings.set_auth_token(buzz::AUTH_MECHANISM_GOOGLE_TOKEN, auth_token_);
74 settings.set_server(talk_base::SocketAddress("talk.google.com", 5222)); 65 settings.set_server(talk_base::SocketAddress("talk.google.com", 5222));
75 66
76 scoped_ptr<jingle_glue::XmppClientSocketFactory> socket_factory( 67 buzz::AsyncSocket* socket = new XmppSocketAdapter(settings, false);
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);
82 68
83 task_runner_.reset(new jingle_glue::TaskPump()); 69 xmpp_client_ = new buzz::XmppClient(thread_->task_pump());
84 xmpp_client_ = new buzz::XmppClient(task_runner_.get());
85 xmpp_client_->Connect(settings, "", socket, CreatePreXmppAuth(settings)); 70 xmpp_client_->Connect(settings, "", socket, CreatePreXmppAuth(settings));
86 xmpp_client_->SignalStateChange.connect( 71 xmpp_client_->SignalStateChange.connect(
87 this, &XmppSignalStrategy::OnConnectionStateChanged); 72 this, &XmppSignalStrategy::OnConnectionStateChanged);
88 xmpp_client_->engine()->AddStanzaHandler(this, buzz::XmppEngine::HL_TYPE); 73 xmpp_client_->engine()->AddStanzaHandler(this, buzz::XmppEngine::HL_TYPE);
89 xmpp_client_->Start(); 74 xmpp_client_->Start();
90 75
91 SetState(CONNECTING); 76 SetState(CONNECTING);
92 } 77 }
93 78
94 void XmppSignalStrategy::Disconnect() { 79 void XmppSignalStrategy::Disconnect() {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; 218 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism;
234 if (settings.token_service() == "oauth2") { 219 if (settings.token_service() == "oauth2") {
235 mechanism = "X-OAUTH2"; 220 mechanism = "X-OAUTH2";
236 } 221 }
237 222
238 return new notifier::GaiaTokenPreXmppAuth( 223 return new notifier::GaiaTokenPreXmppAuth(
239 jid.Str(), settings.auth_token(), settings.token_service(), mechanism); 224 jid.Str(), settings.auth_token(), settings.token_service(), mechanism);
240 } 225 }
241 226
242 } // namespace remoting 227 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/jingle_glue/xmpp_signal_strategy.h ('k') | remoting/jingle_glue/xmpp_socket_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698