Chromium Code Reviews| Index: remoting/host/signaling_connector.cc |
| diff --git a/remoting/host/signaling_connector.cc b/remoting/host/signaling_connector.cc |
| index 9e95219a39f1540e52bb31e66cab17985bc7ed01..92295fc15472271e87c4dac286d8c19d9dd677ba 100644 |
| --- a/remoting/host/signaling_connector.cc |
| +++ b/remoting/host/signaling_connector.cc |
| @@ -6,7 +6,9 @@ |
| #include "base/bind.h" |
| #include "base/callback.h" |
| +#include "net/url_request/url_fetcher.h" |
| #include "remoting/host/chromoting_host_context.h" |
| +#include "remoting/host/constants.h" |
| #include "remoting/host/url_request_context.h" |
| namespace remoting { |
| @@ -33,9 +35,14 @@ SignalingConnector::OAuthCredentials::OAuthCredentials( |
| SignalingConnector::SignalingConnector( |
| XmppSignalStrategy* signal_strategy, |
| + ChromotingHostContext* context, |
| + std::string talkgadget_prefix, |
| const base::Closure& auth_failed_callback) |
| : signal_strategy_(signal_strategy), |
| + context_(context), |
| auth_failed_callback_(auth_failed_callback), |
| + talkgadget_prefix_(talkgadget_prefix), |
| + found_talkgadget_(false), |
| reconnect_attempts_(0), |
| refreshing_oauth_token_(false) { |
| DCHECK(!auth_failed_callback_.is_null()); |
| @@ -52,13 +59,13 @@ SignalingConnector::~SignalingConnector() { |
| } |
| void SignalingConnector::EnableOAuth( |
| - scoped_ptr<OAuthCredentials> oauth_credentials, |
| - net::URLRequestContextGetter* url_context) { |
| + scoped_ptr<OAuthCredentials> oauth_credentials) { |
| oauth_credentials_ = oauth_credentials.Pass(); |
| gaia_oauth_client_.reset(new GaiaOAuthClient( |
| - OAuthProviderInfo::GetDefault(), url_context)); |
| + OAuthProviderInfo::GetDefault(), context_->url_request_context_getter())); |
| } |
| +// SignalStrategy::Listener interface. |
| void SignalingConnector::OnSignalStrategyStateChange( |
| SignalStrategy::State state) { |
| DCHECK(CalledOnValidThread()); |
| @@ -85,12 +92,21 @@ bool SignalingConnector::OnSignalStrategyIncomingStanza( |
| return false; |
| } |
| -void SignalingConnector::OnIPAddressChanged() { |
| - DCHECK(CalledOnValidThread()); |
| - LOG(INFO) << "IP address has changed."; |
| - ResetAndTryReconnect(); |
| +// net::URLFetcherDelegate interface. |
|
Sergey Ulanov
2012/08/24 19:43:33
I don't think we need to duplicate this comment fr
garykac
2012/08/27 22:34:57
Done.
|
| +void SignalingConnector::OnURLFetchComplete(const net::URLFetcher* source) { |
| + int response = source->GetResponseCode(); |
| + if (response == 200) { |
| + found_talkgadget_ = true; |
| + url_fetcher_.reset(NULL); |
| + TryReconnect(); |
| + return; |
| + } |
| + LOG(INFO) << "Failed to find talkgadget. Scheduling a reconnect."; |
| + reconnect_attempts_++; |
| + ScheduleTryReconnect(); |
|
Sergey Ulanov
2012/08/24 19:43:33
If we know we are blocked then there isn't point i
garykac
2012/08/27 22:34:57
Not being able to reach the talkgadget could be fo
|
| } |
| +// NetworkChangeNotifier::ConnectionTypeObserver interface. |
| void SignalingConnector::OnConnectionTypeChanged( |
| net::NetworkChangeNotifier::ConnectionType type) { |
| DCHECK(CalledOnValidThread()); |
| @@ -100,6 +116,14 @@ void SignalingConnector::OnConnectionTypeChanged( |
| } |
| } |
| +// NetworkChangeNotifier::IPAddressObserver interface. |
| +void SignalingConnector::OnIPAddressChanged() { |
| + DCHECK(CalledOnValidThread()); |
| + LOG(INFO) << "IP address has changed."; |
| + ResetAndTryReconnect(); |
| +} |
| + |
| +// GaiaOAuthClient::Delegate interface. |
| void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, |
| const std::string& access_token, |
| int expires_seconds) { |
| @@ -163,7 +187,25 @@ void SignalingConnector::ResetAndTryReconnect() { |
| void SignalingConnector::TryReconnect() { |
| DCHECK(CalledOnValidThread()); |
| + |
| + if (!found_talkgadget_) { |
| + std::string talkgadget_url("https://"); |
| + if (talkgadget_prefix_.empty()) { |
| + talkgadget_url += kDefaultHostTalkGadgetPrefix; |
| + } else { |
| + talkgadget_url += talkgadget_prefix_; |
| + } |
| + talkgadget_url += kTalkGadgetURL; |
| + LOG(INFO) << "Verifying connection to " << talkgadget_url; |
| + url_fetcher_.reset(net::URLFetcher::Create(GURL(talkgadget_url), |
| + net::URLFetcher::GET, this)); |
| + url_fetcher_->SetRequestContext(context_->url_request_context_getter()); |
| + url_fetcher_->Start(); |
| + return; |
| + } |
| + |
| if (signal_strategy_->GetState() == SignalStrategy::DISCONNECTED) { |
| + |
| bool need_new_auth_token = oauth_credentials_.get() && |
| (auth_token_expiry_time_.is_null() || |
| base::Time::Now() >= auth_token_expiry_time_); |