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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_service.cc

Issue 211983002: Add logging for distinguishing between captive portals with HTTP and HTTPS login pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: isherman comments Created 6 years, 9 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) 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 namespace { 28 namespace {
29 29
30 // Make sure this enum is in sync with CaptivePortalDetectionResult enum
31 // in histograms.xml. This enum is append-only, don't modify existing values.
32 enum CaptivePortalDetectionResult {
33 // There's a confirmed connection to the Internet.
34 DETECTION_RESULT_INTERNET_CONNECTED,
35 // Received a network or HTTP error, or a non-HTTP response.
36 DETECTION_RESULT_NO_RESPONSE,
37 // Encountered a captive portal with a non-HTTPS landing URL.
38 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL,
39 // Received a network or HTTP error with an HTTPS landing URL.
40 DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL,
41 // Encountered a captive portal with an HTTPS landing URL.
42 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL,
43 DETECTION_RESULT_COUNT
44 };
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
38 // returned |result| and when a check returned a different result, or when the 54 // returned |result| and when a check returned a different result, or when the
39 // CaptivePortalService was shut down. 55 // CaptivePortalService was shut down.
(...skipping 22 matching lines...) Expand all
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");
91 switch (results.result) {
92 case RESULT_INTERNET_CONNECTED:
93 return DETECTION_RESULT_INTERNET_CONNECTED;
94 case RESULT_NO_RESPONSE:
95 return is_https ?
96 DETECTION_RESULT_NO_RESPONSE_HTTPS_LANDING_URL :
97 DETECTION_RESULT_NO_RESPONSE;
98 case RESULT_BEHIND_CAPTIVE_PORTAL:
99 return is_https ?
100 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL_HTTPS_LANDING_URL :
101 DETECTION_RESULT_BEHIND_CAPTIVE_PORTAL;
102 }
103 NOTREACHED();
104 return -1;
105 }
106
72 bool ShouldDeferToNativeCaptivePortalDetection() { 107 bool ShouldDeferToNativeCaptivePortalDetection() {
73 // On Windows 8, defer to the native captive portal detection. OSX Lion and 108 // On Windows 8, defer to the native captive portal detection. OSX Lion and
74 // later also have captive portal detection, but experimentally, this code 109 // later also have captive portal detection, but experimentally, this code
75 // works in cases its does not. 110 // works in cases its does not.
76 // 111 //
77 // TODO(mmenke): Investigate how well Windows 8's captive portal detection 112 // TODO(mmenke): Investigate how well Windows 8's captive portal detection
78 // works. 113 // works.
79 #if defined(OS_WIN) 114 #if defined(OS_WIN)
80 return base::win::GetVersion() >= base::win::VERSION_WIN8; 115 return base::win::GetVersion() >= base::win::VERSION_WIN8;
81 #else 116 #else
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_); 238 DCHECK_EQ(STATE_CHECKING_FOR_PORTAL, state_);
204 DCHECK(!TimerRunning()); 239 DCHECK(!TimerRunning());
205 DCHECK(enabled_); 240 DCHECK(enabled_);
206 241
207 Result result = results.result; 242 Result result = results.result;
208 const base::TimeDelta& retry_after_delta = results.retry_after_delta; 243 const base::TimeDelta& retry_after_delta = results.retry_after_delta;
209 base::TimeTicks now = GetCurrentTimeTicks(); 244 base::TimeTicks now = GetCurrentTimeTicks();
210 245
211 // Record histograms. 246 // Record histograms.
212 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult", 247 UMA_HISTOGRAM_ENUMERATION("CaptivePortal.DetectResult",
213 result, 248 GetHistogramEntryForDetectionResult(results),
214 RESULT_COUNT); 249 DETECTION_RESULT_COUNT);
215 250
216 // If this isn't the first captive portal result, record stats. 251 // If this isn't the first captive portal result, record stats.
217 if (!last_check_time_.is_null()) { 252 if (!last_check_time_.is_null()) {
218 UMA_HISTOGRAM_LONG_TIMES("CaptivePortal.TimeBetweenChecks", 253 UMA_HISTOGRAM_LONG_TIMES("CaptivePortal.TimeBetweenChecks",
219 now - last_check_time_); 254 now - last_check_time_);
220 255
221 if (last_detection_result_ != result) { 256 if (last_detection_result_ != result) {
222 // If the last result was different from the result of the latest test, 257 // 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 258 // record histograms about the previous period over which the result was
224 // the same. 259 // the same.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 373
339 bool CaptivePortalService::DetectionInProgress() const { 374 bool CaptivePortalService::DetectionInProgress() const {
340 return state_ == STATE_CHECKING_FOR_PORTAL; 375 return state_ == STATE_CHECKING_FOR_PORTAL;
341 } 376 }
342 377
343 bool CaptivePortalService::TimerRunning() const { 378 bool CaptivePortalService::TimerRunning() const {
344 return check_captive_portal_timer_.IsRunning(); 379 return check_captive_portal_timer_.IsRunning();
345 } 380 }
346 381
347 } // namespace captive_portal 382 } // namespace captive_portal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698