Index: chrome/browser/safe_browsing/browser_feature_extractor.cc |
diff --git a/chrome/browser/safe_browsing/browser_feature_extractor.cc b/chrome/browser/safe_browsing/browser_feature_extractor.cc |
index 29e70336f998fb1e83251d79f797594e49c23d47..53ab8eb7224f781261369ee1388581dd9811c58b 100644 |
--- a/chrome/browser/safe_browsing/browser_feature_extractor.cc |
+++ b/chrome/browser/safe_browsing/browser_feature_extractor.cc |
@@ -19,7 +19,7 @@ |
#include "chrome/browser/history/history_types.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/safe_browsing/browser_features.h" |
-#include "chrome/browser/safe_browsing/client_side_detection_service.h" |
+#include "chrome/browser/safe_browsing/client_side_detection_host.h" |
#include "chrome/common/safe_browsing/csd.pb.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/navigation_controller.h" |
@@ -132,9 +132,9 @@ static void AddNavigationFeatures( |
BrowserFeatureExtractor::BrowserFeatureExtractor( |
WebContents* tab, |
- ClientSideDetectionService* service) |
+ ClientSideDetectionHost* host) |
: tab_(tab), |
- service_(service), |
+ host_(host), |
weak_factory_(this) { |
DCHECK(tab); |
} |
@@ -230,42 +230,71 @@ void BrowserFeatureExtractor::ExtractFeatures(const BrowseInfo* info, |
} |
void BrowserFeatureExtractor::ExtractMalwareFeatures( |
- const BrowseInfo* info, |
- ClientMalwareRequest* request) { |
+ const BrowseInfo& info, |
+ ClientMalwareRequest* request, |
+ const MalwareDoneCallback& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(request); |
- DCHECK(info); |
DCHECK_EQ(0U, request->url().find("http:")); |
+ DCHECK(!callback.is_null()); |
+ if (callback.is_null()) { |
+ DLOG(ERROR) << "ExtractMalwareFeatures called without a callback object"; |
+ return; |
mattm
2013/10/25 06:28:12
I think remove this, the DCHECK should be fine. Ch
noé
2013/10/28 23:39:26
Done.
mattm
2013/10/29 01:11:47
It looks like you removed the one from the other m
noé
2013/10/31 02:41:12
Removed it in both cases now :).
|
+ } |
+ // Copy the IPs because they might go away before we're done |
+ // checking them against the IP blacklist on the IO thread. |
+ scoped_ptr<IPUrlMap> ips(new IPUrlMap(info.ips.begin(), |
+ info.ips.end())); |
mattm
2013/10/25 06:28:12
If the ips map isn't used by any other functions,
noé
2013/10/28 23:39:26
Done.
|
+ |
+ // IP blacklist lookups have to happen on the IO thread. |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&BrowserFeatureExtractor::StartExtractMalwareFeatures, |
+ weak_factory_.GetWeakPtr(), |
mattm
2013/10/25 06:28:12
weakptrs shouldn't be de-referenced on a different
noé
2013/10/28 23:39:26
Thank you very much for providing that example. T
|
+ base::Passed(&ips), request, callback)); |
+} |
+ |
+static void CallMalwareCallback( |
mattm
2013/10/25 06:28:12
Chromium style is to use anonymous namespaces rath
noé
2013/10/28 23:39:26
Done.
|
+ const BrowserFeatureExtractor::MalwareDoneCallback& callback, |
+ bool success, |
+ ClientMalwareRequest* request) { |
+ callback.Run(success, request); |
+} |
+ |
+void BrowserFeatureExtractor::StartExtractMalwareFeatures( |
mattm
2013/10/25 06:28:12
Maybe name ExtractMalwareFeaturesOnIOThread?
noé
2013/10/28 23:39:26
Done.
|
+ scoped_ptr<IPUrlMap> ips, |
+ ClientMalwareRequest* request, |
+ const MalwareDoneCallback& callback) { |
// get the IPs and urls that match the malware blacklisted IP list. |
- if (service_) { |
- int matched_bad_ips = 0; |
- for (IPUrlMap::const_iterator it = info->ips.begin(); |
- it != info->ips.end(); ++it) { |
- if (service_->IsBadIpAddress(it->first)) { |
- AddMalwareFeature(features::kBadIpFetch + it->first, |
- it->second, 1.0, request); |
- ++matched_bad_ips; |
- // Limit the number of matched bad IPs in one request to control |
- // the request's size |
- if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
- return; |
- } |
+ if (!host_) { |
+ callback.Run(false, request); |
+ return; |
+ } |
+ int matched_bad_ips = 0; |
+ for (IPUrlMap::const_iterator it = ips->begin(); |
+ it != ips->end(); ++it) { |
+ if (host_->IsBadIpAddress(it->first)) { |
+ AddMalwareFeature(features::kBadIpFetch + it->first, |
+ it->second, 1.0, request); |
mattm
2013/10/25 06:28:12
I don't think AddMalwareFeature is threadsafe?
noé
2013/10/28 23:39:26
Can you elaborate why you think it is not thread s
mattm
2013/10/29 01:11:47
Oh, you're right. I missed that the request object
noé
2013/10/31 02:41:12
Done.
|
+ ++matched_bad_ips; |
+ // Limit the number of matched bad IPs in one request to control |
+ // the request's size |
+ if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
+ break; |
} |
} |
} |
+ // We guanteed to the client of this API that the callback was going to |
+ // be called on the UI thread. |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&CallMalwareCallback, callback, true, request)); |
mattm
2013/10/25 06:28:12
You can just do base::Bind(callback, true, request
noé
2013/10/28 23:39:26
Neat!
|
} |
void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( |
const BrowseInfo& info, |
ClientPhishingRequest* request) { |
- if (service_) { |
- for (IPUrlMap::const_iterator it = info.ips.begin(); |
- it != info.ips.end(); ++it) { |
- if (service_->IsBadIpAddress(it->first)) { |
- AddFeature(features::kBadIpFetch + it->first, 1.0, request); |
mattm
2013/10/25 06:28:12
This doesn't exist in the new version, intentional
noé
2013/10/28 23:39:26
Good catch :-). Yes, this is intentional. We don
|
- } |
- } |
- } |
if (info.unsafe_resource.get()) { |
// A SafeBrowsing interstitial was shown for the current URL. |
AddFeature(features::kSafeBrowsingMaliciousUrl + |