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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 2418813002: [Reland] Refactoring of SBER preference usage (Closed)
Patch Set: Sync Created 4 years, 2 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 #include "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/common/safe_browsing/binary_feature_extractor.h" 45 #include "chrome/common/safe_browsing/binary_feature_extractor.h"
46 #include "chrome/common/safe_browsing/csd.pb.h" 46 #include "chrome/common/safe_browsing/csd.pb.h"
47 #include "chrome/common/safe_browsing/download_protection_util.h" 47 #include "chrome/common/safe_browsing/download_protection_util.h"
48 #include "chrome/common/safe_browsing/file_type_policies.h" 48 #include "chrome/common/safe_browsing/file_type_policies.h"
49 #include "chrome/common/safe_browsing/zip_analyzer_results.h" 49 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
50 #include "chrome/common/url_constants.h" 50 #include "chrome/common/url_constants.h"
51 #include "components/data_use_measurement/core/data_use_user_data.h" 51 #include "components/data_use_measurement/core/data_use_user_data.h"
52 #include "components/google/core/browser/google_util.h" 52 #include "components/google/core/browser/google_util.h"
53 #include "components/history/core/browser/history_service.h" 53 #include "components/history/core/browser/history_service.h"
54 #include "components/prefs/pref_service.h" 54 #include "components/prefs/pref_service.h"
55 #include "components/safe_browsing_db/safe_browsing_prefs.h"
55 #include "content/public/browser/browser_thread.h" 56 #include "content/public/browser/browser_thread.h"
56 #include "content/public/browser/download_item.h" 57 #include "content/public/browser/download_item.h"
57 #include "content/public/browser/page_navigator.h" 58 #include "content/public/browser/page_navigator.h"
58 #include "crypto/sha2.h" 59 #include "crypto/sha2.h"
59 #include "google_apis/google_api_keys.h" 60 #include "google_apis/google_api_keys.h"
60 #include "net/base/escape.h" 61 #include "net/base/escape.h"
61 #include "net/base/load_flags.h" 62 #include "net/base/load_flags.h"
62 #include "net/base/url_util.h" 63 #include "net/base/url_util.h"
63 #include "net/cert/x509_cert_types.h" 64 #include "net/cert/x509_cert_types.h"
64 #include "net/cert/x509_certificate.h" 65 #include "net/cert/x509_certificate.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SBStatsType dangerous_type) 170 SBStatsType dangerous_type)
170 : sha256_hash_(item.GetHash()), 171 : sha256_hash_(item.GetHash()),
171 url_chain_(item.GetUrlChain()), 172 url_chain_(item.GetUrlChain()),
172 referrer_url_(item.GetReferrerUrl()), 173 referrer_url_(item.GetReferrerUrl()),
173 callback_(callback), 174 callback_(callback),
174 ui_manager_(ui_manager), 175 ui_manager_(ui_manager),
175 start_time_(base::TimeTicks::Now()), 176 start_time_(base::TimeTicks::Now()),
176 total_type_(total_type), 177 total_type_(total_type),
177 dangerous_type_(dangerous_type) { 178 dangerous_type_(dangerous_type) {
178 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); 179 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext());
179 is_extended_reporting_ = profile && 180 is_extended_reporting_ =
180 profile->GetPrefs()->GetBoolean( 181 profile && IsExtendedReportingEnabled(*profile->GetPrefs());
181 prefs::kSafeBrowsingExtendedReportingEnabled);
182 } 182 }
183 183
184 virtual void StartCheck() = 0; 184 virtual void StartCheck() = 0;
185 virtual bool IsDangerous(SBThreatType threat_type) const = 0; 185 virtual bool IsDangerous(SBThreatType threat_type) const = 0;
186 186
187 protected: 187 protected:
188 friend class base::RefCountedThreadSafe<DownloadSBClient>; 188 friend class base::RefCountedThreadSafe<DownloadSBClient>;
189 ~DownloadSBClient() override {} 189 ~DownloadSBClient() override {}
190 190
191 void CheckDone(SBThreatType threat_type) { 191 void CheckDone(SBThreatType threat_type) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 DownloadFileType::SAMPLED_PING; 346 DownloadFileType::SAMPLED_PING;
347 } 347 }
348 348
349 void Start() { 349 void Start() {
350 DVLOG(2) << "Starting SafeBrowsing download check for: " 350 DVLOG(2) << "Starting SafeBrowsing download check for: "
351 << item_->DebugString(true); 351 << item_->DebugString(true);
352 DCHECK_CURRENTLY_ON(BrowserThread::UI); 352 DCHECK_CURRENTLY_ON(BrowserThread::UI);
353 if (item_->GetBrowserContext()) { 353 if (item_->GetBrowserContext()) {
354 Profile* profile = 354 Profile* profile =
355 Profile::FromBrowserContext(item_->GetBrowserContext()); 355 Profile::FromBrowserContext(item_->GetBrowserContext());
356 is_extended_reporting_ = profile && 356 is_extended_reporting_ =
357 profile->GetPrefs()->GetBoolean( 357 profile && IsExtendedReportingEnabled(*profile->GetPrefs());
358 prefs::kSafeBrowsingExtendedReportingEnabled);
359 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); 358 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord();
360 } 359 }
361 360
362 DownloadCheckResultReason reason = REASON_MAX; 361 DownloadCheckResultReason reason = REASON_MAX;
363 if (!IsSupportedDownload( 362 if (!IsSupportedDownload(
364 *item_, item_->GetTargetFilePath(), &reason, &type_)) { 363 *item_, item_->GetTargetFilePath(), &reason, &type_)) {
365 switch (reason) { 364 switch (reason) {
366 case REASON_EMPTY_URL_CHAIN: 365 case REASON_EMPTY_URL_CHAIN:
367 case REASON_INVALID_URL: 366 case REASON_INVALID_URL:
368 case REASON_LOCAL_FILE: 367 case REASON_LOCAL_FILE:
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 DCHECK_CURRENTLY_ON(BrowserThread::UI); 613 DCHECK_CURRENTLY_ON(BrowserThread::UI);
615 DCHECK(item_ == NULL); 614 DCHECK(item_ == NULL);
616 } 615 }
617 616
618 // .zip files that look invalid to Chrome can often be successfully unpacked 617 // .zip files that look invalid to Chrome can often be successfully unpacked
619 // by other archive tools, so they may be a real threat. For that reason, 618 // by other archive tools, so they may be a real threat. For that reason,
620 // we send pings for them if !in_incognito && is_extended_reporting. 619 // we send pings for them if !in_incognito && is_extended_reporting.
621 bool CanReportInvalidArchives() { 620 bool CanReportInvalidArchives() {
622 DCHECK_CURRENTLY_ON(BrowserThread::UI); 621 DCHECK_CURRENTLY_ON(BrowserThread::UI);
623 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext()); 622 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext());
624 if (!profile || 623 if (!profile || !IsExtendedReportingEnabled(*profile->GetPrefs()))
625 !profile->GetPrefs()->GetBoolean(
626 prefs::kSafeBrowsingExtendedReportingEnabled))
627 return false; 624 return false;
628 625
629 return !item_->GetBrowserContext()->IsOffTheRecord(); 626 return !item_->GetBrowserContext()->IsOffTheRecord();
630 } 627 }
631 628
632 void OnFileFeatureExtractionDone() { 629 void OnFileFeatureExtractionDone() {
633 // This can run in any thread, since it just posts more messages. 630 // This can run in any thread, since it just posts more messages.
634 631
635 // TODO(noelutz): DownloadInfo should also contain the IP address of 632 // TODO(noelutz): DownloadInfo should also contain the IP address of
636 // every URL in the redirect chain. We also should check whether the 633 // every URL in the redirect chain. We also should check whether the
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 default_file_path_(default_file_path), 1240 default_file_path_(default_file_path),
1244 alternate_extensions_(alternate_extensions), 1241 alternate_extensions_(alternate_extensions),
1245 callback_(callback), 1242 callback_(callback),
1246 service_(service), 1243 service_(service),
1247 database_manager_(database_manager), 1244 database_manager_(database_manager),
1248 start_time_(base::TimeTicks::Now()), 1245 start_time_(base::TimeTicks::Now()),
1249 supported_path_( 1246 supported_path_(
1250 GetSupportedFilePath(default_file_path, alternate_extensions)), 1247 GetSupportedFilePath(default_file_path, alternate_extensions)),
1251 weakptr_factory_(this) { 1248 weakptr_factory_(this) {
1252 DCHECK(profile); 1249 DCHECK(profile);
1253 is_extended_reporting_ = profile->GetPrefs()->GetBoolean( 1250 is_extended_reporting_ = IsExtendedReportingEnabled(*profile->GetPrefs());
1254 prefs::kSafeBrowsingExtendedReportingEnabled);
1255 } 1251 }
1256 1252
1257 ~PPAPIDownloadRequest() override { 1253 ~PPAPIDownloadRequest() override {
1258 if (fetcher_ && !callback_.is_null()) 1254 if (fetcher_ && !callback_.is_null())
1259 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN); 1255 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN);
1260 } 1256 }
1261 1257
1262 // Start the process of checking the download request. The callback passed as 1258 // Start the process of checking the download request. The callback passed as
1263 // the |callback| parameter to the constructor will be invoked with the result 1259 // the |callback| parameter to the constructor will be invoked with the result
1264 // of the check at some point in the future. 1260 // of the check at some point in the future.
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1781 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1786 GURL url(kDownloadRequestUrl); 1782 GURL url(kDownloadRequestUrl);
1787 std::string api_key = google_apis::GetAPIKey(); 1783 std::string api_key = google_apis::GetAPIKey();
1788 if (!api_key.empty()) 1784 if (!api_key.empty())
1789 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1785 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1790 1786
1791 return url; 1787 return url;
1792 } 1788 }
1793 1789
1794 } // namespace safe_browsing 1790 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698