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

Side by Side Diff: chrome/browser/safe_browsing/malware_details.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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Implementation of the MalwareDetails class. 5 // Implementation of the MalwareDetails class.
6 6
7 #include "chrome/browser/safe_browsing/malware_details.h" 7 #include "chrome/browser/safe_browsing/malware_details.h"
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "chrome/browser/net/chrome_url_request_context.h" 11 #include "chrome/browser/net/chrome_url_request_context.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/malware_details_cache.h" 13 #include "chrome/browser/safe_browsing/malware_details_cache.h"
14 #include "chrome/browser/safe_browsing/malware_details_history.h"
14 #include "chrome/browser/safe_browsing/report.pb.h" 15 #include "chrome/browser/safe_browsing/report.pb.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 17 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
17 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
18 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/tab_contents/navigation_entry.h" 20 #include "content/browser/tab_contents/navigation_entry.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
21 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
22 #include "net/disk_cache/disk_cache.h" 23 #include "net/disk_cache/disk_cache.h"
23 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 // Create a MalwareDetails for the given tab. Runs in the UI thread. 71 // Create a MalwareDetails for the given tab. Runs in the UI thread.
71 MalwareDetails::MalwareDetails( 72 MalwareDetails::MalwareDetails(
72 SafeBrowsingService* sb_service, 73 SafeBrowsingService* sb_service,
73 TabContents* tab_contents, 74 TabContents* tab_contents,
74 const SafeBrowsingService::UnsafeResource& resource) 75 const SafeBrowsingService::UnsafeResource& resource)
75 : TabContentsObserver(tab_contents), 76 : TabContentsObserver(tab_contents),
76 request_context_getter_(tab_contents->profile()->GetRequestContext()), 77 request_context_getter_(tab_contents->profile()->GetRequestContext()),
77 sb_service_(sb_service), 78 sb_service_(sb_service),
78 resource_(resource), 79 resource_(resource),
79 cache_collector_(new MalwareDetailsCacheCollector) { 80 cache_collector_(new MalwareDetailsCacheCollector),
81 redirects_collector_(new MalwareDetailsRedirectsCollector) {
80 StartCollection(); 82 StartCollection();
81 } 83 }
82 84
83 MalwareDetails::~MalwareDetails() { 85 MalwareDetails::~MalwareDetails() {
84 } 86 }
85 87
86 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) { 88 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) {
87 bool handled = true; 89 bool handled = true;
88 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message) 90 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message)
89 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_MalwareDOMDetails, 91 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_MalwareDOMDetails,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 BrowserThread::IO, FROM_HERE, 219 BrowserThread::IO, FROM_HERE,
218 NewRunnableMethod( 220 NewRunnableMethod(
219 this, &MalwareDetails::AddDOMDetails, params)); 221 this, &MalwareDetails::AddDOMDetails, params));
220 } 222 }
221 223
222 void MalwareDetails::AddDOMDetails( 224 void MalwareDetails::AddDOMDetails(
223 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) { 225 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
225 DVLOG(1) << "Nodes from the DOM: " << params.size(); 227 DVLOG(1) << "Nodes from the DOM: " << params.size();
226 228
229 // If we have already started getting redirects from history service,
230 // don't modify state, otherwise will invalidate the iterators.
231 if (redirects_collector_->HasStarted())
232 return;
233
227 // If we have already started collecting data from the HTTP cache, don't 234 // If we have already started collecting data from the HTTP cache, don't
228 // modify our state. 235 // modify our state.
229 if (cache_collector_->HasStarted()) 236 if (cache_collector_->HasStarted())
230 return; 237 return;
231 238
232 // Add the urls from the DOM to |resources_|. The renderer could be 239 // Add the urls from the DOM to |resources_|. The renderer could be
233 // sending bogus messages, so limit the number of nodes we accept. 240 // sending bogus messages, so limit the number of nodes we accept.
234 for (uint32 i = 0; i < params.size() && i < kMaxDomNodes; ++i) { 241 for (uint32 i = 0; i < params.size() && i < kMaxDomNodes; ++i) {
235 SafeBrowsingHostMsg_MalwareDOMDetails_Node node = params[i]; 242 SafeBrowsingHostMsg_MalwareDOMDetails_Node node = params[i];
236 DVLOG(1) << node.url << ", " << node.tag_name << ", " << node.parent; 243 DVLOG(1) << node.url << ", " << node.tag_name << ", " << node.parent;
237 AddUrl(node.url, node.parent, node.tag_name, &(node.children)); 244 AddUrl(node.url, node.parent, node.tag_name, &(node.children));
238 } 245 }
239 } 246 }
240 247
241 // Called from the SB Service on the IO thread, after the user has 248 // Called from the SB Service on the IO thread, after the user has
242 // closed the tab, or clicked proceed or goback. Since the user needs 249 // closed the tab, or clicked proceed or goback. Since the user needs
243 // to take an action, we expect this to be called after 250 // to take an action, we expect this to be called after
244 // OnReceivedMalwareDOMDetails in most cases. If not, we don't include 251 // OnReceivedMalwareDOMDetails in most cases. If not, we don't include
245 // the DOM data in our report. 252 // the DOM data in our report.
246 void MalwareDetails::FinishCollection() { 253 void MalwareDetails::FinishCollection() {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
248 255
256 std::vector<GURL> urls;
257 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin();
258 it != resources_.end(); it++) {
259 urls.push_back(GURL(it->first));
260 }
261 redirects_collector_->StartHistoryCollection(
262 urls, tab_contents(),
263 NewRunnableMethod(this, &MalwareDetails::OnRedirectionCollectionReady));
264 }
265
266 void MalwareDetails::OnRedirectionCollectionReady() {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
268 std::vector<safe_browsing::RedirectChain>* redirects =
269 redirects_collector_->GetCollectedUrls();
270
271 for (std::vector<safe_browsing::RedirectChain>::const_iterator it
272 = redirects->begin(); it != redirects->end(); ++it)
273 AddRedirectUrlList(*it);
274
275 // Call the cache collector
249 cache_collector_->StartCacheCollection( 276 cache_collector_->StartCacheCollection(
250 request_context_getter_, 277 request_context_getter_,
251 &resources_, 278 &resources_,
252 &cache_result_, 279 &cache_result_,
253 NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady)); 280 NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady));
254 } 281 }
255 282
283 void MalwareDetails::AddRedirectUrlList(const std::vector<GURL>& urls) {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
285 for (uint i = 0; i < urls.size()-1; ++i) {
mattm 2011/05/17 03:17:01 size_t
kewang 2011/05/18 05:47:40 Done.
286 AddUrl(urls[i], urls[i+1], "redir", NULL);
mattm 2011/05/17 03:17:01 "redir" should be a const. Also, other places jus
panayiotis 2011/05/17 17:19:48 Actually I take it back, let's not add any tagname
kewang 2011/05/18 05:47:40 const added. We are using it for all the redir url
kewang 2011/05/18 05:47:40 Followed Pano's suggestion and removed it.
287 LOG(INFO) << "--- adding...." << urls[i];
panayiotis 2011/05/16 17:14:55 drop the log infos ...
kewang 2011/05/18 05:47:40 Done.
288 }
289 }
290
256 void MalwareDetails::OnCacheCollectionReady() { 291 void MalwareDetails::OnCacheCollectionReady() {
257 DVLOG(1) << "OnCacheCollectionReady."; 292 DVLOG(1) << "OnCacheCollectionReady.";
258 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. 293 // Add all the urls in our |resources_| maps to the |report_| protocol buffer.
259 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); 294 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin();
260 it != resources_.end(); it++) { 295 it != resources_.end(); it++) {
261 ClientMalwareReportRequest::Resource* pb_resource = 296 ClientMalwareReportRequest::Resource* pb_resource =
262 report_->add_resources(); 297 report_->add_resources();
263 pb_resource->CopyFrom(*(it->second)); 298 pb_resource->CopyFrom(*(it->second));
264 } 299 }
265 300
266 report_->set_complete(cache_result_); 301 report_->set_complete(cache_result_);
267 302
268 // Send the report, using the SafeBrowsingService. 303 // Send the report, using the SafeBrowsingService.
269 std::string serialized; 304 std::string serialized;
270 if (!report_->SerializeToString(&serialized)) { 305 if (!report_->SerializeToString(&serialized)) {
271 DLOG(ERROR) << "Unable to serialize the malware report."; 306 DLOG(ERROR) << "Unable to serialize the malware report.";
272 return; 307 return;
273 } 308 }
274 309
275 sb_service_->SendSerializedMalwareDetails(serialized); 310 sb_service_->SendSerializedMalwareDetails(serialized);
276 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698