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

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

Issue 873713004: Introduce NetworkState::is_captive_portal() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback, unit test Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/chromeos/login/network_state_informer.cc » ('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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 void RecordDiscrepancyWithShill( 90 void RecordDiscrepancyWithShill(
91 const NetworkState* network, 91 const NetworkState* network,
92 const NetworkPortalDetector::CaptivePortalStatus status) { 92 const NetworkPortalDetector::CaptivePortalStatus status) {
93 if (InSession()) { 93 if (InSession()) {
94 if (network->connection_state() == shill::kStateOnline) { 94 if (network->connection_state() == shill::kStateOnline) {
95 UMA_HISTOGRAM_ENUMERATION( 95 UMA_HISTOGRAM_ENUMERATION(
96 NetworkPortalDetectorImpl::kSessionShillOnlineHistogram, 96 NetworkPortalDetectorImpl::kSessionShillOnlineHistogram,
97 status, 97 status,
98 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 98 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
99 } else if (network->connection_state() == shill::kStatePortal) { 99 } else if (network->is_captive_portal()) {
100 UMA_HISTOGRAM_ENUMERATION( 100 UMA_HISTOGRAM_ENUMERATION(
101 NetworkPortalDetectorImpl::kSessionShillPortalHistogram, 101 NetworkPortalDetectorImpl::kSessionShillPortalHistogram,
102 status, 102 status,
103 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 103 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
104 } else if (network->connection_state() == shill::kStateOffline) { 104 } else if (network->connection_state() == shill::kStateOffline) {
105 UMA_HISTOGRAM_ENUMERATION( 105 UMA_HISTOGRAM_ENUMERATION(
106 NetworkPortalDetectorImpl::kSessionShillOfflineHistogram, 106 NetworkPortalDetectorImpl::kSessionShillOfflineHistogram,
107 status, 107 status,
108 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 108 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
109 } 109 }
110 } else { 110 } else {
111 if (network->connection_state() == shill::kStateOnline) { 111 if (network->connection_state() == shill::kStateOnline) {
112 UMA_HISTOGRAM_ENUMERATION( 112 UMA_HISTOGRAM_ENUMERATION(
113 NetworkPortalDetectorImpl::kOobeShillOnlineHistogram, 113 NetworkPortalDetectorImpl::kOobeShillOnlineHistogram,
114 status, 114 status,
115 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 115 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
116 } else if (network->connection_state() == shill::kStatePortal) { 116 } else if (network->is_captive_portal()) {
117 UMA_HISTOGRAM_ENUMERATION( 117 UMA_HISTOGRAM_ENUMERATION(
118 NetworkPortalDetectorImpl::kOobeShillPortalHistogram, 118 NetworkPortalDetectorImpl::kOobeShillPortalHistogram,
119 status, 119 status,
120 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 120 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
121 } else if (network->connection_state() == shill::kStateOffline) { 121 } else if (network->connection_state() == shill::kStateOffline) {
122 UMA_HISTOGRAM_ENUMERATION( 122 UMA_HISTOGRAM_ENUMERATION(
123 NetworkPortalDetectorImpl::kOobeShillOfflineHistogram, 123 NetworkPortalDetectorImpl::kOobeShillOfflineHistogram,
124 status, 124 status,
125 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT); 125 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT);
126 } 126 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 captive_portal::CaptivePortalResult result = results.result; 474 captive_portal::CaptivePortalResult result = results.result;
475 int response_code = results.response_code; 475 int response_code = results.response_code;
476 476
477 const NetworkState* network = DefaultNetwork(); 477 const NetworkState* network = DefaultNetwork();
478 478
479 // If using a fake profile client, also fake being behind a captive portal 479 // If using a fake profile client, also fake being behind a captive portal
480 // if the default network is in portal state. 480 // if the default network is in portal state.
481 if (result != captive_portal::RESULT_NO_RESPONSE && 481 if (result != captive_portal::RESULT_NO_RESPONSE &&
482 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface() && 482 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface() &&
483 network && network->connection_state() == shill::kStatePortal) { 483 network && network->is_captive_portal()) {
484 result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL; 484 result = captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL;
485 response_code = 200; 485 response_code = 200;
486 } 486 }
487 487
488 DetectionAttemptCompletedReport attempt_completed_report( 488 DetectionAttemptCompletedReport attempt_completed_report(
489 default_network_name_, default_network_id_, result, response_code); 489 default_network_name_, default_network_id_, result, response_code);
490 if (!attempt_completed_report_.Equals(attempt_completed_report)) { 490 if (!attempt_completed_report_.Equals(attempt_completed_report)) {
491 attempt_completed_report_ = attempt_completed_report; 491 attempt_completed_report_ = attempt_completed_report;
492 attempt_completed_report_.Report(); 492 attempt_completed_report_.Report();
493 } 493 }
494 494
495 state_ = STATE_IDLE; 495 state_ = STATE_IDLE;
496 attempt_timeout_.Cancel(); 496 attempt_timeout_.Cancel();
497 497
498 CaptivePortalState state; 498 CaptivePortalState state;
499 state.response_code = response_code; 499 state.response_code = response_code;
500 state.time = GetCurrentTimeTicks(); 500 state.time = GetCurrentTimeTicks();
501 switch (result) { 501 switch (result) {
502 case captive_portal::RESULT_NO_RESPONSE: 502 case captive_portal::RESULT_NO_RESPONSE:
503 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { 503 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) {
504 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; 504 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED;
505 } else if (network && 505 } else if (network && network->is_captive_portal()) {
506 (network->connection_state() == shill::kStatePortal)) {
507 // Take into account shill's detection results. 506 // Take into account shill's detection results.
508 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; 507 state.status = CAPTIVE_PORTAL_STATUS_PORTAL;
509 } else { 508 } else {
510 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE; 509 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE;
511 } 510 }
512 break; 511 break;
513 case captive_portal::RESULT_INTERNET_CONNECTED: 512 case captive_portal::RESULT_INTERNET_CONNECTED:
514 state.status = CAPTIVE_PORTAL_STATUS_ONLINE; 513 state.status = CAPTIVE_PORTAL_STATUS_ONLINE;
515 break; 514 break;
516 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL: 515 case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 610
612 if (!detection_start_time_.is_null()) 611 if (!detection_start_time_.is_null())
613 RecordDetectionDuration(GetCurrentTimeTicks() - detection_start_time_); 612 RecordDetectionDuration(GetCurrentTimeTicks() - detection_start_time_);
614 RecordDetectionResult(status); 613 RecordDetectionResult(status);
615 614
616 switch (status) { 615 switch (status) {
617 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: 616 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN:
618 NOTREACHED(); 617 NOTREACHED();
619 break; 618 break;
620 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: 619 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE:
621 if (network->connection_state() == shill::kStateOnline || 620 if (network->IsConnectedState())
622 network->connection_state() == shill::kStatePortal) {
623 RecordDiscrepancyWithShill(network, status); 621 RecordDiscrepancyWithShill(network, status);
624 }
625 break; 622 break;
626 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: 623 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE:
627 if (network->connection_state() != shill::kStateOnline) 624 if (network->connection_state() != shill::kStateOnline)
628 RecordDiscrepancyWithShill(network, status); 625 RecordDiscrepancyWithShill(network, status);
629 break; 626 break;
630 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: 627 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL:
631 if (network->connection_state() != shill::kStatePortal) 628 if (!network->is_captive_portal())
632 RecordDiscrepancyWithShill(network, status); 629 RecordDiscrepancyWithShill(network, status);
633 break; 630 break;
634 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: 631 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
635 if (network->connection_state() != shill::kStateOnline) 632 if (network->connection_state() != shill::kStateOnline)
636 RecordDiscrepancyWithShill(network, status); 633 RecordDiscrepancyWithShill(network, status);
637 break; 634 break;
638 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: 635 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT:
639 NOTREACHED(); 636 NOTREACHED();
640 break; 637 break;
641 } 638 }
642 } 639 }
643 640
644 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { 641 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() {
645 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; 642 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN;
646 same_detection_result_count_ = 0; 643 same_detection_result_count_ = 0;
647 no_response_result_count_ = 0; 644 no_response_result_count_ = 0;
648 strategy_->Reset(); 645 strategy_->Reset();
649 } 646 }
650 647
651 } // namespace chromeos 648 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/chromeos/login/network_state_informer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698