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..a63d3800754fa37b1685f211bf3c8352656e2bb6 100644 |
| --- a/remoting/host/signaling_connector.cc |
| +++ b/remoting/host/signaling_connector.cc |
| @@ -6,7 +6,10 @@ |
| #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/dns_blackhole_checker.h" |
| #include "remoting/host/url_request_context.h" |
| namespace remoting { |
| @@ -33,9 +36,13 @@ SignalingConnector::OAuthCredentials::OAuthCredentials( |
| SignalingConnector::SignalingConnector( |
| XmppSignalStrategy* signal_strategy, |
| + ChromotingHostContext* context, |
| + DnsBlackholeChecker* dns_blackhole_checker, |
| const base::Closure& auth_failed_callback) |
| : signal_strategy_(signal_strategy), |
| + context_(context), |
| auth_failed_callback_(auth_failed_callback), |
| + dns_blackhole_checker_(dns_blackhole_checker), |
| reconnect_attempts_(0), |
| refreshing_oauth_token_(false) { |
| DCHECK(!auth_failed_callback_.is_null()); |
| @@ -52,11 +59,10 @@ 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())); |
| } |
| void SignalingConnector::OnSignalStrategyStateChange( |
| @@ -85,12 +91,6 @@ bool SignalingConnector::OnSignalStrategyIncomingStanza( |
| return false; |
| } |
| -void SignalingConnector::OnIPAddressChanged() { |
| - DCHECK(CalledOnValidThread()); |
| - LOG(INFO) << "IP address has changed."; |
| - ResetAndTryReconnect(); |
| -} |
| - |
| void SignalingConnector::OnConnectionTypeChanged( |
| net::NetworkChangeNotifier::ConnectionType type) { |
| DCHECK(CalledOnValidThread()); |
| @@ -100,6 +100,12 @@ void SignalingConnector::OnConnectionTypeChanged( |
| } |
| } |
| +void SignalingConnector::OnIPAddressChanged() { |
| + DCHECK(CalledOnValidThread()); |
| + LOG(INFO) << "IP address has changed."; |
| + ResetAndTryReconnect(); |
| +} |
| + |
| void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, |
| const std::string& access_token, |
| int expires_seconds) { |
| @@ -147,7 +153,7 @@ void SignalingConnector::ScheduleTryReconnect() { |
| DCHECK(CalledOnValidThread()); |
| if (timer_.IsRunning() || net::NetworkChangeNotifier::IsOffline()) |
| return; |
| - int delay_s = std::min(1 << (reconnect_attempts_ * 2), |
|
Sergey Ulanov
2012/08/30 18:05:01
Why remove *2 here. Do we still have the problem w
garykac
2012/08/31 18:28:23
Yes. I haven't been able to find any reason why th
Sergey Ulanov
2012/08/31 23:40:16
I actually see the same issue fetching OAuth token
|
| + int delay_s = std::min(1 << reconnect_attempts_, |
| kMaxReconnectDelaySeconds); |
| timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_s), |
| this, &SignalingConnector::TryReconnect); |
| @@ -163,6 +169,28 @@ void SignalingConnector::ResetAndTryReconnect() { |
| void SignalingConnector::TryReconnect() { |
| DCHECK(CalledOnValidThread()); |
| + DCHECK(dns_blackhole_checker_); |
|
Sergey Ulanov
2012/08/30 18:05:01
maybe put this DCHECK in constructor?
garykac
2012/08/31 18:28:23
Done.
|
| + |
| + // This will check if this machine is allowed to access the chromoting |
| + // host talkgadget. |
| + dns_blackhole_checker_->CheckForDnsBlackhole( |
| + base::Bind(&SignalingConnector::OnDnsBlackholeCheckerDone, |
| + base::Unretained(this))); |
| +} |
| + |
| +void SignalingConnector::OnDnsBlackholeCheckerDone(bool allow) { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + // Unable to access the host talkgadget. Don't allow the connection, but |
| + // schedule a reconnect in case this is a transient problem rather than |
| + // an outright block. |
| + if (!allow) { |
| + reconnect_attempts_++; |
| + LOG(INFO) << "Scheduling reconnect. Attempt " << reconnect_attempts_; |
| + ScheduleTryReconnect(); |
| + return; |
| + } |
| + |
| if (signal_strategy_->GetState() == SignalStrategy::DISCONNECTED) { |
| bool need_new_auth_token = oauth_credentials_.get() && |
| (auth_token_expiry_time_.is_null() || |