diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 00:27:39 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 00:27:39 +0000 |
commit | 17577838ed95c5820579a89b9bf831cc7c016c78 (patch) | |
tree | ea97f35593914b1f3047ad9c7681ca0efd0ca9b0 /remoting/host | |
parent | 31576fd35a7745b9b441560c4422a191f6ada73e (diff) | |
download | chromium_src-17577838ed95c5820579a89b9bf831cc7c016c78.zip chromium_src-17577838ed95c5820579a89b9bf831cc7c016c78.tar.gz chromium_src-17577838ed95c5820579a89b9bf831cc7c016c78.tar.bz2 |
Cleanup XmppSignalStrategy initialization
1. Folded credentials into XmppServerConfig
2. net::ClientSocketFactory is passed from outside of socket factory
3. Various other minor cleanup, particularly in JNI code.
BUG=274652
Review URL: https://chromiumcodereview.appspot.com/23020023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218875 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/plugin/host_script_object.cc | 71 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 29 |
2 files changed, 42 insertions, 58 deletions
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 1c8771d..b766cad 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -16,6 +16,7 @@ #include "base/threading/platform_thread.h" #include "base/values.h" #include "net/base/net_util.h" +#include "net/socket/client_socket_factory.h" #include "remoting/base/auth_token_util.h" #include "remoting/base/auto_thread.h" #include "remoting/base/resources.h" @@ -107,9 +108,7 @@ class HostNPScriptObject::It2MeImpl // Methods called by the script object, from the plugin thread. // Creates It2Me host structures and starts the host. - void Connect(const std::string& uid, - const std::string& auth_token, - const std::string& auth_service); + void Connect(); // Disconnects the host, ready for tear-down. // Also called internally, from the network thread. @@ -135,14 +134,10 @@ class HostNPScriptObject::It2MeImpl bool IsConnected() const; // Called by Connect() to check for policies and start connection process. - void ReadPolicyAndConnect(const std::string& uid, - const std::string& auth_token, - const std::string& auth_service); + void ReadPolicyAndConnect(); // Called by ReadPolicyAndConnect once policies have been read. - void FinishConnect(const std::string& uid, - const std::string& auth_token, - const std::string& auth_service); + void FinishConnect(); // Called when the support host registration completes. void OnReceivedSupportID(bool success, @@ -223,15 +218,11 @@ HostNPScriptObject::It2MeImpl::It2MeImpl( DCHECK(plugin_task_runner_->BelongsToCurrentThread()); } -void HostNPScriptObject::It2MeImpl::Connect( - const std::string& uid, - const std::string& auth_token, - const std::string& auth_service) { +void HostNPScriptObject::It2MeImpl::Connect() { if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { DCHECK(plugin_task_runner_->BelongsToCurrentThread()); host_context_->ui_task_runner()->PostTask( - FROM_HERE, - base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service)); + FROM_HERE, base::Bind(&It2MeImpl::Connect, this)); return; } @@ -248,9 +239,7 @@ void HostNPScriptObject::It2MeImpl::Connect( // Switch to the network thread to start the actual connection. host_context_->network_task_runner()->PostTask( - FROM_HERE, base::Bind( - &It2MeImpl::ReadPolicyAndConnect, this, - uid, auth_token, auth_service)); + FROM_HERE, base::Bind(&It2MeImpl::ReadPolicyAndConnect, this)); } void HostNPScriptObject::It2MeImpl::Disconnect() { @@ -305,10 +294,7 @@ void HostNPScriptObject::It2MeImpl::RequestNatPolicy() { UpdateNatPolicy(nat_traversal_enabled_); } -void HostNPScriptObject::It2MeImpl::ReadPolicyAndConnect( - const std::string& uid, - const std::string& auth_token, - const std::string& auth_service) { +void HostNPScriptObject::It2MeImpl::ReadPolicyAndConnect() { DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); SetState(kStarting); @@ -316,19 +302,15 @@ void HostNPScriptObject::It2MeImpl::ReadPolicyAndConnect( // Only proceed to FinishConnect() if at least one policy update has been // received. if (policy_received_) { - FinishConnect(uid, auth_token, auth_service); + FinishConnect(); } else { // Otherwise, create the policy watcher, and thunk the connect. pending_connect_ = - base::Bind(&It2MeImpl::FinishConnect, this, - uid, auth_token, auth_service); + base::Bind(&It2MeImpl::FinishConnect, this); } } -void HostNPScriptObject::It2MeImpl::FinishConnect( - const std::string& uid, - const std::string& auth_token, - const std::string& auth_service) { +void HostNPScriptObject::It2MeImpl::FinishConnect() { DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); if (state_ != kStarting) { @@ -338,7 +320,8 @@ void HostNPScriptObject::It2MeImpl::FinishConnect( // Check the host domain policy. if (!required_host_domain_.empty() && - !EndsWith(uid, std::string("@") + required_host_domain_, false)) { + !EndsWith(xmpp_server_config_.username, + std::string("@") + required_host_domain_, false)) { SetState(kInvalidDomainError); return; } @@ -349,8 +332,8 @@ void HostNPScriptObject::It2MeImpl::FinishConnect( // Create XMPP connection. scoped_ptr<SignalStrategy> signal_strategy( - new XmppSignalStrategy(host_context_->url_request_context_getter(), - uid, auth_token, auth_service, + new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), + host_context_->url_request_context_getter(), xmpp_server_config_)); // Request registration of the host for support. @@ -405,7 +388,7 @@ void HostNPScriptObject::It2MeImpl::FinishConnect( // Connect signaling and start the host. signal_strategy_->Connect(); - host_->Start(uid); + host_->Start(xmpp_server_config_.username); SetState(kRequestedAccessCode); return; @@ -1015,7 +998,7 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) { return true; } -// string uid, string auth_token +// string username, string auth_token bool HostNPScriptObject::Connect(const NPVariant* args, uint32_t arg_count, NPVariant* result) { @@ -1033,18 +1016,18 @@ bool HostNPScriptObject::Connect(const NPVariant* args, return false; } - std::string uid = StringFromNPVariant(args[0]); - if (uid.empty()) { - SetException("connect: bad uid argument"); + XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_; + + xmpp_config.username = StringFromNPVariant(args[0]); + if (xmpp_config.username.empty()) { + SetException("connect: bad username argument"); return false; } std::string auth_service_with_token = StringFromNPVariant(args[1]); - std::string auth_token; - std::string auth_service; - ParseAuthTokenWithService(auth_service_with_token, &auth_token, - &auth_service); - if (auth_token.empty()) { + ParseAuthTokenWithService(auth_service_with_token, &xmpp_config.auth_token, + &xmpp_config.auth_service); + if (xmpp_config.auth_token.empty()) { SetException("connect: auth_service_with_token argument has empty token"); return false; } @@ -1060,8 +1043,8 @@ bool HostNPScriptObject::Connect(const NPVariant* args, // Create the It2Me host implementation and start connecting. it2me_impl_ = new It2MeImpl( host_context.Pass(), plugin_task_runner_, weak_ptr_, - xmpp_server_config_, directory_bot_jid_); - it2me_impl_->Connect(uid, auth_token, auth_service); + xmpp_config, directory_bot_jid_); + it2me_impl_->Connect(); return true; } diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index e4feca4..9ed3383 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -29,6 +29,7 @@ #include "ipc/ipc_listener.h" #include "media/base/media.h" #include "net/base/network_change_notifier.h" +#include "net/socket/client_socket_factory.h" #include "net/socket/ssl_server_socket.h" #include "net/url_request/url_fetcher.h" #include "remoting/base/auto_thread_task_runner.h" @@ -267,10 +268,7 @@ class HostProcess std::string oauth_refresh_token_; std::string serialized_config_; std::string host_owner_; - std::string xmpp_login_; bool use_service_account_; - std::string xmpp_auth_token_; - std::string xmpp_auth_service_; scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; bool allow_nat_traversal_; std::string talkgadget_prefix_; @@ -714,8 +712,9 @@ bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) { } // Use an XMPP connection to the Talk network for session signalling. - if (!config->GetString(kXmppLoginConfigPath, &xmpp_login_) || - !(config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || + if (!config->GetString(kXmppLoginConfigPath, &xmpp_server_config_.username) || + !(config->GetString(kXmppAuthTokenConfigPath, + &xmpp_server_config_.auth_token) || config->GetString(kOAuthRefreshTokenConfigPath, &oauth_refresh_token_))) { LOG(ERROR) << "XMPP credentials are not defined in the config."; @@ -723,14 +722,15 @@ bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) { } if (!oauth_refresh_token_.empty()) { - xmpp_auth_token_ = ""; // This will be set to the access token later. - xmpp_auth_service_ = "oauth2"; + // SignalingConnector is responsible for getting OAuth token. + xmpp_server_config_.auth_token = ""; + xmpp_server_config_.auth_service = "oauth2"; } else if (!config->GetString(kXmppAuthServiceConfigPath, - &xmpp_auth_service_)) { + &xmpp_server_config_.auth_service)) { // For the me2me host, we default to ClientLogin token for chromiumsync // because earlier versions of the host had no HTTP stack with which to // request an OAuth2 access token. - xmpp_auth_service_ = kChromotingTokenDefaultServiceName; + xmpp_server_config_.auth_service = kChromotingTokenDefaultServiceName; } if (config->GetString(kHostOwnerConfigPath, &host_owner_)) { @@ -738,7 +738,7 @@ bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) { use_service_account_ = true; } else { // User credential configs only have an xmpp_login, which is also the owner. - host_owner_ = xmpp_login_; + host_owner_ = xmpp_server_config_.username; use_service_account_ = false; } return true; @@ -966,9 +966,9 @@ void HostProcess::StartHost() { state_ = HOST_STARTED; signal_strategy_.reset( - new XmppSignalStrategy(context_->url_request_context_getter(), - xmpp_login_, xmpp_auth_token_, - xmpp_auth_service_, xmpp_server_config_)); + new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), + context_->url_request_context_getter(), + xmpp_server_config_)); scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( new DnsBlackholeChecker(context_->url_request_context_getter(), @@ -986,7 +986,8 @@ void HostProcess::StartHost() { if (!oauth_refresh_token_.empty()) { scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials( new SignalingConnector::OAuthCredentials( - xmpp_login_, oauth_refresh_token_, use_service_account_)); + xmpp_server_config_.username, oauth_refresh_token_, + use_service_account_)); signaling_connector_->EnableOAuth(oauth_credentials.Pass()); } |