Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_impl.cc

Issue 419463004: Increased delay before next portal detection attempt in the case of !ONLINE -> ONLINE transition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chromeos/network/portal_detector/network_portal_detector_strategy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
Denis Kuznetsov (DE-MUC) 2014/07/24 11:29:45 Long/Short, use ! instead of ~ for negation.
42 const int kSmallInitialDelayBetweenAttemptsMs = 600;
43
44 // Delay before portal detection attempt after ~ONLINE -> ONLINE
45 // transition.
46 const int kBigInitialDelayBetweenAttemptsMs = 3 * 1000;
47
40 const NetworkState* DefaultNetwork() { 48 const NetworkState* DefaultNetwork() {
41 return NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 49 return NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
42 } 50 }
43 51
44 bool InSession() { 52 bool InSession() {
45 return LoginState::IsInitialized() && LoginState::Get()->IsUserLoggedIn(); 53 return LoginState::IsInitialized() && LoginState::Get()->IsUserLoggedIn();
46 } 54 }
47 55
48 void RecordDetectionResult(NetworkPortalDetector::CaptivePortalStatus status) { 56 void RecordDetectionResult(NetworkPortalDetector::CaptivePortalStatus status) {
49 if (InSession()) { 57 if (InSession()) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 else 208 else
201 set_network_portal_detector(new NetworkPortalDetectorImpl(url_context)); 209 set_network_portal_detector(new NetworkPortalDetectorImpl(url_context));
202 } 210 }
203 211
204 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( 212 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl(
205 const scoped_refptr<net::URLRequestContextGetter>& request_context) 213 const scoped_refptr<net::URLRequestContextGetter>& request_context)
206 : state_(STATE_IDLE), 214 : state_(STATE_IDLE),
207 test_url_(CaptivePortalDetector::kDefaultURL), 215 test_url_(CaptivePortalDetector::kDefaultURL),
208 enabled_(false), 216 enabled_(false),
209 strategy_(PortalDetectorStrategy::CreateById( 217 strategy_(PortalDetectorStrategy::CreateById(
210 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN)), 218 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN, this)),
211 last_detection_result_(CAPTIVE_PORTAL_STATUS_UNKNOWN), 219 last_detection_result_(CAPTIVE_PORTAL_STATUS_UNKNOWN),
212 same_detection_result_count_(0), 220 same_detection_result_count_(0),
213 no_response_result_count_(0), 221 no_response_result_count_(0),
214 weak_factory_(this) { 222 weak_factory_(this) {
215 captive_portal_detector_.reset(new CaptivePortalDetector(request_context)); 223 captive_portal_detector_.reset(new CaptivePortalDetector(request_context));
216 strategy_->set_delegate(this);
217 224
218 registrar_.Add(this, 225 registrar_.Add(this,
219 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, 226 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED,
220 content::NotificationService::AllSources()); 227 content::NotificationService::AllSources());
221 registrar_.Add(this, 228 registrar_.Add(this,
222 chrome::NOTIFICATION_AUTH_SUPPLIED, 229 chrome::NOTIFICATION_AUTH_SUPPLIED,
223 content::NotificationService::AllSources()); 230 content::NotificationService::AllSources());
224 registrar_.Add(this, 231 registrar_.Add(this,
225 chrome::NOTIFICATION_AUTH_CANCELLED, 232 chrome::NOTIFICATION_AUTH_CANCELLED,
226 content::NotificationService::AllSources()); 233 content::NotificationService::AllSources());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (!is_idle()) 309 if (!is_idle())
303 return false; 310 return false;
304 StartDetection(); 311 StartDetection();
305 return true; 312 return true;
306 } 313 }
307 314
308 void NetworkPortalDetectorImpl::SetStrategy( 315 void NetworkPortalDetectorImpl::SetStrategy(
309 PortalDetectorStrategy::StrategyId id) { 316 PortalDetectorStrategy::StrategyId id) {
310 if (id == strategy_->Id()) 317 if (id == strategy_->Id())
311 return; 318 return;
312 strategy_.reset(PortalDetectorStrategy::CreateById(id).release()); 319 strategy_ = PortalDetectorStrategy::CreateById(id, this).Pass();
313 strategy_->set_delegate(this);
314 StopDetection(); 320 StopDetection();
315 StartDetectionIfIdle(); 321 StartDetectionIfIdle();
316 } 322 }
317 323
318 void NetworkPortalDetectorImpl::DefaultNetworkChanged( 324 void NetworkPortalDetectorImpl::DefaultNetworkChanged(
319 const NetworkState* default_network) { 325 const NetworkState* default_network) {
320 DCHECK(CalledOnValidThread()); 326 DCHECK(CalledOnValidThread());
321 327
322 if (!default_network) { 328 if (!default_network) {
323 VLOG(1) << "DefaultNetworkChanged: None."; 329 VLOG(1) << "DefaultNetworkChanged: None.";
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL: 503 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL:
498 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; 504 state.status = CAPTIVE_PORTAL_STATUS_PORTAL;
499 break; 505 break;
500 default: 506 default:
501 break; 507 break;
502 } 508 }
503 509
504 if (last_detection_result_ != state.status) { 510 if (last_detection_result_ != state.status) {
505 last_detection_result_ = state.status; 511 last_detection_result_ = state.status;
506 same_detection_result_count_ = 1; 512 same_detection_result_count_ = 1;
507 strategy_->Reset(); 513 if (state.status == CAPTIVE_PORTAL_STATUS_ONLINE)
514 strategy_->SetInitialDelayAndReset(kBigInitialDelayBetweenAttemptsMs);
515 else
516 strategy_->SetInitialDelayAndReset(kSmallInitialDelayBetweenAttemptsMs);
508 } else { 517 } else {
509 ++same_detection_result_count_; 518 ++same_detection_result_count_;
510 } 519 }
511 strategy_->OnDetectionCompleted(); 520 strategy_->OnDetectionCompleted();
512 521
513 if (result == captive_portal::RESULT_NO_RESPONSE) 522 if (result == captive_portal::RESULT_NO_RESPONSE)
514 ++no_response_result_count_; 523 ++no_response_result_count_;
515 else 524 else
516 no_response_result_count_ = 0; 525 no_response_result_count_ = 0;
517 526
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 623 }
615 624
616 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { 625 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() {
617 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; 626 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN;
618 same_detection_result_count_ = 0; 627 same_detection_result_count_ = 0;
619 no_response_result_count_ = 0; 628 no_response_result_count_ = 0;
620 strategy_->Reset(); 629 strategy_->Reset();
621 } 630 }
622 631
623 } // namespace chromeos 632 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/network/portal_detector/network_portal_detector_strategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698