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,25 @@ |
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)); |
+ const std::vector<safe_browsing::RedirectChain>& redirects = |
+ redirects_collector_->GetCollectedUrls(); |
+ |
+ for (size_t i = 0; i < redirects.size(); ++i) |
+ AddRedirectUrlList(redirects[i]); |
+ |
+ // Call the cache collector |
cache_collector_->StartCacheCollection( |
request_context_getter_, |
&resources_, |
@@ -253,6 +279,13 @@ |
NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady)); |
} |
+void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ for (size_t i = 0; i < urls.size()-1; ++i) { |
+ AddUrl(urls[i], urls[i+1], "", NULL); |
+ } |
+} |
+ |
void MalwareDetails::OnCacheCollectionReady() { |
DVLOG(1) << "OnCacheCollectionReady."; |
// Add all the urls in our |resources_| maps to the |report_| protocol buffer. |