Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3539)

Unified Diff: chrome/browser/safe_browsing/malware_details_history.cc

Issue 6710004: Querying the history service to get the redirect information for urls.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,126 @@
+// 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) {
+}
+
+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 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 (uint i = 0; i < urls.size(); ++i)
+ urls_.push_back(urls[i]);
+ urls_it_ = urls_.begin();
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
panayiotis 2011/05/13 21:15:26 we are already in the UI thread, no need to post a
kewang 2011/05/16 07:11:51 Yes, absolutely. Moved from old code and didn't im
+ NewRunnableMethod(
+ this, &MalwareDetailsRedirectsCollector::GetRedirects, *urls_it_));
+}
+
+void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ CancelableRequestConsumer* request_consumer =
+ new CancelableRequestConsumer();
+
+ 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 (uint 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;
+ }
+
+ BrowserThread::PostTask(
panayiotis 2011/05/13 21:15:26 same here, unless you are posting a task so that w
kewang 2011/05/16 07:11:51 Done.
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &MalwareDetailsRedirectsCollector::GetRedirects, *urls_it_));
+}
+
+bool MalwareDetailsRedirectsCollector::HasStarted() {
+ return has_started_;
+}
+
+void MalwareDetailsRedirectsCollector::AllDone() {
+ DVLOG(1) << "AllDone";
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
+}
+
+std::vector<std::vector<GURL> >
+MalwareDetailsRedirectsCollector::GetCollectedUrls() {
+ return redirects_urls_;
+}
Property changes on: chrome/browser/safe_browsing/malware_details_history.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698