| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/net/network_portal_detector_impl.h" | 5 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Delay before portal detection caused by changes in proxy settings. | 33 // Delay before portal detection caused by changes in proxy settings. |
| 34 const int kProxyChangeDelaySec = 1; | 34 const int kProxyChangeDelaySec = 1; |
| 35 | 35 |
| 36 // Maximum number of reports from captive portal detector about | 36 // Maximum number of reports from captive portal detector about |
| 37 // offline state in a row before notification is sent to observers. | 37 // offline state in a row before notification is sent to observers. |
| 38 const int kMaxOfflineResultsBeforeReport = 3; | 38 const int kMaxOfflineResultsBeforeReport = 3; |
| 39 | 39 |
| 40 // Delay before portal detection attempt after !ONLINE -> !ONLINE |
| 41 // transition. |
| 42 const int kShortInitialDelayBetweenAttemptsMs = 600; |
| 43 |
| 44 // Maximum timeout before portal detection attempts after !ONLINE -> |
| 45 // !ONLINE transition. |
| 46 const int kShortMaximumDelayBetweenAttemptsMs = 2 * 60 * 1000; |
| 47 |
| 48 // Delay before portal detection attempt after !ONLINE -> ONLINE |
| 49 // transition. |
| 50 const int kLongInitialDelayBetweenAttemptsMs = 30 * 1000; |
| 51 |
| 52 // Maximum timeout before portal detection attempts after !ONLINE -> |
| 53 // ONLINE transition. |
| 54 const int kLongMaximumDelayBetweenAttemptsMs = 5 * 60 * 1000; |
| 55 |
| 40 const NetworkState* DefaultNetwork() { | 56 const NetworkState* DefaultNetwork() { |
| 41 return NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 57 return NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
| 42 } | 58 } |
| 43 | 59 |
| 44 bool InSession() { | 60 bool InSession() { |
| 45 return LoginState::IsInitialized() && LoginState::Get()->IsUserLoggedIn(); | 61 return LoginState::IsInitialized() && LoginState::Get()->IsUserLoggedIn(); |
| 46 } | 62 } |
| 47 | 63 |
| 48 void RecordDetectionResult(NetworkPortalDetector::CaptivePortalStatus status) { | 64 void RecordDetectionResult(NetworkPortalDetector::CaptivePortalStatus status) { |
| 49 if (InSession()) { | 65 if (InSession()) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 else | 216 else |
| 201 set_network_portal_detector(new NetworkPortalDetectorImpl(url_context)); | 217 set_network_portal_detector(new NetworkPortalDetectorImpl(url_context)); |
| 202 } | 218 } |
| 203 | 219 |
| 204 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( | 220 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( |
| 205 const scoped_refptr<net::URLRequestContextGetter>& request_context) | 221 const scoped_refptr<net::URLRequestContextGetter>& request_context) |
| 206 : state_(STATE_IDLE), | 222 : state_(STATE_IDLE), |
| 207 test_url_(CaptivePortalDetector::kDefaultURL), | 223 test_url_(CaptivePortalDetector::kDefaultURL), |
| 208 enabled_(false), | 224 enabled_(false), |
| 209 strategy_(PortalDetectorStrategy::CreateById( | 225 strategy_(PortalDetectorStrategy::CreateById( |
| 210 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN)), | 226 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN, this)), |
| 211 last_detection_result_(CAPTIVE_PORTAL_STATUS_UNKNOWN), | 227 last_detection_result_(CAPTIVE_PORTAL_STATUS_UNKNOWN), |
| 212 same_detection_result_count_(0), | 228 same_detection_result_count_(0), |
| 213 no_response_result_count_(0), | 229 no_response_result_count_(0), |
| 214 weak_factory_(this) { | 230 weak_factory_(this) { |
| 215 captive_portal_detector_.reset(new CaptivePortalDetector(request_context)); | 231 captive_portal_detector_.reset(new CaptivePortalDetector(request_context)); |
| 216 strategy_->set_delegate(this); | |
| 217 | 232 |
| 218 registrar_.Add(this, | 233 registrar_.Add(this, |
| 219 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, | 234 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, |
| 220 content::NotificationService::AllSources()); | 235 content::NotificationService::AllSources()); |
| 221 registrar_.Add(this, | 236 registrar_.Add(this, |
| 222 chrome::NOTIFICATION_AUTH_SUPPLIED, | 237 chrome::NOTIFICATION_AUTH_SUPPLIED, |
| 223 content::NotificationService::AllSources()); | 238 content::NotificationService::AllSources()); |
| 224 registrar_.Add(this, | 239 registrar_.Add(this, |
| 225 chrome::NOTIFICATION_AUTH_CANCELLED, | 240 chrome::NOTIFICATION_AUTH_CANCELLED, |
| 226 content::NotificationService::AllSources()); | 241 content::NotificationService::AllSources()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if (!is_idle()) | 317 if (!is_idle()) |
| 303 return false; | 318 return false; |
| 304 StartDetection(); | 319 StartDetection(); |
| 305 return true; | 320 return true; |
| 306 } | 321 } |
| 307 | 322 |
| 308 void NetworkPortalDetectorImpl::SetStrategy( | 323 void NetworkPortalDetectorImpl::SetStrategy( |
| 309 PortalDetectorStrategy::StrategyId id) { | 324 PortalDetectorStrategy::StrategyId id) { |
| 310 if (id == strategy_->Id()) | 325 if (id == strategy_->Id()) |
| 311 return; | 326 return; |
| 312 strategy_.reset(PortalDetectorStrategy::CreateById(id).release()); | 327 strategy_ = PortalDetectorStrategy::CreateById(id, this).Pass(); |
| 313 strategy_->set_delegate(this); | |
| 314 StopDetection(); | 328 StopDetection(); |
| 315 StartDetectionIfIdle(); | 329 StartDetectionIfIdle(); |
| 316 } | 330 } |
| 317 | 331 |
| 318 void NetworkPortalDetectorImpl::DefaultNetworkChanged( | 332 void NetworkPortalDetectorImpl::DefaultNetworkChanged( |
| 319 const NetworkState* default_network) { | 333 const NetworkState* default_network) { |
| 320 DCHECK(CalledOnValidThread()); | 334 DCHECK(CalledOnValidThread()); |
| 321 | 335 |
| 322 if (!default_network) { | 336 if (!default_network) { |
| 323 VLOG(1) << "DefaultNetworkChanged: None."; | 337 VLOG(1) << "DefaultNetworkChanged: None."; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL: | 511 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL: |
| 498 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; | 512 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; |
| 499 break; | 513 break; |
| 500 default: | 514 default: |
| 501 break; | 515 break; |
| 502 } | 516 } |
| 503 | 517 |
| 504 if (last_detection_result_ != state.status) { | 518 if (last_detection_result_ != state.status) { |
| 505 last_detection_result_ = state.status; | 519 last_detection_result_ = state.status; |
| 506 same_detection_result_count_ = 1; | 520 same_detection_result_count_ = 1; |
| 507 strategy_->Reset(); | 521 net::BackoffEntry::Policy policy = strategy_->policy(); |
| 522 if (state.status == CAPTIVE_PORTAL_STATUS_ONLINE) { |
| 523 policy.initial_delay_ms = kLongInitialDelayBetweenAttemptsMs; |
| 524 policy.maximum_backoff_ms = kLongMaximumDelayBetweenAttemptsMs; |
| 525 } else { |
| 526 policy.initial_delay_ms = kShortInitialDelayBetweenAttemptsMs; |
| 527 policy.maximum_backoff_ms = kShortMaximumDelayBetweenAttemptsMs; |
| 528 } |
| 529 strategy_->SetPolicyAndReset(policy); |
| 508 } else { | 530 } else { |
| 509 ++same_detection_result_count_; | 531 ++same_detection_result_count_; |
| 510 } | 532 } |
| 511 strategy_->OnDetectionCompleted(); | 533 strategy_->OnDetectionCompleted(); |
| 512 | 534 |
| 513 if (result == captive_portal::RESULT_NO_RESPONSE) | 535 if (result == captive_portal::RESULT_NO_RESPONSE) |
| 514 ++no_response_result_count_; | 536 ++no_response_result_count_; |
| 515 else | 537 else |
| 516 no_response_result_count_ = 0; | 538 no_response_result_count_ = 0; |
| 517 | 539 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 } | 636 } |
| 615 | 637 |
| 616 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { | 638 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { |
| 617 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; | 639 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; |
| 618 same_detection_result_count_ = 0; | 640 same_detection_result_count_ = 0; |
| 619 no_response_result_count_ = 0; | 641 no_response_result_count_ = 0; |
| 620 strategy_->Reset(); | 642 strategy_->Reset(); |
| 621 } | 643 } |
| 622 | 644 |
| 623 } // namespace chromeos | 645 } // namespace chromeos |
| OLD | NEW |