Index: chrome/browser/safe_browsing/malware_details.cc |
=================================================================== |
--- chrome/browser/safe_browsing/malware_details.cc (revision 84048) |
+++ chrome/browser/safe_browsing/malware_details.cc (working copy) |
@@ -11,6 +11,7 @@ |
#include "chrome/browser/net/chrome_url_request_context.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/safe_browsing/malware_details_cache.h" |
+#include "chrome/browser/safe_browsing/malware_details_history.h" |
#include "chrome/browser/safe_browsing/report.pb.h" |
#include "chrome/browser/safe_browsing/safe_browsing_service.h" |
#include "chrome/common/safe_browsing/safebrowsing_messages.h" |
@@ -76,7 +77,8 @@ |
request_context_getter_(tab_contents->profile()->GetRequestContext()), |
sb_service_(sb_service), |
resource_(resource), |
- cache_collector_(new MalwareDetailsCacheCollector) { |
+ cache_collector_(new MalwareDetailsCacheCollector), |
+ redirects_collector_(new MalwareDetailsRedirectsCollector) { |
StartCollection(); |
} |
@@ -224,6 +226,11 @@ |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
DVLOG(1) << "Nodes from the DOM: " << params.size(); |
+ // If we have already started getting redirects from history service, |
+ // don't modify state, otherwise will invalidate the iterators. |
+ if (redirects_collector_->HasStarted()) |
+ return; |
+ |
// If we have already started collecting data from the HTTP cache, don't |
// modify our state. |
if (cache_collector_->HasStarted()) |
@@ -246,6 +253,26 @@ |
void MalwareDetails::FinishCollection() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ std::vector<GURL> urls; |
+ for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); |
+ it != resources_.end(); it++) { |
+ urls.push_back(GURL(it->first)); |
+ } |
+ redirects_collector_->StartHistoryCollection( |
+ urls, tab_contents(), |
+ NewRunnableMethod(this, &MalwareDetails::OnRedirectionCollectionReady)); |
+} |
+ |
+void MalwareDetails::OnRedirectionCollectionReady() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ std::vector<safe_browsing::RedirectChain>* redirects = |
+ redirects_collector_->GetCollectedUrls(); |
+ |
+ for (std::vector<safe_browsing::RedirectChain>::const_iterator it |
+ = redirects->begin(); it != redirects->end(); ++it) |
+ AddRedirectUrlList(*it); |
+ |
+ // Call the cache collector |
cache_collector_->StartCacheCollection( |
request_context_getter_, |
&resources_, |
@@ -253,6 +280,14 @@ |
NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady)); |
} |
+void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ for (uint i = 0; i < urls.size()-1; ++i) { |
mattm
2011/05/17 03:17:01
size_t
kewang
2011/05/18 05:47:40
Done.
|
+ AddUrl(urls[i], urls[i+1], "redir", NULL); |
mattm
2011/05/17 03:17:01
"redir" should be a const. Also, other places jus
panayiotis
2011/05/17 17:19:48
Actually I take it back, let's not add any tagname
kewang
2011/05/18 05:47:40
const added. We are using it for all the redir url
kewang
2011/05/18 05:47:40
Followed Pano's suggestion and removed it.
|
+ LOG(INFO) << "--- adding...." << urls[i]; |
panayiotis
2011/05/16 17:14:55
drop the log infos ...
kewang
2011/05/18 05:47:40
Done.
|
+ } |
+} |
+ |
void MalwareDetails::OnCacheCollectionReady() { |
DVLOG(1) << "OnCacheCollectionReady."; |
// Add all the urls in our |resources_| maps to the |report_| protocol buffer. |