| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signaling/xmpp_signal_strategy.h" | 5 #include "remoting/signaling/xmpp_signal_strategy.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "net/cert/cert_verifier.h" | 23 #include "net/cert/cert_verifier.h" |
| 24 #include "net/cert/ct_policy_enforcer.h" | 24 #include "net/cert/ct_policy_enforcer.h" |
| 25 #include "net/cert/multi_log_ct_verifier.h" | 25 #include "net/cert/multi_log_ct_verifier.h" |
| 26 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
| 27 #include "net/socket/client_socket_factory.h" | 27 #include "net/socket/client_socket_factory.h" |
| 28 #include "net/socket/client_socket_handle.h" | 28 #include "net/socket/client_socket_handle.h" |
| 29 #include "net/socket/ssl_client_socket.h" | 29 #include "net/socket/ssl_client_socket.h" |
| 30 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
| 31 #include "remoting/base/buffered_socket_writer.h" | 31 #include "remoting/base/buffered_socket_writer.h" |
| 32 #include "remoting/base/logging.h" | 32 #include "remoting/base/logging.h" |
| 33 #include "remoting/signaling/signaling_address.h" |
| 33 #include "remoting/signaling/xmpp_login_handler.h" | 34 #include "remoting/signaling/xmpp_login_handler.h" |
| 34 #include "remoting/signaling/xmpp_stream_parser.h" | 35 #include "remoting/signaling/xmpp_stream_parser.h" |
| 35 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" | 36 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
| 36 | 37 |
| 37 // Use 50 seconds keep-alive interval, in case routers terminate | 38 // Use 50 seconds keep-alive interval, in case routers terminate |
| 38 // connections that are idle for more than a minute. | 39 // connections that are idle for more than a minute. |
| 39 const int kKeepAliveIntervalSeconds = 50; | 40 const int kKeepAliveIntervalSeconds = 50; |
| 40 | 41 |
| 41 const int kReadBufferSize = 4096; | 42 const int kReadBufferSize = 4096; |
| 42 | 43 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 Core( | 61 Core( |
| 61 net::ClientSocketFactory* socket_factory, | 62 net::ClientSocketFactory* socket_factory, |
| 62 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 63 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 63 const XmppServerConfig& xmpp_server_config); | 64 const XmppServerConfig& xmpp_server_config); |
| 64 ~Core() override; | 65 ~Core() override; |
| 65 | 66 |
| 66 void Connect(); | 67 void Connect(); |
| 67 void Disconnect(); | 68 void Disconnect(); |
| 68 State GetState() const; | 69 State GetState() const; |
| 69 Error GetError() const; | 70 Error GetError() const; |
| 70 std::string GetLocalJid() const; | 71 const SignalingAddress& GetLocalAddress() const; |
| 71 void AddListener(Listener* listener); | 72 void AddListener(Listener* listener); |
| 72 void RemoveListener(Listener* listener); | 73 void RemoveListener(Listener* listener); |
| 73 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza); | 74 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza); |
| 74 | 75 |
| 75 void SetAuthInfo(const std::string& username, | 76 void SetAuthInfo(const std::string& username, |
| 76 const std::string& auth_token); | 77 const std::string& auth_token); |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 enum class TlsState { | 80 enum class TlsState { |
| 80 // StartTls() hasn't been called. |socket_| is not encrypted. | 81 // StartTls() hasn't been called. |socket_| is not encrypted. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 129 |
| 129 std::unique_ptr<net::StreamSocket> socket_; | 130 std::unique_ptr<net::StreamSocket> socket_; |
| 130 std::unique_ptr<BufferedSocketWriter> writer_; | 131 std::unique_ptr<BufferedSocketWriter> writer_; |
| 131 scoped_refptr<net::IOBuffer> read_buffer_; | 132 scoped_refptr<net::IOBuffer> read_buffer_; |
| 132 bool read_pending_ = false; | 133 bool read_pending_ = false; |
| 133 | 134 |
| 134 TlsState tls_state_ = TlsState::NOT_REQUESTED; | 135 TlsState tls_state_ = TlsState::NOT_REQUESTED; |
| 135 | 136 |
| 136 std::unique_ptr<XmppLoginHandler> login_handler_; | 137 std::unique_ptr<XmppLoginHandler> login_handler_; |
| 137 std::unique_ptr<XmppStreamParser> stream_parser_; | 138 std::unique_ptr<XmppStreamParser> stream_parser_; |
| 138 std::string jid_; | 139 SignalingAddress local_address_; |
| 139 | 140 |
| 140 Error error_ = OK; | 141 Error error_ = OK; |
| 141 | 142 |
| 142 base::ObserverList<Listener, true> listeners_; | 143 base::ObserverList<Listener, true> listeners_; |
| 143 | 144 |
| 144 base::RepeatingTimer keep_alive_timer_; | 145 base::RepeatingTimer keep_alive_timer_; |
| 145 | 146 |
| 146 base::ThreadChecker thread_checker_; | 147 base::ThreadChecker thread_checker_; |
| 147 | 148 |
| 148 DISALLOW_COPY_AND_ASSIGN(Core); | 149 DISALLOW_COPY_AND_ASSIGN(Core); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } else { | 220 } else { |
| 220 return DISCONNECTED; | 221 return DISCONNECTED; |
| 221 } | 222 } |
| 222 } | 223 } |
| 223 | 224 |
| 224 SignalStrategy::Error XmppSignalStrategy::Core::GetError() const { | 225 SignalStrategy::Error XmppSignalStrategy::Core::GetError() const { |
| 225 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
| 226 return error_; | 227 return error_; |
| 227 } | 228 } |
| 228 | 229 |
| 229 std::string XmppSignalStrategy::Core::GetLocalJid() const { | 230 const SignalingAddress& XmppSignalStrategy::Core::GetLocalAddress() const { |
| 230 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
| 231 return jid_; | 232 return local_address_; |
| 232 } | 233 } |
| 233 | 234 |
| 234 void XmppSignalStrategy::Core::AddListener(Listener* listener) { | 235 void XmppSignalStrategy::Core::AddListener(Listener* listener) { |
| 235 DCHECK(thread_checker_.CalledOnValidThread()); | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 236 listeners_.AddObserver(listener); | 237 listeners_.AddObserver(listener); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void XmppSignalStrategy::Core::RemoveListener(Listener* listener) { | 240 void XmppSignalStrategy::Core::RemoveListener(Listener* listener) { |
| 240 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 241 listeners_.RemoveObserver(listener); | 242 listeners_.RemoveObserver(listener); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 base::Bind(&Core::OnTlsConnected, base::Unretained(this))); | 321 base::Bind(&Core::OnTlsConnected, base::Unretained(this))); |
| 321 if (result != net::ERR_IO_PENDING) | 322 if (result != net::ERR_IO_PENDING) |
| 322 OnTlsConnected(result); | 323 OnTlsConnected(result); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void XmppSignalStrategy::Core::OnHandshakeDone( | 326 void XmppSignalStrategy::Core::OnHandshakeDone( |
| 326 const std::string& jid, | 327 const std::string& jid, |
| 327 std::unique_ptr<XmppStreamParser> parser) { | 328 std::unique_ptr<XmppStreamParser> parser) { |
| 328 DCHECK(thread_checker_.CalledOnValidThread()); | 329 DCHECK(thread_checker_.CalledOnValidThread()); |
| 329 | 330 |
| 330 jid_ = jid; | 331 local_address_ = SignalingAddress(jid); |
| 331 stream_parser_ = std::move(parser); | 332 stream_parser_ = std::move(parser); |
| 332 stream_parser_->SetCallbacks( | 333 stream_parser_->SetCallbacks( |
| 333 base::Bind(&Core::OnStanza, base::Unretained(this)), | 334 base::Bind(&Core::OnStanza, base::Unretained(this)), |
| 334 base::Bind(&Core::OnParserError, base::Unretained(this))); | 335 base::Bind(&Core::OnParserError, base::Unretained(this))); |
| 335 | 336 |
| 336 // Don't need |login_handler_| anymore. | 337 // Don't need |login_handler_| anymore. |
| 337 login_handler_.reset(); | 338 login_handler_.reset(); |
| 338 | 339 |
| 339 for (auto& observer : listeners_) | 340 for (auto& observer : listeners_) |
| 340 observer.OnSignalStrategyStateChange(CONNECTED); | 341 observer.OnSignalStrategyStateChange(CONNECTED); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 } | 526 } |
| 526 | 527 |
| 527 SignalStrategy::State XmppSignalStrategy::GetState() const { | 528 SignalStrategy::State XmppSignalStrategy::GetState() const { |
| 528 return core_->GetState(); | 529 return core_->GetState(); |
| 529 } | 530 } |
| 530 | 531 |
| 531 SignalStrategy::Error XmppSignalStrategy::GetError() const { | 532 SignalStrategy::Error XmppSignalStrategy::GetError() const { |
| 532 return core_->GetError(); | 533 return core_->GetError(); |
| 533 } | 534 } |
| 534 | 535 |
| 535 std::string XmppSignalStrategy::GetLocalJid() const { | 536 const SignalingAddress& XmppSignalStrategy::GetLocalAddress() const { |
| 536 return core_->GetLocalJid(); | 537 return core_->GetLocalAddress(); |
| 537 } | 538 } |
| 538 | 539 |
| 539 void XmppSignalStrategy::AddListener(Listener* listener) { | 540 void XmppSignalStrategy::AddListener(Listener* listener) { |
| 540 core_->AddListener(listener); | 541 core_->AddListener(listener); |
| 541 } | 542 } |
| 542 | 543 |
| 543 void XmppSignalStrategy::RemoveListener(Listener* listener) { | 544 void XmppSignalStrategy::RemoveListener(Listener* listener) { |
| 544 core_->RemoveListener(listener); | 545 core_->RemoveListener(listener); |
| 545 } | 546 } |
| 546 bool XmppSignalStrategy::SendStanza(std::unique_ptr<buzz::XmlElement> stanza) { | 547 bool XmppSignalStrategy::SendStanza(std::unique_ptr<buzz::XmlElement> stanza) { |
| 547 return core_->SendStanza(std::move(stanza)); | 548 return core_->SendStanza(std::move(stanza)); |
| 548 } | 549 } |
| 549 | 550 |
| 550 std::string XmppSignalStrategy::GetNextId() { | 551 std::string XmppSignalStrategy::GetNextId() { |
| 551 return base::Uint64ToString(base::RandUint64()); | 552 return base::Uint64ToString(base::RandUint64()); |
| 552 } | 553 } |
| 553 | 554 |
| 554 void XmppSignalStrategy::SetAuthInfo(const std::string& username, | 555 void XmppSignalStrategy::SetAuthInfo(const std::string& username, |
| 555 const std::string& auth_token) { | 556 const std::string& auth_token) { |
| 556 core_->SetAuthInfo(username, auth_token); | 557 core_->SetAuthInfo(username, auth_token); |
| 557 } | 558 } |
| 558 | 559 |
| 559 } // namespace remoting | 560 } // namespace remoting |
| OLD | NEW |