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