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

Side by Side Diff: chrome/browser/ssl/captive_portal_metrics_recorder.cc

Issue 1365733005: Split captive portal metrics out of SSLErrorClassification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compiler error fix possibly for realsies Created 5 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ssl/captive_portal_metrics_recorder.h"
6
7 #include <vector>
8
9 #include "base/metrics/histogram_macros.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/web_contents.h"
15
16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
17 #include "chrome/browser/captive_portal/captive_portal_service.h"
18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
19 #endif
20
21 namespace {
22
23 // Events for UMA. Do not reorder or change!
24 enum SSLInterstitialCauseCaptivePortal {
25 CAPTIVE_PORTAL_ALL,
26 CAPTIVE_PORTAL_DETECTION_ENABLED,
27 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE,
28 CAPTIVE_PORTAL_PROBE_COMPLETED,
29 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
30 CAPTIVE_PORTAL_NO_RESPONSE,
31 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
32 CAPTIVE_PORTAL_DETECTED,
33 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
34 UNUSED_CAPTIVE_PORTAL_EVENT,
35 };
36
37 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
38 void RecordCaptivePortalEventStats(SSLInterstitialCauseCaptivePortal event) {
39 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.captive_portal", event,
40 UNUSED_CAPTIVE_PORTAL_EVENT);
41 }
42 #endif
43
44 } // namespace
45
46 CaptivePortalMetricsRecorder::CaptivePortalMetricsRecorder(
47 content::WebContents* web_contents,
48 bool overridable)
49 : captive_portal_detection_enabled_(false),
50 captive_portal_probe_completed_(false),
51 captive_portal_no_response_(false),
52 captive_portal_detected_(false) {
53 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
54 overridable_ = overridable;
55 Profile* profile =
56 Profile::FromBrowserContext(web_contents->GetBrowserContext());
57 captive_portal_detection_enabled_ =
58 CaptivePortalServiceFactory::GetForProfile(profile)->enabled();
59 registrar_.Add(this, chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
60 content::Source<Profile>(profile));
61 #endif
62 }
63
64 CaptivePortalMetricsRecorder::~CaptivePortalMetricsRecorder() {}
65
66 void CaptivePortalMetricsRecorder::RecordCaptivePortalUMAStatistics() const {
67 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
68 RecordCaptivePortalEventStats(CAPTIVE_PORTAL_ALL);
69 if (captive_portal_detection_enabled_)
70 RecordCaptivePortalEventStats(
71 overridable_ ? CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE
72 : CAPTIVE_PORTAL_DETECTION_ENABLED);
73 if (captive_portal_probe_completed_)
74 RecordCaptivePortalEventStats(
75 overridable_ ? CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE
76 : CAPTIVE_PORTAL_PROBE_COMPLETED);
77 // Log only one of portal detected and no response results.
78 if (captive_portal_detected_)
79 RecordCaptivePortalEventStats(overridable_
80 ? CAPTIVE_PORTAL_DETECTED_OVERRIDABLE
81 : CAPTIVE_PORTAL_DETECTED);
82 else if (captive_portal_no_response_)
83 RecordCaptivePortalEventStats(overridable_
84 ? CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE
85 : CAPTIVE_PORTAL_NO_RESPONSE);
86 #endif
87 }
88
89 void CaptivePortalMetricsRecorder::Observe(
90 int type,
91 const content::NotificationSource& source,
92 const content::NotificationDetails& details) {
93 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
94 // When detection is disabled, captive portal service always sends
95 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case.
96 if (!captive_portal_detection_enabled_)
97 return;
98 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
99 captive_portal_probe_completed_ = true;
100 CaptivePortalService::Results* results =
101 content::Details<CaptivePortalService::Results>(details).ptr();
102 // If a captive portal was detected at any point when the interstitial was
103 // displayed, assume that the interstitial was caused by a captive portal.
104 // Example scenario:
105 // 1- Interstitial displayed and captive portal detected, setting the flag.
106 // 2- Captive portal detection automatically opens portal login page.
107 // 3- User logs in on the portal login page.
108 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make
109 // sure we don't clear the captive protal flag, since the interstitial was
110 // potentially caused by the captive portal.
111 captive_portal_detected_ =
112 captive_portal_detected_ ||
113 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
114 // Also keep track of non-HTTP portals and error cases.
115 captive_portal_no_response_ =
116 captive_portal_no_response_ ||
117 (results->result == captive_portal::RESULT_NO_RESPONSE);
118 }
119 #endif
120 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/captive_portal_metrics_recorder.h ('k') | chrome/browser/ssl/ssl_blocking_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698