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

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

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

Powered by Google App Engine
This is Rietveld 408576698