diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-22 20:07:51 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-22 20:07:51 +0000 |
commit | 1eb35c3e087bd291fc9d10a6a9e2f3172998f23d (patch) | |
tree | 576da9a1a123c934394f9f33483b1e41d1c6453e /jingle | |
parent | 80d1a8c2443c3dc71de5f94f4ca5e7f3a9f6b052 (diff) | |
download | chromium_src-1eb35c3e087bd291fc9d10a6a9e2f3172998f23d.zip chromium_src-1eb35c3e087bd291fc9d10a6a9e2f3172998f23d.tar.gz chromium_src-1eb35c3e087bd291fc9d10a6a9e2f3172998f23d.tar.bz2 |
[Jingle] Refactored some notifier-related structs/classes
Moved ServerInformation into its own header and added ServerList typedef.
Added notifier_options_util.{h,cc}.
BUG=None
Review URL: http://codereview.chromium.org/6708076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
23 files changed, 249 insertions, 209 deletions
diff --git a/jingle/jingle.gyp b/jingle/jingle.gyp index 06e27f9..7077884 100644 --- a/jingle/jingle.gyp +++ b/jingle/jingle.gyp @@ -17,12 +17,19 @@ 'sources': [ 'notifier/base/chrome_async_socket.cc', 'notifier/base/chrome_async_socket.h', + 'notifier/base/const_communicator.h', 'notifier/base/fake_ssl_client_socket.cc', 'notifier/base/fake_ssl_client_socket.h', + 'notifier/base/gaia_token_pre_xmpp_auth.cc', + 'notifier/base/gaia_token_pre_xmpp_auth.h', 'notifier/base/notification_method.h', 'notifier/base/notification_method.cc', 'notifier/base/notifier_options.cc', 'notifier/base/notifier_options.h', + 'notifier/base/notifier_options_util.cc', + 'notifier/base/notifier_options_util.h', + 'notifier/base/server_information.cc', + 'notifier/base/server_information.h', 'notifier/base/task_pump.cc', 'notifier/base/task_pump.h', 'notifier/base/weak_xmpp_client.cc', @@ -35,9 +42,6 @@ 'notifier/communicator/connection_options.h', 'notifier/communicator/connection_settings.cc', 'notifier/communicator/connection_settings.h', - 'notifier/communicator/const_communicator.h', - 'notifier/communicator/gaia_token_pre_xmpp_auth.cc', - 'notifier/communicator/gaia_token_pre_xmpp_auth.h', 'notifier/communicator/login.cc', 'notifier/communicator/login.h', 'notifier/communicator/login_settings.cc', diff --git a/jingle/notifier/base/const_communicator.h b/jingle/notifier/base/const_communicator.h new file mode 100644 index 0000000..05f5f70c --- /dev/null +++ b/jingle/notifier/base/const_communicator.h @@ -0,0 +1,13 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef JINGLE_NOTIFIER_BASE_CONST_BASE_H_ +#define JINGLE_NOTIFIER_BASE_CONST_BASE_H_ + +namespace notifier { +// The default port for jabber/xmpp communications. +const int kDefaultXmppPort = 5222; +} // namespace notifier + +#endif // JINGLE_NOTIFIER_BASE_CONST_BASE_H_ diff --git a/jingle/notifier/communicator/gaia_token_pre_xmpp_auth.cc b/jingle/notifier/base/gaia_token_pre_xmpp_auth.cc index eb42e6a..907ed5c 100644 --- a/jingle/notifier/communicator/gaia_token_pre_xmpp_auth.cc +++ b/jingle/notifier/base/gaia_token_pre_xmpp_auth.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" +#include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" #include <algorithm> diff --git a/jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h b/jingle/notifier/base/gaia_token_pre_xmpp_auth.h index 9f7f035..0d7987d 100644 --- a/jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h +++ b/jingle/notifier/base/gaia_token_pre_xmpp_auth.h @@ -1,9 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef JINGLE_NOTIFIER_COMMUNICATOR_GAIA_TOKEN_PRE_XMPP_AUTH_H_ -#define JINGLE_NOTIFIER_COMMUNICATOR_GAIA_TOKEN_PRE_XMPP_AUTH_H_ +#ifndef JINGLE_NOTIFIER_BASE_GAIA_TOKEN_PRE_XMPP_AUTH_H_ +#define JINGLE_NOTIFIER_BASE_GAIA_TOKEN_PRE_XMPP_AUTH_H_ #include <string> #include <vector> @@ -62,4 +62,4 @@ class GaiaTokenPreXmppAuth : public buzz::PreXmppAuth { } // namespace notifier -#endif // JINGLE_NOTIFIER_COMMUNICATOR_GAIA_TOKEN_PRE_XMPP_AUTH_H_ +#endif // JINGLE_NOTIFIER_BASE_GAIA_TOKEN_PRE_XMPP_AUTH_H_ diff --git a/jingle/notifier/base/notifier_options.cc b/jingle/notifier/base/notifier_options.cc index 6191af1..2b4b56a 100644 --- a/jingle/notifier/base/notifier_options.cc +++ b/jingle/notifier/base/notifier_options.cc @@ -4,8 +4,7 @@ #include "jingle/notifier/base/notifier_options.h" -// TODO(akalin): Fix the cross-directory dependency. -#include "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" +#include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" namespace notifier { diff --git a/jingle/notifier/base/notifier_options_util.cc b/jingle/notifier/base/notifier_options_util.cc new file mode 100644 index 0000000..24fdad0 --- /dev/null +++ b/jingle/notifier/base/notifier_options_util.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "jingle/notifier/base/notifier_options_util.h" + +#include "base/logging.h" +#include "jingle/notifier/base/const_communicator.h" +#include "jingle/notifier/base/notifier_options.h" +#include "talk/xmpp/jid.h" + +namespace notifier { + +buzz::XmppClientSettings MakeXmppClientSettings( + const NotifierOptions& notifier_options, + const std::string& email, const std::string& token, + const std::string& token_service) { + buzz::Jid jid = buzz::Jid(email); + DCHECK(!jid.node().empty()); + DCHECK(jid.IsValid()); + + buzz::XmppClientSettings xmpp_client_settings; + xmpp_client_settings.set_user(jid.node()); + xmpp_client_settings.set_resource("chrome-sync"); + xmpp_client_settings.set_host(jid.domain()); + xmpp_client_settings.set_use_tls(true); + xmpp_client_settings.set_auth_cookie( + notifier_options.invalidate_xmpp_login ? + token + "bogus" : token); + xmpp_client_settings.set_token_service(token_service); + if (notifier_options.allow_insecure_connection) { + xmpp_client_settings.set_allow_plain(true); + xmpp_client_settings.set_use_tls(false); + } + return xmpp_client_settings; +} + +ServerList GetServerList( + const NotifierOptions& notifier_options) { + ServerList servers; + // Override the default servers with a test notification server if one was + // provided. + if (!notifier_options.xmpp_host_port.host().empty()) { + servers.push_back( + ServerInformation(notifier_options.xmpp_host_port, false)); + } else { + // The default servers know how to serve over port 443 (that's the magic). + servers.push_back( + ServerInformation( + net::HostPortPair("talk.google.com", + notifier::kDefaultXmppPort), + true)); + servers.push_back( + ServerInformation( + net::HostPortPair("talkx.l.google.com", + notifier::kDefaultXmppPort), + true)); + } + return servers; +} + +} // namespace notifier diff --git a/jingle/notifier/base/notifier_options_util.h b/jingle/notifier/base/notifier_options_util.h new file mode 100644 index 0000000..4278329 --- /dev/null +++ b/jingle/notifier/base/notifier_options_util.h @@ -0,0 +1,29 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Utility functions for NotifierOptions. + +#ifndef JINGLE_NOTIFIER_BASE_NOTIFIER_OPTIONS_UTIL_H_ +#define JINGLE_NOTIFIER_BASE_NOTIFIER_OPTIONS_UTIL_H_ + +#include <string> +#include <vector> + +#include "jingle/notifier/base/server_information.h" +#include "talk/xmpp/xmppclientsettings.h" + +namespace notifier { + +struct NotifierOptions; + +buzz::XmppClientSettings MakeXmppClientSettings( + const NotifierOptions& notifier_options, + const std::string& email, const std::string& token, + const std::string& token_service); + +ServerList GetServerList(const NotifierOptions& notifier_options); + +} // namespace notifier + +#endif // JINGLE_NOTIFIER_BASE_NOTIFIER_OPTIONS_UTIL_H_ diff --git a/jingle/notifier/base/server_information.cc b/jingle/notifier/base/server_information.cc new file mode 100644 index 0000000..ba66507 --- /dev/null +++ b/jingle/notifier/base/server_information.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "jingle/notifier/base/server_information.h" + +namespace notifier { + +ServerInformation::ServerInformation( + const net::HostPortPair& server, bool special_port_magic) + : server(server), special_port_magic(special_port_magic) {} + +ServerInformation::ServerInformation() : special_port_magic(false) {} + +} // namespace notifier diff --git a/jingle/notifier/base/server_information.h b/jingle/notifier/base/server_information.h new file mode 100644 index 0000000..c42b69e --- /dev/null +++ b/jingle/notifier/base/server_information.h @@ -0,0 +1,29 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// A utility struct for storing the information for an XMPP server. + +#ifndef JINGLE_NOTIFIER_BASE_SERVER_INFORMATION_H_ +#define JINGLE_NOTIFIER_BASE_SERVER_INFORMATION_H_ + +#include <vector> + +#include "net/base/host_port_pair.h" + +namespace notifier { + +struct ServerInformation { + ServerInformation(const net::HostPortPair& server, + bool special_port_magic); + ServerInformation(); + + net::HostPortPair server; + bool special_port_magic; +}; + +typedef std::vector<ServerInformation> ServerList; + +} // namespace notifier + +#endif // JINGLE_NOTIFIER_BASE_SERVER_INFORMATION_H_ diff --git a/jingle/notifier/communicator/const_communicator.h b/jingle/notifier/communicator/const_communicator.h deleted file mode 100644 index 5f49a62..0000000 --- a/jingle/notifier/communicator/const_communicator.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef JINGLE_NOTIFIER_COMMUNICATOR_CONST_COMMUNICATOR_H_ -#define JINGLE_NOTIFIER_COMMUNICATOR_CONST_COMMUNICATOR_H_ - -namespace notifier { -// The default port for jabber/xmpp communications. -const int kDefaultXmppPort = 5222; -} // namespace notifier - -#endif // JINGLE_NOTIFIER_COMMUNICATOR_CONST_COMMUNICATOR_H_ diff --git a/jingle/notifier/communicator/login.cc b/jingle/notifier/communicator/login.cc index 98d644b..3e21db7 100644 --- a/jingle/notifier/communicator/login.cc +++ b/jingle/notifier/communicator/login.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,8 +35,7 @@ Login::Login(Delegate* delegate, const ConnectionOptions& options, net::HostResolver* host_resolver, net::CertVerifier* cert_verifier, - ServerInformation* server_list, - int server_count, + const ServerList& servers, bool try_ssltcp_first, const std::string& auth_mechanism) : delegate_(delegate), @@ -44,8 +43,7 @@ Login::Login(Delegate* delegate, options, host_resolver, cert_verifier, - server_list, - server_count, + servers, try_ssltcp_first, auth_mechanism)), redirect_port_(0) { diff --git a/jingle/notifier/communicator/login.h b/jingle/notifier/communicator/login.h index 7652bf1..0e5b11b 100644 --- a/jingle/notifier/communicator/login.h +++ b/jingle/notifier/communicator/login.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "base/time.h" #include "base/timer.h" #include "base/weak_ptr.h" +#include "jingle/notifier/base/server_information.h" #include "jingle/notifier/communicator/single_login_attempt.h" #include "net/base/network_change_notifier.h" #include "talk/xmpp/xmppengine.h" @@ -35,7 +36,6 @@ namespace notifier { class ConnectionOptions; class LoginSettings; -struct ServerInformation; // Workaround for MSVS 2005 bug that fails to handle inheritance from a nested // class properly if it comes directly on a base class list. @@ -62,8 +62,7 @@ class Login : public net::NetworkChangeNotifier::IPAddressObserver, const ConnectionOptions& options, net::HostResolver* host_resolver, net::CertVerifier* cert_verifier, - ServerInformation* server_list, - int server_count, + const ServerList& servers, bool try_ssltcp_first, const std::string& auth_mechanism); virtual ~Login(); diff --git a/jingle/notifier/communicator/login_settings.cc b/jingle/notifier/communicator/login_settings.cc index 6345810..6ed3a8c 100644 --- a/jingle/notifier/communicator/login_settings.cc +++ b/jingle/notifier/communicator/login_settings.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "jingle/notifier/communicator/login_settings.h" #include "base/logging.h" +#include "jingle/notifier/base/server_information.h" #include "jingle/notifier/communicator/connection_options.h" #include "jingle/notifier/communicator/xmpp_connection_generator.h" #include "net/base/cert_verifier.h" @@ -20,26 +21,19 @@ LoginSettings::LoginSettings(const buzz::XmppClientSettings& user_settings, const ConnectionOptions& options, net::HostResolver* host_resolver, net::CertVerifier* cert_verifier, - ServerInformation* server_list, - int server_count, + const ServerList& servers, bool try_ssltcp_first, const std::string& auth_mechanism) : try_ssltcp_first_(try_ssltcp_first), host_resolver_(host_resolver), cert_verifier_(cert_verifier), - server_list_(new ServerInformation[server_count]), - server_count_(server_count), + servers_(servers), user_settings_(new buzz::XmppClientSettings(user_settings)), connection_options_(new ConnectionOptions(options)), auth_mechanism_(auth_mechanism) { - // Note: firewall may be NULL. - DCHECK(server_list); DCHECK(host_resolver); DCHECK(cert_verifier); - DCHECK_GT(server_count, 0); - for (int i = 0; i < server_count_; ++i) { - server_list_[i] = server_list[i]; - } + DCHECK_GT(servers_.size(), 0u); } // Defined so that the destructors are executed here (and the corresponding @@ -49,9 +43,8 @@ LoginSettings::~LoginSettings() { void LoginSettings::set_server_override( const net::HostPortPair& server) { - server_override_.reset(new ServerInformation()); - server_override_->server = server; - server_override_->special_port_magic = server_list_[0].special_port_magic; + server_override_.reset( + new ServerInformation(server, servers_[0].special_port_magic)); } void LoginSettings::clear_server_override() { diff --git a/jingle/notifier/communicator/login_settings.h b/jingle/notifier/communicator/login_settings.h index 812022b..5bc8160 100644 --- a/jingle/notifier/communicator/login_settings.h +++ b/jingle/notifier/communicator/login_settings.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,8 +6,8 @@ #define JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_SETTINGS_H_ #include <string> +#include "jingle/notifier/base/server_information.h" #include "jingle/notifier/communicator/xmpp_connection_generator.h" -#include "talk/base/scoped_ptr.h" namespace buzz { class XmppClientSettings; @@ -25,7 +25,6 @@ class SocketAddress; namespace notifier { class ConnectionOptions; -struct ServerInformation; class LoginSettings { public: @@ -33,8 +32,7 @@ class LoginSettings { const ConnectionOptions& options, net::HostResolver* host_resolver, net::CertVerifier* cert_verifier, - ServerInformation* server_list, - int server_count, + const ServerList& servers, bool try_ssltcp_first, const std::string& auth_mechanism); @@ -52,12 +50,9 @@ class LoginSettings { return cert_verifier_; } - const ServerInformation* server_list() const { - return server_override_.get() ? server_override_.get() : server_list_.get(); - } - - int server_count() const { - return server_override_.get() ? 1 : server_count_; + ServerList servers() const { + return + server_override_.get() ? ServerList(1, *server_override_) : servers_; } const buzz::XmppClientSettings& user_settings() const { @@ -84,8 +79,7 @@ class LoginSettings { net::HostResolver* const host_resolver_; net::CertVerifier* const cert_verifier_; - talk_base::scoped_array<ServerInformation> server_list_; - int server_count_; + const ServerList servers_; // Used to handle redirects scoped_ptr<ServerInformation> server_override_; diff --git a/jingle/notifier/communicator/single_login_attempt.cc b/jingle/notifier/communicator/single_login_attempt.cc index 5bfe6e3..2cf99d3 100644 --- a/jingle/notifier/communicator/single_login_attempt.cc +++ b/jingle/notifier/communicator/single_login_attempt.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,10 +11,10 @@ #include "base/compiler_specific.h" #include "base/logging.h" +#include "jingle/notifier/base/const_communicator.h" +#include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" #include "jingle/notifier/communicator/connection_options.h" #include "jingle/notifier/communicator/connection_settings.h" -#include "jingle/notifier/communicator/const_communicator.h" -#include "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" #include "jingle/notifier/communicator/login_settings.h" #include "jingle/notifier/listener/xml_element_util.h" #include "talk/xmllite/xmlelement.h" @@ -37,8 +37,7 @@ SingleLoginAttempt::SingleLoginAttempt(LoginSettings* login_settings, login_settings_->host_resolver(), &login_settings_->connection_options(), login_settings_->try_ssltcp_first(), - login_settings_->server_list(), - login_settings_->server_count()) { + login_settings_->servers()) { connection_generator_.StartGenerating(); } diff --git a/jingle/notifier/communicator/xmpp_connection_generator.cc b/jingle/notifier/communicator/xmpp_connection_generator.cc index c1ca8d2..77282e7 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator.cc +++ b/jingle/notifier/communicator/xmpp_connection_generator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -23,6 +23,7 @@ #include "base/callback.h" #include "base/compiler_specific.h" #include "base/logging.h" +#include "jingle/notifier/base/server_information.h" #include "jingle/notifier/communicator/connection_options.h" #include "jingle/notifier/communicator/connection_settings.h" #include "net/base/net_errors.h" @@ -41,8 +42,7 @@ XmppConnectionGenerator::XmppConnectionGenerator( net::HostResolver* host_resolver, const ConnectionOptions* options, bool try_ssltcp_first, - const ServerInformation* server_list, - int server_count) + const ServerList& servers) : delegate_(delegate), host_resolver_(host_resolver), resolve_callback_( @@ -51,9 +51,8 @@ XmppConnectionGenerator::XmppConnectionGenerator( &XmppConnectionGenerator::OnServerDNSResolved))), settings_list_(new ConnectionSettingsList()), settings_index_(0), - server_list_(new ServerInformation[server_count]), - server_count_(server_count), - server_index_(-1), + servers_(servers), + current_server_(servers_.end()), try_ssltcp_first_(try_ssltcp_first), successfully_resolved_dns_(false), first_dns_error_(0), @@ -61,10 +60,7 @@ XmppConnectionGenerator::XmppConnectionGenerator( DCHECK(delegate_); DCHECK(host_resolver); DCHECK(options_); - DCHECK_GT(server_count_, 0); - for (int i = 0; i < server_count_; ++i) { - server_list_[i] = server_list[i]; - } + DCHECK_GT(servers_.size(), 0u); } XmppConnectionGenerator::~XmppConnectionGenerator() { @@ -109,8 +105,12 @@ void XmppConnectionGenerator::UseNextConnection() { } // Iterate to the next possible server. - server_index_++; - if (server_index_ >= server_count_) { + if (current_server_ == servers_.end()) { + current_server_ = servers_.begin(); + } else { + ++current_server_; + } + if (current_server_ == servers_.end()) { // All out of possibilities. VLOG(1) << "(" << buzz::XmppEngine::ERROR_SOCKET << ", " << first_dns_error_ << ")"; @@ -120,8 +120,7 @@ void XmppConnectionGenerator::UseNextConnection() { } // Resolve the server. - const net::HostPortPair& server = - server_list_[server_index_].server; + const net::HostPortPair& server = current_server_->server; net::HostResolver::RequestInfo request_info(server); int status = host_resolver_.Resolve( @@ -146,7 +145,7 @@ void XmppConnectionGenerator::HandleServerDNSResolved(int status) { DCHECK_NE(status, net::ERR_IO_PENDING); VLOG(1) << "XmppConnectionGenerator::HandleServerDNSResolved"; // Print logging info. - VLOG(1) << " server: " << server_list_[server_index_].server.ToString() + VLOG(1) << " server: " << current_server_->server.ToString() << ", error: " << status; if (status != net::OK) { if (first_dns_error_ == 0) @@ -175,10 +174,10 @@ void XmppConnectionGenerator::HandleServerDNSResolved(int status) { settings_index_ = -1; settings_list_->ClearPermutations(); settings_list_->AddPermutations( - server_list_[server_index_].server.host(), + current_server_->server.host(), ip_list, - server_list_[server_index_].server.port(), - server_list_[server_index_].special_port_magic, + current_server_->server.port(), + current_server_->special_port_magic, try_ssltcp_first_); } diff --git a/jingle/notifier/communicator/xmpp_connection_generator.h b/jingle/notifier/communicator/xmpp_connection_generator.h index 0c3085c..176bd4f 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator.h +++ b/jingle/notifier/communicator/xmpp_connection_generator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,13 +7,12 @@ #include <vector> -#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" -#include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" #include "net/base/net_log.h" -#include "talk/base/scoped_ptr.h" +#include "jingle/notifier/base/server_information.h" namespace talk_base { struct ProxyInfo; @@ -26,11 +25,6 @@ class ConnectionOptions; class ConnectionSettings; class ConnectionSettingsList; -struct ServerInformation { - net::HostPortPair server; - bool special_port_magic; -}; - // Resolves dns names and iterates through the various ip address and transport // combinations. class XmppConnectionGenerator { @@ -54,8 +48,7 @@ class XmppConnectionGenerator { net::HostResolver* host_resolver, const ConnectionOptions* options, bool try_ssltcp_first, - const ServerInformation* server_list, - int server_count); + const ServerList& servers); ~XmppConnectionGenerator(); // Only call this once. Create a new XmppConnectionGenerator and delete the @@ -73,11 +66,10 @@ class XmppConnectionGenerator { scoped_ptr<net::CompletionCallback> resolve_callback_; net::AddressList address_list_; net::BoundNetLog bound_net_log_; - talk_base::scoped_ptr<ConnectionSettingsList> settings_list_; + scoped_ptr<ConnectionSettingsList> settings_list_; int settings_index_; // The setting that is currently being used. - talk_base::scoped_array<ServerInformation> server_list_; - int server_count_; - int server_index_; // The server that is current being used. + const ServerList servers_; + ServerList::const_iterator current_server_; bool try_ssltcp_first_; // Used when sync tests are run on chromium builders. bool successfully_resolved_dns_; int first_dns_error_; diff --git a/jingle/notifier/communicator/xmpp_connection_generator_unittest.cc b/jingle/notifier/communicator/xmpp_connection_generator_unittest.cc index 70d24a0..daa421f 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator_unittest.cc +++ b/jingle/notifier/communicator/xmpp_connection_generator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -27,9 +27,9 @@ class MockXmppConnectionGeneratorDelegate }; const ServerInformation kXmppServers[] = { - { net::HostPortPair("www.foo.com", 5222), true }, - { net::HostPortPair("www.bar.com", 8080), false }, - { net::HostPortPair("www.baz.com", 80), true }, + ServerInformation(net::HostPortPair("www.foo.com", 5222), true), + ServerInformation(net::HostPortPair("www.bar.com", 8080), false), + ServerInformation(net::HostPortPair("www.baz.com", 80), true), }; class XmppConnectionGeneratorTest : public testing::Test { @@ -40,8 +40,8 @@ class XmppConnectionGeneratorTest : public testing::Test { &mock_host_resolver_, &connection_options_, false /* try_ssltcp_first */, - kXmppServers, - arraysize(kXmppServers)) {} + ServerList(kXmppServers, + kXmppServers + arraysize(kXmppServers))) {} virtual ~XmppConnectionGeneratorTest() {} diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc index 5d0f7b3..556a035 100644 --- a/jingle/notifier/listener/mediator_thread_impl.cc +++ b/jingle/notifier/listener/mediator_thread_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,9 +6,10 @@ #include "base/logging.h" #include "base/message_loop.h" +#include "jingle/notifier/base/const_communicator.h" +#include "jingle/notifier/base/notifier_options_util.h" #include "jingle/notifier/base/task_pump.h" #include "jingle/notifier/communicator/connection_options.h" -#include "jingle/notifier/communicator/const_communicator.h" #include "jingle/notifier/communicator/xmpp_connection_generator.h" #include "jingle/notifier/listener/push_notifications_send_update_task.h" #include "net/base/cert_verifier.h" @@ -138,37 +139,12 @@ void MediatorThreadImpl::DoLogin( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, NULL, NULL)); cert_verifier_.reset(new net::CertVerifier); - - notifier::ServerInformation server_list[2]; - int server_list_count = 0; - - // Override the default servers with a test notification server if one was - // provided. - if (!notifier_options_.xmpp_host_port.host().empty()) { - server_list[0].server = notifier_options_.xmpp_host_port; - server_list[0].special_port_magic = false; - server_list_count = 1; - } else { - // The default servers know how to serve over port 443 (that's the magic). - server_list[0].server = net::HostPortPair("talk.google.com", - notifier::kDefaultXmppPort); - server_list[0].special_port_magic = true; - server_list[1].server = net::HostPortPair("talkx.l.google.com", - notifier::kDefaultXmppPort); - server_list[1].special_port_magic = true; - server_list_count = 2; - } - - // Autodetect proxy is on by default. - notifier::ConnectionOptions options; - login_.reset(new notifier::Login(this, settings, - options, + notifier::ConnectionOptions(), host_resolver_.get(), cert_verifier_.get(), - server_list, - server_list_count, + GetServerList(notifier_options_), notifier_options_.try_ssltcp_first, notifier_options_.auth_mechanism)); login_->StartConnection(); diff --git a/jingle/notifier/listener/talk_mediator.h b/jingle/notifier/listener/talk_mediator.h index 4851df8..7ea23b0 100644 --- a/jingle/notifier/listener/talk_mediator.h +++ b/jingle/notifier/listener/talk_mediator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -42,7 +42,7 @@ class TalkMediator { virtual void SetDelegate(Delegate* delegate) = 0; // The following methods are for authorizaiton of the xmpp client. - virtual bool SetAuthToken(const std::string& email, + virtual void SetAuthToken(const std::string& email, const std::string& token, const std::string& token_service) = 0; virtual bool Login() = 0; diff --git a/jingle/notifier/listener/talk_mediator_impl.cc b/jingle/notifier/listener/talk_mediator_impl.cc index 1bf3d28..fa0fc4fc 100644 --- a/jingle/notifier/listener/talk_mediator_impl.cc +++ b/jingle/notifier/listener/talk_mediator_impl.cc @@ -1,24 +1,20 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "jingle/notifier/listener/talk_mediator_impl.h" #include "base/logging.h" -#include "jingle/notifier/listener/mediator_thread_impl.h" -#include "talk/base/cryptstring.h" -#include "talk/xmpp/xmppclientsettings.h" -#include "talk/xmpp/xmppengine.h" +#include "jingle/notifier/base/notifier_options_util.h" namespace notifier { TalkMediatorImpl::TalkMediatorImpl( - MediatorThread* mediator_thread, bool invalidate_xmpp_auth_token, - bool allow_insecure_connection) + MediatorThread* mediator_thread, + const NotifierOptions& notifier_options) : delegate_(NULL), mediator_thread_(mediator_thread), - invalidate_xmpp_auth_token_(invalidate_xmpp_auth_token), - allow_insecure_connection_(allow_insecure_connection) { + notifier_options_(notifier_options) { DCHECK(non_thread_safe_.CalledOnValidThread()); mediator_thread_->Start(); state_.started = 1; @@ -73,29 +69,13 @@ void TalkMediatorImpl::SetDelegate(TalkMediator::Delegate* delegate) { delegate_ = delegate; } -bool TalkMediatorImpl::SetAuthToken(const std::string& email, +void TalkMediatorImpl::SetAuthToken(const std::string& email, const std::string& token, const std::string& token_service) { DCHECK(non_thread_safe_.CalledOnValidThread()); - // Verify that we can create a JID from the email provided. - buzz::Jid jid = buzz::Jid(email); - if (jid.node().empty() || !jid.IsValid()) { - return false; - } - - // Construct the XmppSettings object for login to buzz. - xmpp_settings_.set_user(jid.node()); - xmpp_settings_.set_resource("chrome-sync"); - xmpp_settings_.set_host(jid.domain()); - xmpp_settings_.set_use_tls(true); - xmpp_settings_.set_auth_cookie(invalidate_xmpp_auth_token_ ? - token + "bogus" : token); - xmpp_settings_.set_token_service(token_service); - if (allow_insecure_connection_) { - xmpp_settings_.set_allow_plain(true); - xmpp_settings_.set_use_tls(false); - } + xmpp_settings_ = + MakeXmppClientSettings(notifier_options_, email, token, token_service); // The auth token got updated and we are already in the logging_in or // logged_in state. Update the token. @@ -104,7 +84,6 @@ bool TalkMediatorImpl::SetAuthToken(const std::string& email, } state_.initialized = 1; - return true; } void TalkMediatorImpl::AddSubscription(const Subscription& subscription) { diff --git a/jingle/notifier/listener/talk_mediator_impl.h b/jingle/notifier/listener/talk_mediator_impl.h index d52541b..a6145e9 100644 --- a/jingle/notifier/listener/talk_mediator_impl.h +++ b/jingle/notifier/listener/talk_mediator_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -15,6 +15,7 @@ #include "base/gtest_prod_util.h" #include "base/scoped_ptr.h" #include "base/threading/non_thread_safe.h" +#include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/listener/mediator_thread.h" #include "jingle/notifier/listener/talk_mediator.h" #include "talk/xmpp/xmppclientsettings.h" @@ -29,15 +30,16 @@ class TalkMediatorImpl // This means that you can store a pointer to mediator_thread separately // and use it until this object is destroyed. TalkMediatorImpl( - MediatorThread* mediator_thread, bool invalidate_xmpp_auth_token, - bool allow_insecure_connection); + MediatorThread* mediator_thread, + const NotifierOptions& notifier_options); virtual ~TalkMediatorImpl(); // TalkMediator implementation. virtual void SetDelegate(TalkMediator::Delegate* delegate); - virtual bool SetAuthToken(const std::string& email, + // |email| must be a valid email address (e.g., foo@bar.com). + virtual void SetAuthToken(const std::string& email, const std::string& token, const std::string& token_service); virtual bool Login(); @@ -86,13 +88,11 @@ class TalkMediatorImpl // The worker thread through which talk events are posted and received. scoped_ptr<MediatorThread> mediator_thread_; - const bool invalidate_xmpp_auth_token_; - const bool allow_insecure_connection_; + const NotifierOptions notifier_options_; SubscriptionList subscriptions_; - FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthTokenWithBadInput); - FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthTokenWithGoodInput); + FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthToken); FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SendNotification); FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, MediatorThreadCallbacks); diff --git a/jingle/notifier/listener/talk_mediator_unittest.cc b/jingle/notifier/listener/talk_mediator_unittest.cc index 2697e89..4cdb884 100644 --- a/jingle/notifier/listener/talk_mediator_unittest.cc +++ b/jingle/notifier/listener/talk_mediator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,11 +40,8 @@ class TalkMediatorImplTest : public testing::Test { TalkMediatorImpl* NewMockedTalkMediator( MockMediatorThread* mock_mediator_thread) { - const bool kInvalidateXmppAuthToken = false; - const bool kAllowInsecureConnection = false; return new TalkMediatorImpl(mock_mediator_thread, - kInvalidateXmppAuthToken, - kAllowInsecureConnection); + NotifierOptions()); } int last_message_; @@ -56,40 +53,20 @@ class TalkMediatorImplTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(TalkMediatorImplTest); }; -TEST_F(TalkMediatorImplTest, SetAuthTokenWithBadInput) { +TEST_F(TalkMediatorImplTest, SetAuthToken) { scoped_ptr<TalkMediatorImpl> talk1( NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_FALSE(talk1->SetAuthToken("@missinguser.com", "", "fake_service")); - EXPECT_FALSE(talk1->state_.initialized); - - scoped_ptr<TalkMediatorImpl> talk2( - NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_FALSE(talk2->SetAuthToken("", "1234567890", "fake_service")); - EXPECT_FALSE(talk2->state_.initialized); - - scoped_ptr<TalkMediatorImpl> talk3( - NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_FALSE(talk3->SetAuthToken("missingdomain", "abcde", "fake_service")); - EXPECT_FALSE(talk3->state_.initialized); -} - -TEST_F(TalkMediatorImplTest, SetAuthTokenWithGoodInput) { - scoped_ptr<TalkMediatorImpl> talk1( - NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token", - "fake_service")); + talk1->SetAuthToken("chromium@gmail.com", "token", "fake_service"); EXPECT_TRUE(talk1->state_.initialized); scoped_ptr<TalkMediatorImpl> talk2( NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_TRUE(talk2->SetAuthToken("chromium@mail.google.com", "token", - "fake_service")); + talk2->SetAuthToken("chromium@mail.google.com", "token", "fake_service"); EXPECT_TRUE(talk2->state_.initialized); scoped_ptr<TalkMediatorImpl> talk3( NewMockedTalkMediator(new MockMediatorThread())); - EXPECT_TRUE(talk3->SetAuthToken("chromium@chromium.org", "token", - "fake_service")); + talk3->SetAuthToken("chromium@mail.google.com", "token", "fake_service"); EXPECT_TRUE(talk3->state_.initialized); } @@ -102,16 +79,14 @@ TEST_F(TalkMediatorImplTest, LoginWiring) { EXPECT_FALSE(talk1->Login()); EXPECT_EQ(0, mock->login_calls); - EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token", - "fake_service")); + talk1->SetAuthToken("chromium@gmail.com", "token", "fake_service"); EXPECT_EQ(0, mock->update_settings_calls); EXPECT_TRUE(talk1->Login()); EXPECT_EQ(1, mock->login_calls); // We call SetAuthToken again to update the settings after an update. - EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token", - "fake_service")); + talk1->SetAuthToken("chromium@gmail.com", "token", "fake_service"); EXPECT_EQ(1, mock->update_settings_calls); // Successive calls to login will fail. One needs to create a new talk @@ -137,8 +112,7 @@ TEST_F(TalkMediatorImplTest, SendNotification) { EXPECT_FALSE(talk1->SendNotification(data)); EXPECT_EQ(0, mock->send_calls); - EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token", - "fake_service")); + talk1->SetAuthToken("chromium@gmail.com", "token", "fake_service"); EXPECT_TRUE(talk1->Login()); talk1->OnConnectionStateChange(true); EXPECT_EQ(1, mock->login_calls); @@ -170,8 +144,7 @@ TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) { talk1->SetDelegate(&mock_delegate); - EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token", - "fake_service")); + talk1->SetAuthToken("chromium@gmail.com", "token", "fake_service"); EXPECT_TRUE(talk1->Login()); EXPECT_EQ(1, mock->login_calls); |