OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ui_manager_(ui_manager), | 159 ui_manager_(ui_manager), |
160 start_time_(base::TimeTicks::Now()), | 160 start_time_(base::TimeTicks::Now()), |
161 total_type_(total_type), | 161 total_type_(total_type), |
162 dangerous_type_(dangerous_type) {} | 162 dangerous_type_(dangerous_type) {} |
163 | 163 |
164 virtual void StartCheck() = 0; | 164 virtual void StartCheck() = 0; |
165 virtual bool IsDangerous(SBThreatType threat_type) const = 0; | 165 virtual bool IsDangerous(SBThreatType threat_type) const = 0; |
166 | 166 |
167 protected: | 167 protected: |
168 friend class base::RefCountedThreadSafe<DownloadSBClient>; | 168 friend class base::RefCountedThreadSafe<DownloadSBClient>; |
169 virtual ~DownloadSBClient() {} | 169 ~DownloadSBClient() override {} |
170 | 170 |
171 void CheckDone(SBThreatType threat_type) { | 171 void CheckDone(SBThreatType threat_type) { |
172 DownloadProtectionService::DownloadCheckResult result = | 172 DownloadProtectionService::DownloadCheckResult result = |
173 IsDangerous(threat_type) ? | 173 IsDangerous(threat_type) ? |
174 DownloadProtectionService::DANGEROUS : | 174 DownloadProtectionService::DANGEROUS : |
175 DownloadProtectionService::SAFE; | 175 DownloadProtectionService::SAFE; |
176 BrowserThread::PostTask(BrowserThread::UI, | 176 BrowserThread::PostTask(BrowserThread::UI, |
177 FROM_HERE, | 177 FROM_HERE, |
178 base::Bind(callback_, result)); | 178 base::Bind(callback_, result)); |
179 UpdateDownloadCheckStats(total_type_); | 179 UpdateDownloadCheckStats(total_type_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 DownloadUrlSBClient( | 229 DownloadUrlSBClient( |
230 const content::DownloadItem& item, | 230 const content::DownloadItem& item, |
231 const DownloadProtectionService::CheckDownloadCallback& callback, | 231 const DownloadProtectionService::CheckDownloadCallback& callback, |
232 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, | 232 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, |
233 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) | 233 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) |
234 : DownloadSBClient(item, callback, ui_manager, | 234 : DownloadSBClient(item, callback, ui_manager, |
235 DOWNLOAD_URL_CHECKS_TOTAL, | 235 DOWNLOAD_URL_CHECKS_TOTAL, |
236 DOWNLOAD_URL_CHECKS_MALWARE), | 236 DOWNLOAD_URL_CHECKS_MALWARE), |
237 database_manager_(database_manager) { } | 237 database_manager_(database_manager) { } |
238 | 238 |
239 virtual void StartCheck() override { | 239 void StartCheck() override { |
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
241 if (!database_manager_.get() || | 241 if (!database_manager_.get() || |
242 database_manager_->CheckDownloadUrl(url_chain_, this)) { | 242 database_manager_->CheckDownloadUrl(url_chain_, this)) { |
243 CheckDone(SB_THREAT_TYPE_SAFE); | 243 CheckDone(SB_THREAT_TYPE_SAFE); |
244 } else { | 244 } else { |
245 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr. | 245 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr. |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 virtual bool IsDangerous(SBThreatType threat_type) const override { | 249 bool IsDangerous(SBThreatType threat_type) const override { |
250 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL; | 250 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL; |
251 } | 251 } |
252 | 252 |
253 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, | 253 void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, |
254 SBThreatType threat_type) override { | 254 SBThreatType threat_type) override { |
255 CheckDone(threat_type); | 255 CheckDone(threat_type); |
256 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", | 256 UMA_HISTOGRAM_TIMES("SB2.DownloadUrlCheckDuration", |
257 base::TimeTicks::Now() - start_time_); | 257 base::TimeTicks::Now() - start_time_); |
258 Release(); | 258 Release(); |
259 } | 259 } |
260 | 260 |
261 protected: | 261 protected: |
262 virtual ~DownloadUrlSBClient() {} | 262 ~DownloadUrlSBClient() override {} |
263 | 263 |
264 private: | 264 private: |
265 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 265 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
266 | 266 |
267 DISALLOW_COPY_AND_ASSIGN(DownloadUrlSBClient); | 267 DISALLOW_COPY_AND_ASSIGN(DownloadUrlSBClient); |
268 }; | 268 }; |
269 | 269 |
270 class DownloadProtectionService::CheckClientDownloadRequest | 270 class DownloadProtectionService::CheckClientDownloadRequest |
271 : public base::RefCountedThreadSafe< | 271 : public base::RefCountedThreadSafe< |
272 DownloadProtectionService::CheckClientDownloadRequest, | 272 DownloadProtectionService::CheckClientDownloadRequest, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // Note: If there is no fetcher, then some callback is still holding a | 371 // Note: If there is no fetcher, then some callback is still holding a |
372 // reference to this object. We'll eventually wind up in some method on | 372 // reference to this object. We'll eventually wind up in some method on |
373 // the UI thread that will call FinishRequest() again. If FinishRequest() | 373 // the UI thread that will call FinishRequest() again. If FinishRequest() |
374 // is called a second time, it will be a no-op. | 374 // is called a second time, it will be a no-op. |
375 FinishRequest(UNKNOWN, REASON_REQUEST_CANCELED); | 375 FinishRequest(UNKNOWN, REASON_REQUEST_CANCELED); |
376 // Calling FinishRequest might delete this object, we may be deleted by | 376 // Calling FinishRequest might delete this object, we may be deleted by |
377 // this point. | 377 // this point. |
378 } | 378 } |
379 | 379 |
380 // content::DownloadItem::Observer implementation. | 380 // content::DownloadItem::Observer implementation. |
381 virtual void OnDownloadDestroyed(content::DownloadItem* download) override { | 381 void OnDownloadDestroyed(content::DownloadItem* download) override { |
382 Cancel(); | 382 Cancel(); |
383 DCHECK(item_ == NULL); | 383 DCHECK(item_ == NULL); |
384 } | 384 } |
385 | 385 |
386 // From the net::URLFetcherDelegate interface. | 386 // From the net::URLFetcherDelegate interface. |
387 virtual void OnURLFetchComplete(const net::URLFetcher* source) override { | 387 void OnURLFetchComplete(const net::URLFetcher* source) override { |
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
389 DCHECK_EQ(source, fetcher_.get()); | 389 DCHECK_EQ(source, fetcher_.get()); |
390 VLOG(2) << "Received a response for URL: " | 390 VLOG(2) << "Received a response for URL: " |
391 << item_->GetUrlChain().back() << ": success=" | 391 << item_->GetUrlChain().back() << ": success=" |
392 << source->GetStatus().is_success() << " response_code=" | 392 << source->GetStatus().is_success() << " response_code=" |
393 << source->GetResponseCode(); | 393 << source->GetResponseCode(); |
394 if (source->GetStatus().is_success()) { | 394 if (source->GetStatus().is_success()) { |
395 UMA_HISTOGRAM_SPARSE_SLOWLY( | 395 UMA_HISTOGRAM_SPARSE_SLOWLY( |
396 "SBClientDownload.DownloadRequestResponseCode", | 396 "SBClientDownload.DownloadRequestResponseCode", |
397 source->GetResponseCode()); | 397 source->GetResponseCode()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return false; | 472 return false; |
473 } | 473 } |
474 *type = download_protection_util::GetDownloadType(target_path); | 474 *type = download_protection_util::GetDownloadType(target_path); |
475 return true; | 475 return true; |
476 } | 476 } |
477 | 477 |
478 private: | 478 private: |
479 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 479 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
480 friend class base::DeleteHelper<CheckClientDownloadRequest>; | 480 friend class base::DeleteHelper<CheckClientDownloadRequest>; |
481 | 481 |
482 virtual ~CheckClientDownloadRequest() { | 482 ~CheckClientDownloadRequest() override { |
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
484 DCHECK(item_ == NULL); | 484 DCHECK(item_ == NULL); |
485 } | 485 } |
486 | 486 |
487 void OnFileFeatureExtractionDone() { | 487 void OnFileFeatureExtractionDone() { |
488 // This can run in any thread, since it just posts more messages. | 488 // This can run in any thread, since it just posts more messages. |
489 | 489 |
490 // TODO(noelutz): DownloadInfo should also contain the IP address of | 490 // TODO(noelutz): DownloadInfo should also contain the IP address of |
491 // every URL in the redirect chain. We also should check whether the | 491 // every URL in the redirect chain. We also should check whether the |
492 // download URL is hosted on the internal network. | 492 // download URL is hosted on the internal network. |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1076 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
1077 GURL url(kDownloadRequestUrl); | 1077 GURL url(kDownloadRequestUrl); |
1078 std::string api_key = google_apis::GetAPIKey(); | 1078 std::string api_key = google_apis::GetAPIKey(); |
1079 if (!api_key.empty()) | 1079 if (!api_key.empty()) |
1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1080 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
1081 | 1081 |
1082 return url; | 1082 return url; |
1083 } | 1083 } |
1084 | 1084 |
1085 } // namespace safe_browsing | 1085 } // namespace safe_browsing |
OLD | NEW |