Chromium Code Reviews| 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,10 +226,16 @@ |
| 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()) |
| + if (cache_collector_->HasStarted()) { |
|
panayiotis
2011/05/13 21:15:26
drop the { here
kewang
2011/05/16 07:11:51
Done.
|
| return; |
| + } |
| // Add the urls from the DOM to |resources_|. The renderer could be |
| // sending bogus messages, so limit the number of nodes we accept. |
| @@ -246,6 +254,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<std::vector<GURL> > redirects = |
| + redirects_collector_->GetCollectedUrls(); |
| + |
| + for (uint i = 0; i < redirects.size(); ++i) { |
| + AddRedirectUrlList(redirects[i]); |
| + } |
| + |
| + // Call the cache collector |
| cache_collector_->StartCacheCollection( |
| request_context_getter_, |
| &resources_, |
| @@ -253,6 +281,15 @@ |
| NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady)); |
| } |
| +void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + LOG(INFO) << "url list size:" << urls.size(); |
|
panayiotis
2011/05/13 21:15:26
let's drop the logging
kewang
2011/05/16 07:11:51
Done.
|
| + for (uint i = 0; i < urls.size()-1; ++i) { |
| + AddUrl(urls[i], urls[i+1], "", NULL); |
|
panayiotis
2011/05/13 21:15:26
I wonder if we should specify a tagname for these
kewang
2011/05/16 07:11:51
Done.
|
| + LOG(INFO) << "--- adding...." << urls[i]; |
| + } |
| +} |
| + |
| void MalwareDetails::OnCacheCollectionReady() { |
| DVLOG(1) << "OnCacheCollectionReady."; |
| // Add all the urls in our |resources_| maps to the |report_| protocol buffer. |