| 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/remote_database_manager.h" | 5 #include "components/safe_browsing_db/remote_database_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
| 13 #include "chrome/browser/safe_browsing/safe_browsing_api_handler.h" | 13 #include "components/safe_browsing_db/safe_browsing_api_handler.h" |
| 14 #include "components/variations/variations_associated_data.h" | 14 #include "components/variations/variations_associated_data.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Android field trial for controlling types_to_check. | 21 // Android field trial for controlling types_to_check. |
| 22 const char kAndroidFieldExperiment[] = "SafeBrowsingAndroid"; | 22 const char kAndroidFieldExperiment[] = "SafeBrowsingAndroid"; |
| 23 const char kAndroidTypesToCheckParam[] = "types_to_check"; | 23 const char kAndroidTypesToCheckParam[] = "types_to_check"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 RemoteSafeBrowsingDatabaseManager* db_manager_; | 53 RemoteSafeBrowsingDatabaseManager* db_manager_; |
| 54 GURL url_; | 54 GURL url_; |
| 55 base::ElapsedTimer timer_; | 55 base::ElapsedTimer timer_; |
| 56 base::WeakPtrFactory<ClientRequest> weak_factory_; | 56 base::WeakPtrFactory<ClientRequest> weak_factory_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 RemoteSafeBrowsingDatabaseManager::ClientRequest::ClientRequest( | 59 RemoteSafeBrowsingDatabaseManager::ClientRequest::ClientRequest( |
| 60 Client* client, | 60 Client* client, |
| 61 RemoteSafeBrowsingDatabaseManager* db_manager, | 61 RemoteSafeBrowsingDatabaseManager* db_manager, |
| 62 const GURL& url) | 62 const GURL& url) |
| 63 : client_(client), db_manager_(db_manager), url_(url), weak_factory_(this) { | 63 : client_(client), |
| 64 } | 64 db_manager_(db_manager), |
| 65 url_(url), |
| 66 weak_factory_(this) {} |
| 65 | 67 |
| 66 // Static | 68 // Static |
| 67 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDoneWeak( | 69 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDoneWeak( |
| 68 const base::WeakPtr<ClientRequest>& req, | 70 const base::WeakPtr<ClientRequest>& req, |
| 69 SBThreatType matched_threat_type, | 71 SBThreatType matched_threat_type, |
| 70 const std::string& metadata) { | 72 const std::string& metadata) { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 72 if (!req) | 74 if (!req) |
| 73 return; // Previously canceled | 75 return; // Previously canceled |
| 74 req->OnRequestDone(matched_threat_type, metadata); | 76 req->OnRequestDone(matched_threat_type, metadata); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 bool RemoteSafeBrowsingDatabaseManager::CanCheckResourceType( | 153 bool RemoteSafeBrowsingDatabaseManager::CanCheckResourceType( |
| 152 content::ResourceType resource_type) const { | 154 content::ResourceType resource_type) const { |
| 153 return resource_types_to_check_.count(resource_type) > 0; | 155 return resource_types_to_check_.count(resource_type) > 0; |
| 154 } | 156 } |
| 155 | 157 |
| 156 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { | 158 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { |
| 157 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || | 159 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || |
| 158 url.SchemeIs(url::kFtpScheme); | 160 url.SchemeIs(url::kFtpScheme); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled() | 163 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled() const { |
| 162 const { | |
| 163 return false; | 164 return false; |
| 164 } | 165 } |
| 165 | 166 |
| 166 bool RemoteSafeBrowsingDatabaseManager::CheckDownloadUrl( | 167 bool RemoteSafeBrowsingDatabaseManager::CheckDownloadUrl( |
| 167 const std::vector<GURL>& url_chain, | 168 const std::vector<GURL>& url_chain, |
| 168 Client* client) { | 169 Client* client) { |
| 169 NOTREACHED(); | 170 NOTREACHED(); |
| 170 return true; | 171 return true; |
| 171 } | 172 } |
| 172 | 173 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // |current_requests_|, so we make a copy first. | 277 // |current_requests_|, so we make a copy first. |
| 277 std::vector<ClientRequest*> to_callback(current_requests_); | 278 std::vector<ClientRequest*> to_callback(current_requests_); |
| 278 for (auto req : to_callback) { | 279 for (auto req : to_callback) { |
| 279 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); | 280 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); |
| 280 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); | 281 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); |
| 281 } | 282 } |
| 282 enabled_ = false; | 283 enabled_ = false; |
| 283 } | 284 } |
| 284 | 285 |
| 285 } // namespace safe_browsing | 286 } // namespace safe_browsing |
| OLD | NEW |