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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
15 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h" | 15 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h" |
16 #include "chrome/common/safe_browsing/download_protection_util.h" | 16 #include "chrome/common/safe_browsing/file_type_policies.h" |
17 #include "components/rappor/rappor_service.h" | 17 #include "components/rappor/rappor_service.h" |
18 #include "components/rappor/rappor_utils.h" | 18 #include "components/rappor/rappor_utils.h" |
19 #include "components/safe_browsing_db/database_manager.h" | 19 #include "components/safe_browsing_db/database_manager.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 | 21 |
22 namespace safe_browsing { | 22 namespace safe_browsing { |
23 | 23 |
24 namespace { | 24 namespace { |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
(...skipping 18 matching lines...) Expand all Loading... |
45 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 45 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
46 base::Bind(&RecordPolicyMetricOnUIThread, metric_name, | 46 base::Bind(&RecordPolicyMetricOnUIThread, metric_name, |
47 uma_file_type, requestor)); | 47 uma_file_type, requestor)); |
48 } | 48 } |
49 | 49 |
50 void RespondWithPolicy( | 50 void RespondWithPolicy( |
51 const base::FilePath& file, | 51 const base::FilePath& file, |
52 const UnverifiedDownloadCheckCompletionCallback& callback, | 52 const UnverifiedDownloadCheckCompletionCallback& callback, |
53 const GURL& requestor, | 53 const GURL& requestor, |
54 UnverifiedDownloadPolicy policy) { | 54 UnverifiedDownloadPolicy policy) { |
55 int uma_file_type = | 55 int64_t uma_file_type = |
56 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); | 56 FileTypePolicies::GetInstance()->UmaValueForFile(file); |
57 if (policy == UnverifiedDownloadPolicy::ALLOWED) { | 57 if (policy == UnverifiedDownloadPolicy::ALLOWED) { |
58 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Allowed", | 58 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Allowed", |
59 uma_file_type, requestor); | 59 uma_file_type, requestor); |
60 } else { | 60 } else { |
61 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Blocked", | 61 RecordPolicyMetric("SafeBrowsing.UnverifiedDownloads.Blocked", |
62 uma_file_type, requestor); | 62 uma_file_type, requestor); |
63 } | 63 } |
64 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 64 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
65 base::Bind(callback, policy)); | 65 base::Bind(callback, policy)); |
66 } | 66 } |
(...skipping 22 matching lines...) Expand all Loading... |
89 UnverifiedDownloadPolicy::ALLOWED); | 89 UnverifiedDownloadPolicy::ALLOWED); |
90 } | 90 } |
91 | 91 |
92 void CheckWhitelistOnIOThread( | 92 void CheckWhitelistOnIOThread( |
93 scoped_refptr<SafeBrowsingService> service, | 93 scoped_refptr<SafeBrowsingService> service, |
94 const GURL& requestor, | 94 const GURL& requestor, |
95 const base::FilePath& file, | 95 const base::FilePath& file, |
96 const std::vector<base::FilePath::StringType>& alternate_extensions, | 96 const std::vector<base::FilePath::StringType>& alternate_extensions, |
97 const UnverifiedDownloadCheckCompletionCallback& callback) { | 97 const UnverifiedDownloadCheckCompletionCallback& callback) { |
98 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
99 int uma_file_type = | 99 int64_t uma_file_type = |
100 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file); | 100 FileTypePolicies::GetInstance()->UmaValueForFile(file); |
101 | 101 |
102 if (!service || !service->enabled()) { | 102 if (!service || !service->enabled()) { |
103 // If the SafeBrowsing service was disabled, don't try to check against the | 103 // If the SafeBrowsing service was disabled, don't try to check against the |
104 // field trial list. Instead allow the download. We are assuming that if the | 104 // field trial list. Instead allow the download. We are assuming that if the |
105 // SafeBrowsing service was disabled for this user, then we shouldn't | 105 // SafeBrowsing service was disabled for this user, then we shouldn't |
106 // interefere with unverified downloads. | 106 // interefere with unverified downloads. |
107 RecordPolicyMetric( | 107 RecordPolicyMetric( |
108 "SafeBrowsing.UnverifiedDownloads.AllowedDueToDisabledService", | 108 "SafeBrowsing.UnverifiedDownloads.AllowedDueToDisabledService", |
109 uma_file_type, requestor); | 109 uma_file_type, requestor); |
110 RespondWithPolicy(file, callback, requestor, | 110 RespondWithPolicy(file, callback, requestor, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 BrowserThread::IO, FROM_HERE, | 146 BrowserThread::IO, FROM_HERE, |
147 base::Bind(&CheckWhitelistOnIOThread, service, requestor, file, | 147 base::Bind(&CheckWhitelistOnIOThread, service, requestor, file, |
148 alternate_extensions, callback)); | 148 alternate_extensions, callback)); |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 CheckFieldTrialOnAnyThread(file, alternate_extensions, GURL(), callback); | 152 CheckFieldTrialOnAnyThread(file, alternate_extensions, GURL(), callback); |
153 } | 153 } |
154 | 154 |
155 } // namespace safe_browsing | 155 } // namespace safe_browsing |
OLD | NEW |