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

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
mattm 2011/05/17 03:17:01 The HistoryService class comment says it is thread
kewang 2011/05/18 05:47:40 yes, when access history service from profile, it
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)
mattm 2011/05/17 03:17:01 size_t (other places too)
kewang 2011/05/18 05:47:40 Done.
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 CancelableRequestConsumer* request_consumer =
73 new CancelableRequestConsumer();
mattm 2011/05/17 03:17:01 This will be leaked. It should be a class member.
kewang 2011/05/18 05:47:40 Done.
74
75 history_->QueryRedirectsTo(
76 url,
77 request_consumer,
78 NewCallback(this,
79 &MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo));
80 }
81
82 void MalwareDetailsRedirectsCollector::OnGotQueryRedirectsTo(
83 HistoryService::Handle handle,
84 GURL url,
85 bool success,
86 history::RedirectList* redirect_list) {
87
88 if (success && redirect_list->size() > 0) {
mattm 2011/05/17 03:17:01 wrong indentation
kewang 2011/05/18 05:47:40 Done.
89 std::vector<GURL> urllist;
90 urllist.push_back(url);
91 for (uint i = 0; i < redirect_list->size(); i++) {
92 urllist.push_back(redirect_list->at(i));
93 }
94 redirects_urls_.push_back(urllist);
95 }
96
97 // Proceed to next url
98 ++urls_it_;
99
100 if (urls_it_ == urls_.end()) {
101 AllDone();
102 return;
103 }
104
105 GetRedirects(*urls_it_);
106 }
107
108 bool MalwareDetailsRedirectsCollector::HasStarted() {
109 return has_started_;
110 }
111
112 void MalwareDetailsRedirectsCollector::AllDone() {
113 DVLOG(1) << "AllDone";
114 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
115 }
116
117 std::vector<safe_browsing::RedirectChain>*
118 MalwareDetailsRedirectsCollector::GetCollectedUrls() {
119 return &redirects_urls_;
120 }
121
122 void MalwareDetailsRedirectsCollector::SetHistory(HistoryService* history) {
123 history_ = history;
124 }
125
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698