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

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

Issue 245113003: Removed dependency on the UI from the NetworkPortalDetector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 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
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 "CaptivePortal.Session.PortalToOnlineTransition"; 149 "CaptivePortal.Session.PortalToOnlineTransition";
150 150
151 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl( 151 NetworkPortalDetectorImpl::NetworkPortalDetectorImpl(
152 const scoped_refptr<net::URLRequestContextGetter>& request_context) 152 const scoped_refptr<net::URLRequestContextGetter>& request_context)
153 : state_(STATE_IDLE), 153 : state_(STATE_IDLE),
154 test_url_(CaptivePortalDetector::kDefaultURL), 154 test_url_(CaptivePortalDetector::kDefaultURL),
155 enabled_(false), 155 enabled_(false),
156 weak_factory_(this), 156 weak_factory_(this),
157 attempt_count_(0), 157 attempt_count_(0),
158 strategy_(PortalDetectorStrategy::CreateById( 158 strategy_(PortalDetectorStrategy::CreateById(
159 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN)), 159 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN)) {
160 error_screen_displayed_(false) {
161 captive_portal_detector_.reset(new CaptivePortalDetector(request_context)); 160 captive_portal_detector_.reset(new CaptivePortalDetector(request_context));
162 strategy_->set_delegate(this); 161 strategy_->set_delegate(this);
163 162
164 registrar_.Add(this, 163 registrar_.Add(this,
165 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED, 164 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED,
166 content::NotificationService::AllSources()); 165 content::NotificationService::AllSources());
167 registrar_.Add(this, 166 registrar_.Add(this,
168 chrome::NOTIFICATION_AUTH_SUPPLIED, 167 chrome::NOTIFICATION_AUTH_SUPPLIED,
169 content::NotificationService::AllSources()); 168 content::NotificationService::AllSources());
170 registrar_.Add(this, 169 registrar_.Add(this,
171 chrome::NOTIFICATION_AUTH_CANCELLED, 170 chrome::NOTIFICATION_AUTH_CANCELLED,
172 content::NotificationService::AllSources()); 171 content::NotificationService::AllSources());
173 registrar_.Add(this,
174 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
175 content::NotificationService::AllSources());
176 172
177 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); 173 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
178 UpdateCurrentStrategy(); 174 StartDetectionIfIdle();
179 } 175 }
180 176
181 NetworkPortalDetectorImpl::~NetworkPortalDetectorImpl() { 177 NetworkPortalDetectorImpl::~NetworkPortalDetectorImpl() {
182 DCHECK(CalledOnValidThread()); 178 DCHECK(CalledOnValidThread());
183 179
184 attempt_task_.Cancel(); 180 attempt_task_.Cancel();
185 attempt_timeout_.Cancel(); 181 attempt_timeout_.Cancel();
186 182
187 captive_portal_detector_->Cancel(); 183 captive_portal_detector_->Cancel();
188 captive_portal_detector_.reset(); 184 captive_portal_detector_.reset();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return it->second; 241 return it->second;
246 } 242 }
247 243
248 bool NetworkPortalDetectorImpl::StartDetectionIfIdle() { 244 bool NetworkPortalDetectorImpl::StartDetectionIfIdle() {
249 if (!is_idle()) 245 if (!is_idle())
250 return false; 246 return false;
251 StartDetection(); 247 StartDetection();
252 return true; 248 return true;
253 } 249 }
254 250
251 void NetworkPortalDetectorImpl::SetStrategy(
252 PortalDetectorStrategy::StrategyId id) {
253 if (id == strategy_->Id())
254 return;
255 strategy_.reset(PortalDetectorStrategy::CreateById(id).release());
256 strategy_->set_delegate(this);
257 StopDetection();
258 StartDetectionIfIdle();
259 }
260
255 void NetworkPortalDetectorImpl::DefaultNetworkChanged( 261 void NetworkPortalDetectorImpl::DefaultNetworkChanged(
256 const NetworkState* default_network) { 262 const NetworkState* default_network) {
257 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
258 264
259 if (!default_network) { 265 if (!default_network) {
260 default_network_name_.clear(); 266 default_network_name_.clear();
261 default_network_id_.clear(); 267 default_network_id_.clear();
262 268
263 StopDetection(); 269 StopDetection();
264 270
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 base::TimeTicks NetworkPortalDetectorImpl::AttemptStartTime() { 306 base::TimeTicks NetworkPortalDetectorImpl::AttemptStartTime() {
301 return attempt_start_time_; 307 return attempt_start_time_;
302 } 308 }
303 309
304 base::TimeTicks NetworkPortalDetectorImpl::GetCurrentTimeTicks() { 310 base::TimeTicks NetworkPortalDetectorImpl::GetCurrentTimeTicks() {
305 if (time_ticks_for_testing_.is_null()) 311 if (time_ticks_for_testing_.is_null())
306 return base::TimeTicks::Now(); 312 return base::TimeTicks::Now();
307 return time_ticks_for_testing_; 313 return time_ticks_for_testing_;
308 } 314 }
309 315
310 void NetworkPortalDetectorImpl::OnErrorScreenShow() {
311 error_screen_displayed_ = true;
312 UpdateCurrentStrategy();
313 }
314
315 void NetworkPortalDetectorImpl::OnErrorScreenHide() {
316 error_screen_displayed_ = false;
317 UpdateCurrentStrategy();
318 }
319 316
320 //////////////////////////////////////////////////////////////////////////////// 317 ////////////////////////////////////////////////////////////////////////////////
321 // NetworkPortalDetectorImpl, private: 318 // NetworkPortalDetectorImpl, private:
322 319
323 void NetworkPortalDetectorImpl::StartDetection() { 320 void NetworkPortalDetectorImpl::StartDetection() {
324 attempt_count_ = 0; 321 attempt_count_ = 0;
325 DCHECK(CanPerformAttempt()); 322 DCHECK(CanPerformAttempt());
326 detection_start_time_ = GetCurrentTimeTicks(); 323 detection_start_time_ = GetCurrentTimeTicks();
327 ScheduleAttempt(base::TimeDelta()); 324 ScheduleAttempt(base::TimeDelta());
328 } 325 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 const content::NotificationDetails& details) { 462 const content::NotificationDetails& details) {
466 if (type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED || 463 if (type == chrome::NOTIFICATION_LOGIN_PROXY_CHANGED ||
467 type == chrome::NOTIFICATION_AUTH_SUPPLIED || 464 type == chrome::NOTIFICATION_AUTH_SUPPLIED ||
468 type == chrome::NOTIFICATION_AUTH_CANCELLED) { 465 type == chrome::NOTIFICATION_AUTH_CANCELLED) {
469 VLOG(1) << "Restarting portal detection due to proxy change."; 466 VLOG(1) << "Restarting portal detection due to proxy change.";
470 attempt_count_ = 0; 467 attempt_count_ = 0;
471 if (is_portal_check_pending()) 468 if (is_portal_check_pending())
472 return; 469 return;
473 StopDetection(); 470 StopDetection();
474 ScheduleAttempt(base::TimeDelta::FromSeconds(kProxyChangeDelaySec)); 471 ScheduleAttempt(base::TimeDelta::FromSeconds(kProxyChangeDelaySec));
475 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) {
476 UpdateCurrentStrategy();
477 } 472 }
478 } 473 }
479 474
480 void NetworkPortalDetectorImpl::OnDetectionCompleted( 475 void NetworkPortalDetectorImpl::OnDetectionCompleted(
481 const NetworkState* network, 476 const NetworkState* network,
482 const CaptivePortalState& state) { 477 const CaptivePortalState& state) {
483 if (!network) { 478 if (!network) {
484 NotifyDetectionCompleted(network, state); 479 NotifyDetectionCompleted(network, state);
485 return; 480 return;
486 } 481 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: 549 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
555 if (network->connection_state() != shill::kStateOnline) 550 if (network->connection_state() != shill::kStateOnline)
556 RecordDiscrepancyWithShill(network, status); 551 RecordDiscrepancyWithShill(network, status);
557 break; 552 break;
558 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: 553 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT:
559 NOTREACHED(); 554 NOTREACHED();
560 break; 555 break;
561 } 556 }
562 } 557 }
563 558
564 void NetworkPortalDetectorImpl::UpdateCurrentStrategy() {
565 if (InSession()) {
566 SetStrategy(PortalDetectorStrategy::STRATEGY_ID_SESSION);
567 return;
568 }
569 if (error_screen_displayed_) {
570 SetStrategy(PortalDetectorStrategy::STRATEGY_ID_ERROR_SCREEN);
571 return;
572 }
573 SetStrategy(PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN);
574 }
575
576 void NetworkPortalDetectorImpl::SetStrategy(
577 PortalDetectorStrategy::StrategyId id) {
578 if (id == strategy_->Id())
579 return;
580 strategy_.reset(PortalDetectorStrategy::CreateById(id).release());
581 strategy_->set_delegate(this);
582 StopDetection();
583 StartDetectionIfIdle();
584 }
585
586 } // namespace chromeos 559 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698