#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
+#include "components/captive_portal/captive_portal_types.h"
#include "content/public/browser/notification_service.h"
#if defined(OS_MACOSX)
#include "base/win/windows_version.h"
#endif
-namespace captive_portal {
+using captive_portal::CaptivePortalResult;
namespace {
DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL,
// Encountered a captive portal with an HTTPS landing URL.
DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL,
+ // Received a network or HTTP error, or a non-HTTP response with IP address.
+ DETECTION_RESULT_NO_RESPONSE_IP_ADDRESS,
+ // Encountered a captive portal with a non-HTTPS, IP address landing URL.
+ DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_IP_ADDRESS,
+ // Received a network or HTTP error with an HTTPS, IP address landing URL.
+ DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL_IP_ADDRESS,
+ // Encountered a captive portal with an HTTPS, IP address landing URL.
+ DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL_IP_ADDRESS,
DETECTION_RESULT_COUNT
};
// |result_duration| is the time between when a captive portal check first
// returned |result| and when a check returned a different result, or when the
// CaptivePortalService was shut down.
-void RecordRepeatHistograms(Result result,
+void RecordRepeatHistograms(CaptivePortalResult result,
int repeat_count,
base::TimeDelta result_duration) {
// Histogram macros can't be used with variable names, since they cache
// Record number of times the last result was received in a row.
base::HistogramBase* result_repeated_histogram =
base::Histogram::FactoryGet(
- "CaptivePortal.ResultRepeated." +
- CaptivePortalDetector::CaptivePortalResultToString(result),
+ "CaptivePortal.ResultRepeated." + CaptivePortalResultToString(result),
1, // min
100, // max
100, // bucket_count
// Time between first request that returned |result| and now.
base::HistogramBase* result_duration_histogram =
base::Histogram::FactoryTimeGet(
- "CaptivePortal.ResultDuration." +
- CaptivePortalDetector::CaptivePortalResultToString(result),
+ "CaptivePortal.ResultDuration." + CaptivePortalResultToString(result),
base::TimeDelta::FromSeconds(1), // min
base::TimeDelta::FromHours(1), // max
50, // bucket_count
}
int GetHistogramEntryForDetectionResult(
- const CaptivePortalDetector::Results& results) {
+ const captive_portal::CaptivePortalDetector::Results& results) {
bool is_https = results.landing_url.SchemeIs("https");
+ bool is_ip = results.landing_url.HostIsIPAddress();
switch (results.result) {
- case RESULT_INTERNET_CONNECTED:
+ case captive_portal::RESULT_INTERNET_CONNECTED:
return DETECTION_RESULT_INTERNET_CONNECTED;
- case RESULT_NO_RESPONSE:
+ case captive_portal::RESULT_NO_RESPONSE:
+ if (is_ip) {
+ return is_https ?
+ DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL_IP_ADDRESS :
+ DETECTION_RESULT_NO_RESPONSE_IP_ADDRESS;
+ }
return is_https ?
DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL :
DETECTION_RESULT_NO_RESPONSE;
- case RESULT_BEHIND_CAPTIVE_PORTAL:
+ case captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL:
+ if (is_ip) {
+ return is_https ?
+ DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL_IP_ADDRESS :
+ DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_IP_ADDRESS;
+ }
return is_https ?
DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL :
DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL;
}
private:
- virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE {
+ base::TimeTicks ImplGetTimeNow() const override {
return captive_portal_service_->GetCurrentTimeTicks();
}
state_(STATE_IDLE),
captive_portal_detector_(profile->GetRequestContext()),
enabled_(false),
- last_detection_result_(RESULT_INTERNET_CONNECTED),
+ last_detection_result_(captive_portal::RESULT_INTERNET_CONNECTED),
num_checks_with_same_result_(0),
- test_url_(CaptivePortalDetector::kDefaultURL) {
+ test_url_(captive_portal::CaptivePortalDetector::kDefaultURL) {
// The order matters here:
// |resolve_errors_with_web_service_| must be initialized and |backoff_entry_|
// created before the call to UpdateEnabledState.
// Count this as a success, so the backoff entry won't apply exponential
// backoff, but will apply the standard delay.
backoff_entry_->InformOfRequest(true);
- OnResult(RESULT_INTERNET_CONNECTED);
+ OnResult(captive_portal::RESULT_INTERNET_CONNECTED);
return;
}
}
void CaptivePortalService::OnPortalDetectionCompleted(
- const CaptivePortalDetector::Results& results) {
+ const captive_portal::CaptivePortalDetector::Results& results) {
DCHECK(CalledOnValidThread());
DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_);
DCHECK(!TimerRunning());
DCHECK(enabled_);
- Result result = results.result;
+ CaptivePortalResult result = results.result;
const base::TimeDelta& retry_after_delta = results.retry_after_delta;
base::TimeTicks now = GetCurrentTimeTicks();
}
}
-void CaptivePortalService::OnResult(Result result) {
+void CaptivePortalService::OnResult(CaptivePortalResult result) {
DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_);
state_ = STATE_IDLE;
content::Details<Results>(&results));
}
-void CaptivePortalService::ResetBackoffEntry(Result result) {
- if (!enabled_ || result == RESULT_BEHIND_CAPTIVE_PORTAL) {
+void CaptivePortalService::ResetBackoffEntry(CaptivePortalResult result) {
+ if (!enabled_ || result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) {
// Use the shorter time when the captive portal service is not enabled, or
// behind a captive portal.
recheck_policy_.backoff_policy.initial_delay_ms =
bool CaptivePortalService::TimerRunning() const {
return check_captive_portal_timer_.IsRunning();
}
-
-} // namespace captive_portal