| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback_old.h" | 9 #include "base/callback_old.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 13 | 13 |
| 14 struct DownloadCreateInfo; | |
| 15 | |
| 16 // This is a helper class used by DownloadManager to check a download URL with | 14 // This is a helper class used by DownloadManager to check a download URL with |
| 17 // SafeBrowsingService. The client is refcounted and will be released once | 15 // SafeBrowsingService. The client is refcounted and will be released once |
| 18 // there is no reference to it. | 16 // there is no reference to it. |
| 19 // Usage: | 17 // Usage: |
| 20 // { | 18 // { |
| 21 // scoped_refptr<DownloadSBClient> client_ = new DownloadSBClient(...); | 19 // scoped_refptr<DownloadSBClient> client_ = new DownloadSBClient(...); |
| 22 // client_->CheckDownloadUrl(..., NewCallback(this, | 20 // client_->CheckDownloadUrl(..., NewCallback(this, |
| 23 // &DownloadManager::UrlCallBack)); | 21 // &DownloadManager::UrlCallBack)); |
| 24 // or | 22 // or |
| 25 // client_->CheckDownloadHash(..., NewCallback(this, | 23 // client_->CheckDownloadHash(..., NewCallback(this, |
| 26 // &DownloadManager::HashCallBack)); | 24 // &DownloadManager::HashCallBack)); |
| 27 // } | 25 // } |
| 28 // DownloadManager::UrlCallBack(...) or HashCallCall { | 26 // DownloadManager::UrlCallBack(...) or HashCallCall { |
| 29 // // After this, the |client_| is gone. | 27 // // After this, the |client_| is gone. |
| 30 // } | 28 // } |
| 31 class DownloadSBClient | 29 class DownloadSBClient |
| 32 : public SafeBrowsingService::Client, | 30 : public SafeBrowsingService::Client, |
| 33 public base::RefCountedThreadSafe<DownloadSBClient> { | 31 public base::RefCountedThreadSafe<DownloadSBClient> { |
| 34 public: | 32 public: |
| 35 typedef Callback2<DownloadCreateInfo*, bool>::Type UrlDoneCallback; | 33 typedef Callback2<int32, bool>::Type UrlDoneCallback; |
| 36 typedef Callback2<int32, bool>::Type HashDoneCallback; | 34 typedef Callback2<int32, bool>::Type HashDoneCallback; |
| 37 | 35 |
| 38 DownloadSBClient(int32 download_id, | 36 DownloadSBClient(int32 download_id, |
| 39 const std::vector<GURL>& url_chain, | 37 const std::vector<GURL>& url_chain, |
| 40 const GURL& referrer_url); | 38 const GURL& referrer_url); |
| 41 | 39 |
| 42 // Call safebrowsing service to verifiy the download. | 40 // Call safebrowsing service to verifiy the download. |
| 43 // For each DownloadSBClient instance, either CheckDownloadUrl or | 41 // For each DownloadSBClient instance, either CheckDownloadUrl or |
| 44 // CheckDownloadHash can be called, and be called only once. | 42 // CheckDownloadHash can be called, and be called only once. |
| 45 // DownloadSBClient instance. | 43 // DownloadSBClient instance. |
| 46 void CheckDownloadUrl(DownloadCreateInfo* info, UrlDoneCallback* callback); | 44 void CheckDownloadUrl(UrlDoneCallback* callback); |
| 47 void CheckDownloadHash(const std::string& hash, HashDoneCallback* callback); | 45 void CheckDownloadHash(const std::string& hash, HashDoneCallback* callback); |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 // Call SafeBrowsingService on IO thread to verify the download URL or | 48 // Call SafeBrowsingService on IO thread to verify the download URL or |
| 51 // hash of downloaded file. | 49 // hash of downloaded file. |
| 52 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain); | 50 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain); |
| 53 void CheckDownloadHashOnIOThread(const std::string& hash); | 51 void CheckDownloadHashOnIOThread(const std::string& hash); |
| 54 | 52 |
| 55 // Callback interfaces for SafeBrowsingService::Client. | 53 // Callback interfaces for SafeBrowsingService::Client. |
| 56 virtual void OnDownloadUrlCheckResult( | 54 virtual void OnDownloadUrlCheckResult( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 | 82 |
| 85 // Report malware hits to safebrowsing service. | 83 // Report malware hits to safebrowsing service. |
| 86 void ReportMalware(SafeBrowsingService::UrlCheckResult result); | 84 void ReportMalware(SafeBrowsingService::UrlCheckResult result); |
| 87 | 85 |
| 88 // Update the UMA stats. | 86 // Update the UMA stats. |
| 89 void UpdateDownloadCheckStats(SBStatsType stat_type); | 87 void UpdateDownloadCheckStats(SBStatsType stat_type); |
| 90 | 88 |
| 91 scoped_ptr<UrlDoneCallback> url_done_callback_; | 89 scoped_ptr<UrlDoneCallback> url_done_callback_; |
| 92 scoped_ptr<HashDoneCallback> hash_done_callback_; | 90 scoped_ptr<HashDoneCallback> hash_done_callback_; |
| 93 | 91 |
| 94 // Not owned by this class. | |
| 95 DownloadCreateInfo* info_; | |
| 96 | |
| 97 int32 download_id_; | 92 int32 download_id_; |
| 98 scoped_refptr<SafeBrowsingService> sb_service_; | 93 scoped_refptr<SafeBrowsingService> sb_service_; |
| 99 | 94 |
| 100 // These URLs are used to report malware to safe browsing service. | 95 // These URLs are used to report malware to safe browsing service. |
| 101 std::vector<GURL> url_chain_; | 96 std::vector<GURL> url_chain_; |
| 102 GURL referrer_url_; | 97 GURL referrer_url_; |
| 103 | 98 |
| 104 // When a safebrowsing check starts, for stats purpose. | 99 // When a safebrowsing check starts, for stats purpose. |
| 105 base::TimeTicks start_time_; | 100 base::TimeTicks start_time_; |
| 106 | 101 |
| 107 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); | 102 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); |
| 108 }; | 103 }; |
| 109 | 104 |
| 110 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ | 105 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SAFE_BROWSING_CLIENT_H_ |
| OLD | NEW |