|
OLD | NEW |
---|---|
(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 LOG(INFO) << "Num of urls: " << urls.size(); | |
panayiotis
2011/05/19 17:08:37
if you want to keep these logs, maybe we should us
kewang
2011/05/20 03:52:55
Done.
| |
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 need to happen in UI thread | |
panayiotis
2011/05/19 17:08:37
"needs to happen"
kewang
2011/05/20 03:52:55
Done.
| |
50 if (history_ == NULL) { | |
51 LOG(INFO) << "Getting access to history service"; | |
panayiotis
2011/05/19 17:08:37
same here
kewang
2011/05/20 03:52:55
Done.
| |
52 history_ = tab_contents_->profile()->GetHistoryService( | |
53 Profile::EXPLICIT_ACCESS); | |
54 } | |
55 | |
56 if (history_ == NULL) { | |
57 LOG(INFO) << "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 urls_it_ = urls_.begin(); | |
65 | |
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 } | |
OLD | NEW |