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

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 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.
21 }
22
23 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() {
24 }
25
26 void MalwareDetailsRedirectsCollector::StartHistoryCollection(
27 const std::vector<GURL>& urls,
28 TabContents* tab_contents,
29 Task* callback) {
30 LOG(INFO) << "Num of urls: " << urls.size();
31 tab_contents_ = tab_contents;
32 has_started_ = true;
33 callback_ = callback;
34
35 if (urls.size() == 0) {
36 AllDone();
37 return;
38 }
39
40 BrowserThread::PostTask(
41 BrowserThread::UI, FROM_HERE,
42 NewRunnableMethod(
43 this, &MalwareDetailsRedirectsCollector::StartGetRedirects, urls));
44 }
45
46 void MalwareDetailsRedirectsCollector::StartGetRedirects(
47 const std::vector<GURL>& urls) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49
50 // History access from profile need to happen in UI thread
51 if (history_ == NULL) {
52 LOG(INFO) << "Getting access to history service";
53 history_ = tab_contents_->profile()->GetHistoryService(
54 Profile::EXPLICIT_ACCESS);
55 }
56
57 if (history_ == NULL) {
58 LOG(INFO) << "Could not access history service.";
59 AllDone();
60 return;
61 }
62
63 for (size_t i = 0; i < urls.size(); ++i)
64 urls_.push_back(urls[i]);
65 urls_it_ = urls_.begin();
66
67 GetRedirects(*urls_it_);
68 }
69
70 void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72
73 history_->QueryRedirectsTo(
74 url,
75 request_consumer_,
76 NewCallback(this,
77 &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo));
78 }
79
80 void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo(
81 HistoryService::Handle handle,
82 GURL url,
83 bool success,
84 history::RedirectList* redirect_list) {
85
86 if (success && redirect_list->size() > 0) {
87 std::vector<GURL> urllist;
88 urllist.push_back(url);
89 for (size_t i = 0; i < redirect_list->size(); i++) {
90 urllist.push_back(redirect_list->at(i));
91 }
92 redirects_urls_.push_back(urllist);
93 }
94
95 // Proceed to next url
96 ++urls_it_;
97
98 if (urls_it_ == urls_.end()) {
99 AllDone();
100 return;
101 }
102
103 GetRedirects(*urls_it_);
104 }
105
106 bool MalwareDetailsRedirectsCollector::HasStarted() const {
107 return has_started_;
108 }
109
110 void MalwareDetailsRedirectsCollector::AllDone() {
111 DVLOG(1) << "AllDone";
112 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
113 }
114
115 const std::vector<safe_browsing::RedirectChain>&
116 MalwareDetailsRedirectsCollector::GetCollectedUrls() const {
117 return redirects_urls_;
118 }
119
120 void MalwareDetailsRedirectsCollector::SetHistory(HistoryService* history) {
121 history_ = history;
122 }
123
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698