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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.h

Issue 839183002: Remove redundancy in security interstitial UMA logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ... Created 5 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Classes for managing the SafeBrowsing interstitial pages. 5 // Classes for managing the SafeBrowsing interstitial pages.
6 // 6 //
7 // When a user is about to visit a page the SafeBrowsing system has deemed to 7 // When a user is about to visit a page the SafeBrowsing system has deemed to
8 // be malicious, either as malware or a phishing page, we show an interstitial 8 // be malicious, either as malware or a phishing page, we show an interstitial
9 // page with some options (go back, continue) to give the user a chance to avoid 9 // page with some options (go back, continue) to give the user a chance to avoid
10 // the harmful page. 10 // the harmful page.
(...skipping 16 matching lines...) Expand all
27 27
28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
30 30
31 #include <map> 31 #include <map>
32 #include <string> 32 #include <string>
33 #include <vector> 33 #include <vector>
34 34
35 #include "base/gtest_prod_util.h" 35 #include "base/gtest_prod_util.h"
36 #include "base/task/cancelable_task_tracker.h" 36 #include "base/task/cancelable_task_tracker.h"
37 #include "base/time/time.h"
38 #include "chrome/browser/history/history_service.h"
39 #include "chrome/browser/interstitials/security_interstitial_page.h" 37 #include "chrome/browser/interstitials/security_interstitial_page.h"
38 #include "chrome/browser/interstitials/security_interstitial_uma_helper.h"
40 #include "chrome/browser/safe_browsing/ui_manager.h" 39 #include "chrome/browser/safe_browsing/ui_manager.h"
41 #include "url/gurl.h" 40 #include "url/gurl.h"
42 41
43 class MalwareDetails; 42 class MalwareDetails;
44 class SafeBrowsingBlockingPageFactory; 43 class SafeBrowsingBlockingPageFactory;
45 44
46 namespace base { 45 namespace base {
47 class MessageLoop; 46 class MessageLoop;
48 } 47 }
49 48
50 #if defined(ENABLE_EXTENSIONS)
51 namespace extensions {
52 class ExperienceSamplingEvent;
53 }
54 #endif
55
56 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { 49 class SafeBrowsingBlockingPage : public SecurityInterstitialPage {
57 public: 50 public:
58 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 51 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
59 typedef std::vector<UnsafeResource> UnsafeResourceList; 52 typedef std::vector<UnsafeResource> UnsafeResourceList;
60 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; 53 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap;
61 54
62 // Interstitial type, used in tests. 55 // Interstitial type, used in tests.
63 static const void* kTypeForTesting; 56 static const void* kTypeForTesting;
64 57
65 ~SafeBrowsingBlockingPage() override; 58 ~SafeBrowsingBlockingPage() override;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // report but clicked "proceed anyway", we delay the call to 108 // report but clicked "proceed anyway", we delay the call to
116 // MalwareDetails::FinishCollection() by this much time (in 109 // MalwareDetails::FinishCollection() by this much time (in
117 // milliseconds), in order to get data from the blocked resource itself. 110 // milliseconds), in order to get data from the blocked resource itself.
118 int64 malware_details_proceed_delay_ms_; 111 int64 malware_details_proceed_delay_ms_;
119 112
120 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 113 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
121 MalwareReportsTransitionDisabled); 114 MalwareReportsTransitionDisabled);
122 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, 115 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
123 MalwareReportsToggling); 116 MalwareReportsToggling);
124 117
125 // These enums are used for histograms. Don't reorder, delete, or insert
126 // elements. New elements should be added before MAX_ACTION only.
127 enum Decision {
128 SHOW,
129 PROCEED,
130 DONT_PROCEED,
131 PROCEEDING_DISABLED,
132 MAX_DECISION
133 };
134 enum Interaction {
135 TOTAL_VISITS,
136 SHOW_ADVANCED,
137 SHOW_PRIVACY_POLICY,
138 SHOW_DIAGNOSTIC,
139 SHOW_LEARN_MORE,
140 MAX_INTERACTION
141 };
142
143 // Record a user decision or interaction to the appropriate UMA histogram.
144 void RecordUserDecision(Decision decision);
145 void RecordUserInteraction(Interaction interaction);
146
147 // Used to query the HistoryService to see if the URL is in history. For UMA.
148 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit);
149
150 // Checks if we should even show the malware details option. For example, we 118 // Checks if we should even show the malware details option. For example, we
151 // don't show it in incognito mode. 119 // don't show it in incognito mode.
152 bool CanShowMalwareDetailsOption(); 120 bool CanShowMalwareDetailsOption();
153 121
154 // Called when the insterstitial is going away. If there is a 122 // Called when the insterstitial is going away. If there is a
155 // pending malware details object, we look at the user's 123 // pending malware details object, we look at the user's
156 // preferences, and if the option to send malware details is 124 // preferences, and if the option to send malware details is
157 // enabled, the report is scheduled to be sent on the |ui_manager_|. 125 // enabled, the report is scheduled to be sent on the |ui_manager_|.
158 void FinishMalwareDetails(int64 delay_ms); 126 void FinishMalwareDetails(int64 delay_ms);
159 127
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // The list of unsafe resources this page is warning about. 164 // The list of unsafe resources this page is warning about.
197 UnsafeResourceList unsafe_resources_; 165 UnsafeResourceList unsafe_resources_;
198 166
199 // A MalwareDetails object that we start generating when the 167 // A MalwareDetails object that we start generating when the
200 // blocking page is shown. The object will be sent when the warning 168 // blocking page is shown. The object will be sent when the warning
201 // is gone (if the user enables the feature). 169 // is gone (if the user enables the feature).
202 scoped_refptr<MalwareDetails> malware_details_; 170 scoped_refptr<MalwareDetails> malware_details_;
203 171
204 bool proceeded_; 172 bool proceeded_;
205 173
206 // Which type of interstitial this is. 174 // Which type of Safe Browsing interstitial this is.
207 enum { 175 enum SBInterstitialReason {
208 TYPE_MALWARE, 176 SB_REASON_MALWARE,
209 TYPE_HARMFUL, 177 SB_REASON_HARMFUL,
210 TYPE_PHISHING, 178 SB_REASON_PHISHING,
211 } interstitial_type_; 179 } interstitial_reason_;
212 180
213 // The factory used to instantiate SafeBrowsingBlockingPage objects. 181 // The factory used to instantiate SafeBrowsingBlockingPage objects.
214 // Usefull for tests, so they can provide their own implementation of 182 // Usefull for tests, so they can provide their own implementation of
215 // SafeBrowsingBlockingPage. 183 // SafeBrowsingBlockingPage.
216 static SafeBrowsingBlockingPageFactory* factory_; 184 static SafeBrowsingBlockingPageFactory* factory_;
217 185
218 // How many times is this same URL in history? Used for histogramming.
219 int num_visits_;
220 base::CancelableTaskTracker request_tracker_;
221
222 private: 186 private:
223 // Fills the passed dictionary with the values to be passed to the template 187 // Fills the passed dictionary with the values to be passed to the template
224 // when creating the HTML. 188 // when creating the HTML.
225 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data); 189 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data);
226 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); 190 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data);
227 void PopulateHarmfulLoadTimeData(base::DictionaryValue* load_time_data); 191 void PopulateHarmfulLoadTimeData(base::DictionaryValue* load_time_data);
228 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); 192 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data);
229 193
230 #if defined(ENABLE_EXTENSIONS) 194 std::string GetHistogramPrefix() const;
231 scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_; 195 std::string GetSamplingEventName() const;
232 #endif 196
197 scoped_ptr<SecurityInterstitialUmaHelper> uma_helper_;
233 198
234 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); 199 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage);
235 }; 200 };
236 201
237 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. 202 // Factory for creating SafeBrowsingBlockingPage. Useful for tests.
238 class SafeBrowsingBlockingPageFactory { 203 class SafeBrowsingBlockingPageFactory {
239 public: 204 public:
240 virtual ~SafeBrowsingBlockingPageFactory() { } 205 virtual ~SafeBrowsingBlockingPageFactory() { }
241 206
242 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 207 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
243 SafeBrowsingUIManager* ui_manager, 208 SafeBrowsingUIManager* ui_manager,
244 content::WebContents* web_contents, 209 content::WebContents* web_contents,
245 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; 210 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0;
246 }; 211 };
247 212
248 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 213 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698