OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014 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/interstitials/security_interstitial_uma_helper.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "chrome/browser/history/history_service.h" | |
9 #include "chrome/browser/history/history_service_factory.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/webdata/web_data_service_factory.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 | |
14 #if defined(ENABLE_EXTENSIONS) | |
15 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | |
16 #endif | |
17 | |
18 SecurityInterstitialUmaHelper::SecurityInterstitialUmaHelper( | |
19 content::WebContents* web_contents, | |
20 const GURL& request_url, | |
21 const std::string& histogram_prefix, | |
22 const std::string& sampling_event_name) | |
23 : web_contents_(web_contents), | |
24 request_url_(request_url), | |
25 histogram_prefix_(histogram_prefix), | |
26 sampling_event_name_(sampling_event_name), | |
27 num_visits_(-1) { | |
28 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | |
29 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
30 ServiceAccessType::EXPLICIT_ACCESS); | |
31 if (history_service) { | |
32 history_service->GetVisibleVisitCountToHost( | |
33 request_url_, | |
34 base::Bind(&SecurityInterstitialUmaHelper::OnGotHistoryCount, | |
35 base::Unretained(this)), | |
36 &request_tracker_); | |
37 } | |
38 } | |
39 | |
40 SecurityInterstitialUmaHelper::~SecurityInterstitialUmaHelper() { | |
41 } | |
42 | |
43 // Directly adds to the histograms, using the same properties as | |
44 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant | |
45 // histogram names. | |
46 void SecurityInterstitialUmaHelper::RecordUserDecision( | |
47 SecurityInterstitialDecision decision) { | |
48 std::string decision_histogram_name( | |
49 "interstitial." + histogram_prefix_ + ".decision"); | |
50 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet( | |
51 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | |
52 base::HistogramBase::kUmaTargetedHistogramFlag); | |
53 decision_histogram->Add(decision); | |
54 | |
55 #if defined(ENABLE_EXTENSIONS) | |
56 if (!sampling_event_.get()) { | |
57 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | |
58 sampling_event_name_, | |
59 request_url_, | |
60 web_contents_->GetLastCommittedURL(), | |
61 web_contents_->GetBrowserContext())); | |
62 } | |
63 switch (decision) { | |
64 case PROCEED: | |
65 sampling_event_->CreateUserDecisionEvent( | |
66 extensions::ExperienceSamplingEvent::kProceed); | |
67 break; | |
68 case DONT_PROCEED: | |
69 sampling_event_->CreateUserDecisionEvent( | |
70 extensions::ExperienceSamplingEvent::kDeny); | |
71 break; | |
72 case SHOW: | |
73 case PROCEEDING_DISABLED: | |
74 case MAX_DECISION: | |
75 break; | |
76 } | |
77 #endif | |
78 | |
79 // Record additional information about sites that users have | |
80 // visited before. | |
81 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED)) | |
82 return; | |
83 std::string history_histogram_name( | |
84 "interstitial." + histogram_prefix_ + ".decision.repeat_visit"); | |
85 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet( | |
86 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | |
87 base::HistogramBase::kUmaTargetedHistogramFlag); | |
88 history_histogram->Add(SHOW); | |
89 history_histogram->Add(decision); | |
90 } | |
91 | |
92 void SecurityInterstitialUmaHelper::RecordUserInteraction( | |
93 SecurityInterstitialInteraction interaction) { | |
94 std::string interaction_histogram_name( | |
95 "interstitial." + histogram_prefix_ + ".interaction"); | |
96 base::HistogramBase* interaction_histogram = | |
97 base::LinearHistogram::FactoryGet( | |
98 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1, | |
99 base::HistogramBase::kUmaTargetedHistogramFlag); | |
100 interaction_histogram->Add(interaction); | |
101 | |
102 #if defined(ENABLE_EXTENSIONS) | |
103 if (!sampling_event_.get()) { | |
104 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | |
105 sampling_event_name_, | |
106 request_url_, | |
107 web_contents_->GetLastCommittedURL(), | |
108 web_contents_->GetBrowserContext())); | |
109 } | |
110 switch (interaction) { | |
111 case SHOW_LEARN_MORE: | |
112 sampling_event_->set_has_viewed_learn_more(true); | |
113 break; | |
114 case SHOW_ADVANCED: | |
115 sampling_event_->set_has_viewed_details(true); | |
116 break; | |
117 case SHOW_PRIVACY_POLICY: | |
118 case SHOW_DIAGNOSTIC: | |
119 case RELOAD: | |
120 case OPEN_TIME_SETTINGS: | |
121 case TOTAL_VISITS: | |
122 case MAX_INTERACTION: | |
123 break; | |
124 } | |
125 #endif | |
126 } | |
127 | |
128 void SecurityInterstitialUmaHelper::OnGotHistoryCount( | |
129 bool success, | |
130 int num_visits, | |
131 base::Time first_visit) { | |
132 if (success) | |
133 num_visits_ = num_visits; | |
134 } | |
OLD | NEW |