OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/safe_browsing/unverified_download_policy.h" | 5 #include "chrome/browser/safe_browsing/unverified_download_policy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/metrics/histogram_macros.h" | |
10 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
13 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h" | 14 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h" |
14 #include "chrome/common/safe_browsing/download_protection_util.h" | 15 #include "chrome/common/safe_browsing/download_protection_util.h" |
15 #include "components/rappor/rappor_service.h" | 16 #include "components/rappor/rappor_service.h" |
16 #include "components/rappor/rappor_utils.h" | 17 #include "components/rappor/rappor_utils.h" |
17 #include "components/safe_browsing_db/database_manager.h" | 18 #include "components/safe_browsing_db/database_manager.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 | 20 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 int uma_file_type = | 54 int uma_file_type = |
54 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); | 55 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); |
55 if (policy == UnverifiedDownloadPolicy::ALLOWED) { | 56 if (policy == UnverifiedDownloadPolicy::ALLOWED) { |
56 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Allowed", | 57 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Allowed", |
57 uma_file_type, requestor); | 58 uma_file_type, requestor); |
58 } else { | 59 } else { |
59 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Blocked", | 60 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Blocked", |
60 uma_file_type, requestor); | 61 uma_file_type, requestor); |
61 } | 62 } |
62 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 63 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
63 base::Bind(callback, policy)); | 64 base::Bind(callback, policy)); |
64 } | 65 } |
65 | 66 |
66 void CheckFieldTrialOnAnyThread( | 67 void CheckFieldTrialOnAnyThread( |
67 const base::FilePath& file, | 68 const base::FilePath& file, |
69 const std::vector<base::FilePath::StringType>& alternate_extensions, | |
68 const GURL& requestor, | 70 const GURL& requestor, |
69 const UnverifiedDownloadCheckCompletionCallback& callback) { | 71 const UnverifiedDownloadCheckCompletionCallback& callback) { |
70 bool is_allowed = IsUnverifiedDownloadAllowedByFieldTrial(file); | 72 if (!IsUnverifiedDownloadAllowedByFieldTrial(file)) { |
71 RespondWithPolicy(file, callback, requestor, is_allowed | 73 RespondWithPolicy(file, callback, requestor, |
72 ? UnverifiedDownloadPolicy::ALLOWED | 74 UnverifiedDownloadPolicy::DISALLOWED); |
73 : UnverifiedDownloadPolicy::DISALLOWED); | 75 return; |
76 } | |
77 | |
78 for (const auto& extension : alternate_extensions) { | |
79 base::FilePath alternate_filename = file.AddExtension(extension); | |
80 if (!IsUnverifiedDownloadAllowedByFieldTrial(alternate_filename)) { | |
81 RespondWithPolicy(alternate_filename, callback, requestor, | |
82 UnverifiedDownloadPolicy::DISALLOWED); | |
83 return; | |
84 } | |
85 } | |
86 | |
87 RespondWithPolicy(file, callback, requestor, | |
88 UnverifiedDownloadPolicy::ALLOWED); | |
74 } | 89 } |
75 | 90 |
76 void CheckWhitelistOnIOThread( | 91 void CheckWhitelistOnIOThread( |
77 scoped_refptr<SafeBrowsingService> service, | 92 scoped_refptr<SafeBrowsingService> service, |
78 const GURL& requestor, | 93 const GURL& requestor, |
79 const base::FilePath& file, | 94 const base::FilePath& file, |
95 const std::vector<base::FilePath::StringType>& alternate_extensions, | |
80 const UnverifiedDownloadCheckCompletionCallback& callback) { | 96 const UnverifiedDownloadCheckCompletionCallback& callback) { |
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
82 int uma_file_type = | 98 int uma_file_type = |
83 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); | 99 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); |
84 | 100 |
85 if (!service || !service->enabled()) { | 101 if (!service || !service->enabled()) { |
86 // If the SafeBrowsing service was disabled, don't try to check against the | 102 // If the SafeBrowsing service was disabled, don't try to check against the |
87 // field trial list. Instead allow the download. We are assuming that if the | 103 // field trial list. Instead allow the download. We are assuming that if the |
88 // SafeBrowsing service was disabled for this user, then we shouldn't | 104 // SafeBrowsing service was disabled for this user, then we shouldn't |
89 // interefere with unverified downloads. | 105 // interefere with unverified downloads. |
90 RecordPolicyMetric( | 106 RecordPolicyMetric( |
91 "SafeBrowsing.UnverifiedDownloads.AllowedDueToDisabledService", | 107 "SafeBrowsing.UnverifiedDownloads.AllowedDueToDisabledService", |
92 uma_file_type, requestor); | 108 uma_file_type, requestor); |
93 RespondWithPolicy(file, callback, requestor, | 109 RespondWithPolicy(file, callback, requestor, |
94 UnverifiedDownloadPolicy::ALLOWED); | 110 UnverifiedDownloadPolicy::ALLOWED); |
95 return; | 111 return; |
96 } | 112 } |
97 | 113 |
98 if (service->database_manager() && | 114 if (service->database_manager() && |
99 service->database_manager()->MatchDownloadWhitelistUrl(requestor)) { | 115 service->database_manager()->MatchDownloadWhitelistUrl(requestor)) { |
100 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.AllowedByWhitelist", | 116 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.AllowedByWhitelist", |
101 uma_file_type, requestor); | 117 uma_file_type, requestor); |
102 RespondWithPolicy(file, callback, requestor, | 118 RespondWithPolicy(file, callback, requestor, |
103 UnverifiedDownloadPolicy::ALLOWED); | 119 UnverifiedDownloadPolicy::ALLOWED); |
104 return; | 120 return; |
105 } | 121 } |
106 | 122 |
107 CheckFieldTrialOnAnyThread(file, requestor, callback); | 123 CheckFieldTrialOnAnyThread(file, alternate_extensions, requestor, callback); |
108 } | 124 } |
109 | 125 |
110 } // namespace | 126 } // namespace |
111 | 127 |
112 void CheckUnverifiedDownloadPolicy( | 128 void CheckUnverifiedDownloadPolicy( |
113 const GURL& requestor, | 129 const GURL& requestor, |
114 const base::FilePath& file, | 130 const base::FilePath& file, |
131 const std::vector<base::FilePath::StringType>& alternate_extensions, | |
115 const UnverifiedDownloadCheckCompletionCallback& callback) { | 132 const UnverifiedDownloadCheckCompletionCallback& callback) { |
133 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
134 "SafeBrowsing.UnverifiedDownloads.AlternateExtensionCount", | |
135 alternate_extensions.size() + 1, 1, 31, 32); | |
Nathan Parker
2016/01/21 21:47:43
Thanks.
I'm curious: Why +1? Why not 0-32?
asanka
2016/01/21 22:08:47
0 is the underflow bucket. If the minimum is 0, it
Steven Holte
2016/01/22 23:50:49
You don't need the +1. This histogram will get a
asanka
2016/01/23 04:42:59
Ah. Got it.
I actually switched to a sparse histo
| |
116 if (requestor.is_valid()) { | 136 if (requestor.is_valid()) { |
117 scoped_refptr<SafeBrowsingService> service = | 137 scoped_refptr<SafeBrowsingService> service = |
118 g_browser_process->safe_browsing_service(); | 138 g_browser_process->safe_browsing_service(); |
119 BrowserThread::PostTask( | 139 BrowserThread::PostTask( |
120 BrowserThread::IO, FROM_HERE, | 140 BrowserThread::IO, FROM_HERE, |
121 base::Bind(&CheckWhitelistOnIOThread, service, requestor, file, | 141 base::Bind(&CheckWhitelistOnIOThread, service, requestor, file, |
122 callback)); | 142 alternate_extensions, callback)); |
123 return; | 143 return; |
124 } | 144 } |
125 | 145 |
126 CheckFieldTrialOnAnyThread(file, GURL(), callback); | 146 CheckFieldTrialOnAnyThread(file, alternate_extensions, GURL(), callback); |
127 } | 147 } |
128 | 148 |
129 } // namespace safe_browsing | 149 } // namespace safe_browsing |
OLD | NEW |