OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/captive_portal/captive_portal_service.h" | 5 #include "chrome/browser/captive_portal/captive_portal_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 | 17 |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
19 #include "base/mac/mac_util.h" | 19 #include "base/mac/mac_util.h" |
20 #endif | 20 #endif |
21 | 21 |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace captive_portal { | 26 namespace captive_portal { |
27 | 27 |
28 // Make sure this enum is in sync with CaptivePortalDetectionResult enum | |
29 // in histograms.xml. | |
30 enum CaptivePortalDetectionResult { | |
31 // There's a confirmed connection to the Internet. | |
32 DETECTION_RESULT_INTERNET_CONNECTED, | |
33 // Received a network or HTTP error, or a non-HTTP response. | |
34 DETECTION_RESULT_NO_RESPONSE, | |
35 // Encountered a captive portal with a non-HTTPS landing URL. | |
36 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL, | |
37 // Received a network or HTTP error with an HTTPS landing URL. | |
38 DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL, | |
39 // Encountered a captive portal with an HTTPS landing URL. | |
40 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL, | |
41 DETECTION_RESULT_COUNT | |
42 }; | |
mmenke
2014/03/26 18:05:36
This should be in the anonymous namespace.
meacer
2014/03/26 19:07:32
Done.
| |
43 | |
28 namespace { | 44 namespace { |
29 | 45 |
30 // Records histograms relating to how often captive portal detection attempts | 46 // Records histograms relating to how often captive portal detection attempts |
31 // ended with |result| in a row, and for how long |result| was the last result | 47 // ended with |result| in a row, and for how long |result| was the last result |
32 // of a detection attempt. Recorded both on quit and on a new Result. | 48 // of a detection attempt. Recorded both on quit and on a new Result. |
33 // | 49 // |
34 // |repeat_count| may be 0 if there were no captive portal checks during | 50 // |repeat_count| may be 0 if there were no captive portal checks during |
35 // a session. | 51 // a session. |
36 // | 52 // |
37 // |result_duration| is the time between when a captive portal check first | 53 // |result_duration| is the time between when a captive portal check first |
(...skipping 24 matching lines...) Expand all Loading... | |
62 base::Histogram::FactoryTimeGet( | 78 base::Histogram::FactoryTimeGet( |
63 "CaptivePortal.ResultDuration." + | 79 "CaptivePortal.ResultDuration." + |
64 CaptivePortalDetector::CaptivePortalResultToString(result), | 80 CaptivePortalDetector::CaptivePortalResultToString(result), |
65 base::TimeDelta::FromSeconds(1), // min | 81 base::TimeDelta::FromSeconds(1), // min |
66 base::TimeDelta::FromHours(1), // max | 82 base::TimeDelta::FromHours(1), // max |
67 50, // bucket_count | 83 50, // bucket_count |
68 base::Histogram::kUmaTargetedHistogramFlag); | 84 base::Histogram::kUmaTargetedHistogramFlag); |
69 result_duration_histogram->AddTime(result_duration); | 85 result_duration_histogram->AddTime(result_duration); |
70 } | 86 } |
71 | 87 |
88 int GetHistogramEntryForDetectionResult( | |
89 const CaptivePortalDetector::Results& results) { | |
90 bool is_https = results.landing_url.SchemeIs("https"); | |
mmenke
2014/03/26 18:05:36
Should use a switch on results.result. It's more
meacer
2014/03/26 19:07:32
Done.
| |
91 if (results.result == RESULT_NO_RESPONSE) { | |
92 return is_https | |
93 ? DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL | |
94 : DETECTION_RESULT_NO_RESPONSE; | |
95 } | |
96 if (results.result == RESULT_BEHIND_CAPTIVE_PORTAL) { | |
97 return is_https | |
98 ? DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL | |
99 : DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL; | |
100 } | |
101 return DETECTION_RESULT_INTERNET_CONNECTED; | |
102 } | |
103 | |
72 bool ShouldDeferToNativeCaptivePortalDetection() { | 104 bool ShouldDeferToNativeCaptivePortalDetection() { |
73 // On Windows 8, defer to the native captive portal detection. OSX Lion and | 105 // On Windows 8, defer to the native captive portal detection. OSX Lion and |
74 // later also have captive portal detection, but experimentally, this code | 106 // later also have captive portal detection, but experimentally, this code |
75 // works in cases its does not. | 107 // works in cases its does not. |
76 // | 108 // |
77 // TODO(mmenke): Investigate how well Windows 8's captive portal detection | 109 // TODO(mmenke): Investigate how well Windows 8's captive portal detection |
78 // works. | 110 // works. |
79 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
80 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 112 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
81 #else | 113 #else |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); | 235 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); |
204 DCHECK(!TimerRunning()); | 236 DCHECK(!TimerRunning()); |
205 DCHECK(enabled_); | 237 DCHECK(enabled_); |
206 | 238 |
207 Result result = results.result; | 239 Result result = results.result; |
208 const base::TimeDelta& retry_after_delta = results.retry_after_delta; | 240 const base::TimeDelta& retry_after_delta = results.retry_after_delta; |
209 base::TimeTicks now = GetCurrentTimeTicks(); | 241 base::TimeTicks now = GetCurrentTimeTicks(); |
210 | 242 |
211 // Record histograms. | 243 // Record histograms. |
212 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult", | 244 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult", |
213 result, | 245 GetHistogramEntryForDetectionResult(results), |
214 RESULT_COUNT); | 246 DETECTION_RESULT_COUNT); |
215 | 247 |
216 // If this isn't the first captive portal result, record stats. | 248 // If this isn't the first captive portal result, record stats. |
217 if (!last_check_time_.is_null()) { | 249 if (!last_check_time_.is_null()) { |
218 UMA_HISTOGRAM_LONG_TIMES("CaptivePortal.TimeBetweenChecks", | 250 UMA_HISTOGRAM_LONG_TIMES("CaptivePortal.TimeBetweenChecks", |
219 now - last_check_time_); | 251 now - last_check_time_); |
220 | 252 |
221 if (last_detection_result_ != result) { | 253 if (last_detection_result_ != result) { |
222 // If the last result was different from the result of the latest test, | 254 // If the last result was different from the result of the latest test, |
223 // record histograms about the previous period over which the result was | 255 // record histograms about the previous period over which the result was |
224 // the same. | 256 // the same. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 | 370 |
339 bool CaptivePortalService::DetectionInProgress() const { | 371 bool CaptivePortalService::DetectionInProgress() const { |
340 return state_ == STATE_CHECKING_FOR_PORTAL; | 372 return state_ == STATE_CHECKING_FOR_PORTAL; |
341 } | 373 } |
342 | 374 |
343 bool CaptivePortalService::TimerRunning() const { | 375 bool CaptivePortalService::TimerRunning() const { |
344 return check_captive_portal_timer_.IsRunning(); | 376 return check_captive_portal_timer_.IsRunning(); |
345 } | 377 } |
346 | 378 |
347 } // namespace captive_portal | 379 } // namespace captive_portal |
OLD | NEW |