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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Implementation of the MalwareDetailsRedirectsCollector class.
6
7 #include "chrome/browser/safe_browsing/malware_details_history.h"
8
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/malware_details.h"
11 #include "content/browser/browser_thread.h"
12 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/tab_contents/navigation_entry.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15
16
17 MalwareDetailsRedirectsCollector::MalwareDetailsRedirectsCollector()
18 : history_(NULL),
19 has_started_(false) {
20 }
21
22 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() {
23 }
24
25 void MalwareDetailsRedirectsCollector::StartHistoryCollection(
26 const std::vector<GURL>& urls,
27 TabContents* tab_contents,
28 Task* callback) {
29 DVLOG(1) << "Num of urls to check in history service: " << urls.size();
30 tab_contents_ = tab_contents;
31 has_started_ = true;
32 callback_ = callback;
33
34 if (urls.size() == 0) {
35 AllDone();
36 return;
37 }
38
39 BrowserThread::PostTask(
40 BrowserThread::UI, FROM_HERE,
41 NewRunnableMethod(
42 this, &MalwareDetailsRedirectsCollector::StartGetRedirects, urls));
43 }
44
45 void MalwareDetailsRedirectsCollector::StartGetRedirects(
46 const std::vector<GURL>& urls) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48
49 // History access from profile needs to happen in UI thread
50 if (history_ == NULL) {
51 DVLOG(1) << "Getting access to history service";
52 history_ = tab_contents_->profile()->GetHistoryService(
53 Profile::EXPLICIT_ACCESS);
54 }
55
56 if (history_ == NULL) {
57 DVLOG(1) << "Could not access history service.";
58 AllDone();
59 return;
60 }
61
62 for (size_t i = 0; i < urls.size(); ++i)
63 urls_.push_back(urls[i]);
64
65 urls_it_ = urls_.begin();
66 GetRedirects(*urls_it_);
67 }
68
69 void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71
72 history_->QueryRedirectsTo(
73 url,
74 &request_consumer_,
75 NewCallback(this,
76 &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo));
77 }
78
79 void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo(
80 HistoryService::Handle handle,
81 GURL url,
82 bool success,
83 history::RedirectList* redirect_list) {
84
85 if (success && redirect_list->size() > 0) {
86 std::vector<GURL> urllist;
87 urllist.push_back(url);
88 for (size_t i = 0; i < redirect_list->size(); i++) {
89 urllist.push_back(redirect_list->at(i));
90 }
91 redirects_urls_.push_back(urllist);
92 }
93
94 // Proceed to next url
95 ++urls_it_;
96
97 if (urls_it_ == urls_.end()) {
98 AllDone();
99 return;
100 }
101
102 GetRedirects(*urls_it_);
103 }
104
105 bool MalwareDetailsRedirectsCollector::HasStarted() const {
106 return has_started_;
107 }
108
109 void MalwareDetailsRedirectsCollector::AllDone() {
110 DVLOG(1) << "AllDone";
111 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
112 }
113
114 const std::vector<safe_browsing::RedirectChain>&
115 MalwareDetailsRedirectsCollector::GetCollectedUrls() const {
116 return redirects_urls_;
117 }
118
119 void MalwareDetailsRedirectsCollector::SetHistory(HistoryService* history) {
120 history_ = history;
121 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details_history.h ('k') | chrome/browser/safe_browsing/malware_details_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698