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 content::WebContents* SecurityInterstitialUmaHelper::web_contents() const { | |
44 return web_contents_; | |
45 } | |
46 | |
47 GURL SecurityInterstitialUmaHelper::request_url() const { | |
48 return request_url_; | |
49 } | |
50 | |
51 // Directly adds to the histograms, using the same properties as | |
52 // UMA_HISTOGRAM_ENUMERATION, because the macro doesn't allow non-constant | |
53 // histogram names. | |
54 void SecurityInterstitialUmaHelper::RecordUserDecision( | |
55 SecurityInterstitialDecision decision) { | |
56 std::string decision_histogram_name( | |
57 "interstitial." + histogram_prefix_ + ".decision"); | |
58 base::HistogramBase* decision_histogram = base::LinearHistogram::FactoryGet( | |
59 decision_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | |
60 base::HistogramBase::kUmaTargetedHistogramFlag); | |
61 decision_histogram->Add(decision); | |
62 | |
63 #if defined(ENABLE_EXTENSIONS) | |
64 if (!sampling_event_.get()) { | |
65 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | |
66 sampling_event_name_, | |
67 request_url(), | |
68 web_contents()->GetLastCommittedURL(), | |
69 web_contents()->GetBrowserContext())); | |
70 } | |
71 switch (decision) { | |
72 case PROCEED: | |
73 sampling_event_->CreateUserDecisionEvent( | |
74 extensions::ExperienceSamplingEvent::kProceed); | |
75 break; | |
76 case DONT_PROCEED: | |
77 sampling_event_->CreateUserDecisionEvent( | |
78 extensions::ExperienceSamplingEvent::kDeny); | |
79 break; | |
80 case SHOW: | |
81 case PROCEEDING_DISABLED: | |
82 case MAX_DECISION: | |
83 break; | |
84 } | |
85 #endif | |
86 | |
87 // Record additional information about sites that users have | |
88 // visited before. | |
89 if (num_visits_ < 1 || (decision != PROCEED && decision != DONT_PROCEED)) | |
90 return; | |
91 std::string history_histogram_name( | |
92 "interstitial." + histogram_prefix_ + ".decision.repeat_visit"); | |
93 base::HistogramBase* history_histogram = base::LinearHistogram::FactoryGet( | |
94 history_histogram_name, 1, MAX_DECISION, MAX_DECISION + 1, | |
95 base::HistogramBase::kUmaTargetedHistogramFlag); | |
96 history_histogram->Add(SHOW); | |
97 history_histogram->Add(decision); | |
98 } | |
99 | |
100 void SecurityInterstitialUmaHelper::RecordUserInteraction( | |
101 SecurityInterstitialInteraction interaction) { | |
102 std::string interaction_histogram_name( | |
103 "interstitial." + histogram_prefix_ + ".interaction"); | |
104 base::HistogramBase* interaction_histogram = | |
105 base::LinearHistogram::FactoryGet( | |
106 interaction_histogram_name, 1, MAX_INTERACTION, MAX_INTERACTION + 1, | |
107 base::HistogramBase::kUmaTargetedHistogramFlag); | |
108 interaction_histogram->Add(interaction); | |
109 | |
110 #if defined(ENABLE_EXTENSIONS) | |
111 if (!sampling_event_.get()) { | |
112 sampling_event_.reset(new extensions::ExperienceSamplingEvent( | |
113 sampling_event_name_, | |
114 request_url(), | |
115 web_contents()->GetLastCommittedURL(), | |
116 web_contents()->GetBrowserContext())); | |
117 } | |
118 switch (interaction) { | |
119 case SHOW_LEARN_MORE: | |
120 sampling_event_->set_has_viewed_learn_more(true); | |
121 break; | |
122 case SHOW_ADVANCED: | |
123 sampling_event_->set_has_viewed_details(true); | |
124 break; | |
125 case SHOW_PRIVACY_POLICY: | |
126 case SHOW_DIAGNOSTIC: | |
127 case RELOAD: | |
128 case OPEN_TIME_SETTINGS: | |
129 case TOTAL_VISITS: | |
130 case MAX_INTERACTION: | |
131 break; | |
132 } | |
133 #endif | |
134 } | |
135 | |
136 void SecurityInterstitialUmaHelper::OnGotHistoryCount( | |
137 bool success, int num_visits, base::Time first_visit) { | |
Alexei Svitkine (slow)
2015/01/14 22:12:33
Nit: When params wrap in a decl, put one param on
palmer
2015/01/15 01:09:32
Or whatever "git cl format" does :)
felt
2015/01/15 06:47:22
Done.
| |
138 if (success) | |
139 num_visits_ = num_visits; | |
140 } | |
OLD | NEW |