Chromium Code Reviews| Index: chrome/browser/safe_browsing/malware_details_history.cc |
| =================================================================== |
| --- chrome/browser/safe_browsing/malware_details_history.cc (revision 0) |
| +++ chrome/browser/safe_browsing/malware_details_history.cc (revision 0) |
| @@ -0,0 +1,123 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// Implementation of the MalwareDetailsRedirectsCollector class. |
| + |
| +#include "chrome/browser/safe_browsing/malware_details_history.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/safe_browsing/malware_details.h" |
| +#include "content/browser/browser_thread.h" |
| +#include "content/browser/renderer_host/render_view_host.h" |
| +#include "content/browser/tab_contents/navigation_entry.h" |
| +#include "content/browser/tab_contents/tab_contents.h" |
| + |
| + |
| +MalwareDetailsRedirectsCollector::MalwareDetailsRedirectsCollector() |
| + : history_(NULL), |
| + has_started_(false) { |
| + request_consumer_ = new CancelableRequestConsumer(); |
|
mattm
2011/05/18 22:31:47
This will still be leaked. It should be a non-poi
kewang
2011/05/19 06:03:10
Done.
|
| +} |
| + |
| +MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() { |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::StartHistoryCollection( |
| + const std::vector<GURL>& urls, |
| + TabContents* tab_contents, |
| + Task* callback) { |
| + LOG(INFO) << "Num of urls: " << urls.size(); |
| + tab_contents_ = tab_contents; |
| + has_started_ = true; |
| + callback_ = callback; |
| + |
| + if (urls.size() == 0) { |
| + AllDone(); |
| + return; |
| + } |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + NewRunnableMethod( |
| + this, &MalwareDetailsRedirectsCollector::StartGetRedirects, urls)); |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::StartGetRedirects( |
| + const std::vector<GURL>& urls) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + // History access from profile need to happen in UI thread |
| + if (history_ == NULL) { |
| + LOG(INFO) << "Getting access to history service"; |
| + history_ = tab_contents_->profile()->GetHistoryService( |
| + Profile::EXPLICIT_ACCESS); |
| + } |
| + |
| + if (history_ == NULL) { |
| + LOG(INFO) << "Could not access history service."; |
| + AllDone(); |
| + return; |
| + } |
| + |
| + for (size_t i = 0; i < urls.size(); ++i) |
| + urls_.push_back(urls[i]); |
| + urls_it_ = urls_.begin(); |
| + |
| + GetRedirects(*urls_it_); |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + history_->QueryRedirectsTo( |
| + url, |
| + request_consumer_, |
| + NewCallback(this, |
| + &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo)); |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo( |
| + HistoryService::Handle handle, |
| + GURL url, |
| + bool success, |
| + history::RedirectList* redirect_list) { |
| + |
| + if (success && redirect_list->size() > 0) { |
| + std::vector<GURL> urllist; |
| + urllist.push_back(url); |
| + for (size_t i = 0; i < redirect_list->size(); i++) { |
| + urllist.push_back(redirect_list->at(i)); |
| + } |
| + redirects_urls_.push_back(urllist); |
| + } |
| + |
| + // Proceed to next url |
| + ++urls_it_; |
| + |
| + if (urls_it_ == urls_.end()) { |
| + AllDone(); |
| + return; |
| + } |
| + |
| + GetRedirects(*urls_it_); |
| +} |
| + |
| +bool MalwareDetailsRedirectsCollector::HasStarted() const { |
| + return has_started_; |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::AllDone() { |
| + DVLOG(1) << "AllDone"; |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
| +} |
| + |
| +const std::vector<safe_browsing::RedirectChain>& |
| +MalwareDetailsRedirectsCollector::GetCollectedUrls() const { |
| + return redirects_urls_; |
| +} |
| + |
| +void MalwareDetailsRedirectsCollector::SetHistory(HistoryService* history) { |
| + history_ = history; |
| +} |
| + |
| Property changes on: chrome/browser/safe_browsing/malware_details_history.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |