OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 5 #include <algorithm> |
6 #include <cstddef> | 6 #include <cstddef> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "jingle/notifier/communicator/single_login_attempt.h" | 10 #include "jingle/notifier/communicator/single_login_attempt.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "talk/xmpp/xmppclient.h" | 21 #include "talk/xmpp/xmppclient.h" |
22 #include "talk/xmpp/xmppclientsettings.h" | 22 #include "talk/xmpp/xmppclientsettings.h" |
23 #include "talk/xmpp/constants.h" | 23 #include "talk/xmpp/constants.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 class NetLog; | 26 class NetLog; |
27 } // namespace net | 27 } // namespace net |
28 | 28 |
29 namespace notifier { | 29 namespace notifier { |
30 | 30 |
31 SingleLoginAttempt::SingleLoginAttempt(LoginSettings* login_settings) | 31 SingleLoginAttempt::SingleLoginAttempt(LoginSettings* login_settings, |
| 32 Delegate* delegate) |
32 : login_settings_(login_settings), | 33 : login_settings_(login_settings), |
| 34 delegate_(delegate), |
33 connection_generator_( | 35 connection_generator_( |
34 ALLOW_THIS_IN_INITIALIZER_LIST(this), | 36 ALLOW_THIS_IN_INITIALIZER_LIST(this), |
35 login_settings_->host_resolver(), | 37 login_settings_->host_resolver(), |
36 &login_settings_->connection_options(), | 38 &login_settings_->connection_options(), |
37 login_settings_->try_ssltcp_first(), | 39 login_settings_->try_ssltcp_first(), |
38 login_settings_->server_list(), | 40 login_settings_->server_list(), |
39 login_settings_->server_count()) { | 41 login_settings_->server_count()) { |
40 connection_generator_.StartGenerating(); | 42 connection_generator_.StartGenerating(); |
41 } | 43 } |
42 | 44 |
43 SingleLoginAttempt::~SingleLoginAttempt() {} | 45 SingleLoginAttempt::~SingleLoginAttempt() {} |
44 | 46 |
45 void SingleLoginAttempt::OnConnect(base::WeakPtr<talk_base::Task> base_task) { | 47 void SingleLoginAttempt::OnConnect(base::WeakPtr<talk_base::Task> base_task) { |
46 SignalConnect(base_task); | 48 delegate_->OnConnect(base_task); |
47 } | 49 } |
48 | 50 |
49 void SingleLoginAttempt::OnError(buzz::XmppEngine::Error error, int subcode, | 51 void SingleLoginAttempt::OnError(buzz::XmppEngine::Error error, int subcode, |
50 const buzz::XmlElement* stream_error) { | 52 const buzz::XmlElement* stream_error) { |
51 VLOG(1) << "Error: " << error << ", subcode: " << subcode; | 53 VLOG(1) << "Error: " << error << ", subcode: " << subcode; |
52 if (stream_error) { | 54 if (stream_error) { |
53 DCHECK_EQ(error, buzz::XmppEngine::ERROR_STREAM); | 55 DCHECK_EQ(error, buzz::XmppEngine::ERROR_STREAM); |
54 VLOG(1) << "Stream error: " << XmlElementToString(*stream_error); | 56 VLOG(1) << "Stream error: " << XmlElementToString(*stream_error); |
55 } | 57 } |
56 | 58 |
(...skipping 17 matching lines...) Expand all Loading... |
74 } else { | 76 } else { |
75 redirect_server = redirect.substr(0, colon); | 77 redirect_server = redirect.substr(0, colon); |
76 const std::string& port_text = redirect.substr(colon + 1); | 78 const std::string& port_text = redirect.substr(colon + 1); |
77 std::istringstream ist(port_text); | 79 std::istringstream ist(port_text); |
78 ist >> redirect_port; | 80 ist >> redirect_port; |
79 } | 81 } |
80 // We never allow a redirect to port 0. | 82 // We never allow a redirect to port 0. |
81 if (redirect_port == 0) { | 83 if (redirect_port == 0) { |
82 redirect_port = kDefaultXmppPort; | 84 redirect_port = kDefaultXmppPort; |
83 } | 85 } |
84 SignalRedirect(redirect_server, redirect_port); | 86 delegate_->OnRedirect(redirect_server, redirect_port); |
85 // May be deleted at this point. | 87 // May be deleted at this point. |
86 return; | 88 return; |
87 } | 89 } |
88 } | 90 } |
89 } | 91 } |
90 | 92 |
91 // Iterate to the next possible connection (still trying to connect). | 93 // Iterate to the next possible connection (still trying to connect). |
92 connection_generator_.UseNextConnection(); | 94 connection_generator_.UseNextConnection(); |
93 } | 95 } |
94 | 96 |
(...skipping 20 matching lines...) Expand all Loading... |
115 xmpp_connection_.reset( | 117 xmpp_connection_.reset( |
116 new XmppConnection(client_settings, this, pre_xmpp_auth)); | 118 new XmppConnection(client_settings, this, pre_xmpp_auth)); |
117 } | 119 } |
118 | 120 |
119 void SingleLoginAttempt::OnExhaustedSettings( | 121 void SingleLoginAttempt::OnExhaustedSettings( |
120 bool successfully_resolved_dns, | 122 bool successfully_resolved_dns, |
121 int first_dns_error) { | 123 int first_dns_error) { |
122 if (!successfully_resolved_dns) | 124 if (!successfully_resolved_dns) |
123 VLOG(1) << "Could not resolve DNS: " << first_dns_error; | 125 VLOG(1) << "Could not resolve DNS: " << first_dns_error; |
124 VLOG(1) << "Could not connect to any XMPP server"; | 126 VLOG(1) << "Could not connect to any XMPP server"; |
125 SignalNeedAutoReconnect(); | 127 delegate_->OnNeedReconnect(); |
126 } | 128 } |
127 | 129 |
128 } // namespace notifier | 130 } // namespace notifier |
OLD | NEW |