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

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 LOG(INFO) << "Num of urls: " << 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 need to happen in UI thread
50 if (history_ == NULL) {
51 LOG(INFO) << "Getting access to history service";
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 (uint i = 0; i < urls.size(); ++i)
63 urls_.push_back(urls[i]);
64 urls_it_ = urls_.begin();
65
66 BrowserThread::PostTask(
67 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
68 NewRunnableMethod(
69 this, &MalwareDetailsRedirectsCollector::GetRedirects, *urls_it_));
70 }
71
72 void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74
75 CancelableRequestConsumer* request_consumer =
76 new CancelableRequestConsumer();
77
78 history_->QueryRedirectsTo(
79 url,
80 request_consumer,
81 NewCallback(this,
82 &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo));
83 }
84
85 void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo(
86 HistoryService::Handle handle,
87 GURL url,
88 bool success,
89 history::RedirectList* redirect_list) {
90
91 if (success && redirect_list->size() > 0) {
92 std::vector<GURL> urllist;
93 urllist.push_back(url);
94 for (uint i = 0; i < redirect_list->size(); i++) {
95 urllist.push_back(redirect_list->at(i));
96 }
97 redirects_urls_.push_back(urllist);
98 }
99
100 // Proceed to next url
101 ++urls_it_;
102
103 if (urls_it_ == urls_.end()) {
104 AllDone();
105 return;
106 }
107
108 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.
109 BrowserThread::UI, FROM_HERE,
110 NewRunnableMethod(
111 this, &MalwareDetailsRedirectsCollector::GetRedirects, *urls_it_));
112 }
113
114 bool MalwareDetailsRedirectsCollector::HasStarted() {
115 return has_started_;
116 }
117
118 void MalwareDetailsRedirectsCollector::AllDone() {
119 DVLOG(1) << "AllDone";
120 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
121 }
122
123 std::vector<std::vector<GURL> >
124 MalwareDetailsRedirectsCollector::GetCollectedUrls() {
125 return redirects_urls_;
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698