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 218 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 virtual 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 virtual 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 virtual 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 virtual ~DownloadUrlSBClient() {} |
263 | 263 |
264 private: | 264 private: |
(...skipping 106 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 virtual 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 virtual 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 678 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 |