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

Side by Side Diff: chrome/browser/safe_browsing/threat_details.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Bring back anon namespace. Remove safe_browsing:: wherever not needed. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threat_details.h" 7 #include "chrome/browser/safe_browsing/threat_details.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/safe_browsing/report.pb.h" 12 #include "chrome/browser/safe_browsing/report.pb.h"
13 #include "chrome/browser/safe_browsing/threat_details_cache.h" 13 #include "chrome/browser/safe_browsing/threat_details_cache.h"
14 #include "chrome/browser/safe_browsing/threat_details_history.h" 14 #include "chrome/browser/safe_browsing/threat_details_history.h"
15 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 15 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using content::NavigationEntry; 24 using content::NavigationEntry;
25 using content::WebContents; 25 using content::WebContents;
26 using safe_browsing::ClientMalwareReportRequest; 26
27 namespace safe_browsing {
27 28
28 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details 29 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details
29 static const uint32 kMaxDomNodes = 500; 30 static const uint32 kMaxDomNodes = 500;
30 31
31 // static 32 // static
32 ThreatDetailsFactory* ThreatDetails::factory_ = NULL; 33 ThreatDetailsFactory* ThreatDetails::factory_ = NULL;
33 34
34 // The default ThreatDetailsFactory. Global, made a singleton so we 35 // The default ThreatDetailsFactory. Global, made a singleton so we
35 // don't leak it. 36 // don't leak it.
36 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { 37 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // TODO(panayiotis): also skip internal urls. 98 // TODO(panayiotis): also skip internal urls.
98 return url.SchemeIs("http") || url.SchemeIs("https"); 99 return url.SchemeIs("http") || url.SchemeIs("https");
99 } 100 }
100 101
101 // Looks for a Resource for the given url in resources_. If found, it 102 // Looks for a Resource for the given url in resources_. If found, it
102 // updates |resource|. Otherwise, it creates a new message, adds it to 103 // updates |resource|. Otherwise, it creates a new message, adds it to
103 // resources_ and updates |resource| to point to it. 104 // resources_ and updates |resource| to point to it.
104 // 105 //
105 ClientMalwareReportRequest::Resource* ThreatDetails::FindOrCreateResource( 106 ClientMalwareReportRequest::Resource* ThreatDetails::FindOrCreateResource(
106 const GURL& url) { 107 const GURL& url) {
107 safe_browsing::ResourceMap::iterator it = resources_.find(url.spec()); 108 ResourceMap::iterator it = resources_.find(url.spec());
108 if (it != resources_.end()) 109 if (it != resources_.end())
109 return it->second.get(); 110 return it->second.get();
110 111
111 // Create the resource for |url|. 112 // Create the resource for |url|.
112 int id = resources_.size(); 113 int id = resources_.size();
113 linked_ptr<ClientMalwareReportRequest::Resource> new_resource( 114 linked_ptr<ClientMalwareReportRequest::Resource> new_resource(
114 new ClientMalwareReportRequest::Resource()); 115 new ClientMalwareReportRequest::Resource());
115 new_resource->set_url(url.spec()); 116 new_resource->set_url(url.spec());
116 new_resource->set_id(id); 117 new_resource->set_id(id);
117 resources_[url.spec()] = new_resource; 118 resources_[url.spec()] = new_resource;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // closed the tab, or clicked proceed or goback. Since the user needs 244 // closed the tab, or clicked proceed or goback. Since the user needs
244 // to take an action, we expect this to be called after 245 // to take an action, we expect this to be called after
245 // OnReceivedThreatDOMDetails in most cases. If not, we don't include 246 // OnReceivedThreatDOMDetails in most cases. If not, we don't include
246 // the DOM data in our report. 247 // the DOM data in our report.
247 void ThreatDetails::FinishCollection(bool did_proceed, int num_visit) { 248 void ThreatDetails::FinishCollection(bool did_proceed, int num_visit) {
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); 249 DCHECK_CURRENTLY_ON(BrowserThread::IO);
249 250
250 did_proceed_ = did_proceed; 251 did_proceed_ = did_proceed;
251 num_visits_ = num_visit; 252 num_visits_ = num_visit;
252 std::vector<GURL> urls; 253 std::vector<GURL> urls;
253 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); 254 for (ResourceMap::const_iterator it = resources_.begin();
254 it != resources_.end(); ++it) { 255 it != resources_.end(); ++it) {
255 urls.push_back(GURL(it->first)); 256 urls.push_back(GURL(it->first));
256 } 257 }
257 redirects_collector_->StartHistoryCollection( 258 redirects_collector_->StartHistoryCollection(
258 urls, base::Bind(&ThreatDetails::OnRedirectionCollectionReady, this)); 259 urls, base::Bind(&ThreatDetails::OnRedirectionCollectionReady, this));
259 } 260 }
260 261
261 void ThreatDetails::OnRedirectionCollectionReady() { 262 void ThreatDetails::OnRedirectionCollectionReady() {
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); 263 DCHECK_CURRENTLY_ON(BrowserThread::IO);
263 const std::vector<safe_browsing::RedirectChain>& redirects = 264 const std::vector<RedirectChain>& redirects =
264 redirects_collector_->GetCollectedUrls(); 265 redirects_collector_->GetCollectedUrls();
265 266
266 for (size_t i = 0; i < redirects.size(); ++i) 267 for (size_t i = 0; i < redirects.size(); ++i)
267 AddRedirectUrlList(redirects[i]); 268 AddRedirectUrlList(redirects[i]);
268 269
269 // Call the cache collector 270 // Call the cache collector
270 cache_collector_->StartCacheCollection( 271 cache_collector_->StartCacheCollection(
271 request_context_getter_.get(), &resources_, &cache_result_, 272 request_context_getter_.get(), &resources_, &cache_result_,
272 base::Bind(&ThreatDetails::OnCacheCollectionReady, this)); 273 base::Bind(&ThreatDetails::OnCacheCollectionReady, this));
273 } 274 }
274 275
275 void ThreatDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { 276 void ThreatDetails::AddRedirectUrlList(const std::vector<GURL>& urls) {
276 DCHECK_CURRENTLY_ON(BrowserThread::IO); 277 DCHECK_CURRENTLY_ON(BrowserThread::IO);
277 for (size_t i = 0; i < urls.size() - 1; ++i) { 278 for (size_t i = 0; i < urls.size() - 1; ++i) {
278 AddUrl(urls[i], urls[i + 1], std::string(), NULL); 279 AddUrl(urls[i], urls[i + 1], std::string(), NULL);
279 } 280 }
280 } 281 }
281 282
282 void ThreatDetails::OnCacheCollectionReady() { 283 void ThreatDetails::OnCacheCollectionReady() {
283 DVLOG(1) << "OnCacheCollectionReady."; 284 DVLOG(1) << "OnCacheCollectionReady.";
284 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. 285 // Add all the urls in our |resources_| maps to the |report_| protocol buffer.
285 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); 286 for (ResourceMap::const_iterator it = resources_.begin();
286 it != resources_.end(); ++it) { 287 it != resources_.end(); ++it) {
287 ClientMalwareReportRequest::Resource* pb_resource = 288 ClientMalwareReportRequest::Resource* pb_resource =
288 report_->add_resources(); 289 report_->add_resources();
289 pb_resource->CopyFrom(*(it->second)); 290 pb_resource->CopyFrom(*(it->second));
290 const GURL url(pb_resource->url()); 291 const GURL url(pb_resource->url());
291 if (url.SchemeIs("https")) { 292 if (url.SchemeIs("https")) {
292 // Don't report headers of HTTPS requests since they may contain private 293 // Don't report headers of HTTPS requests since they may contain private
293 // cookies. We still retain the full URL. 294 // cookies. We still retain the full URL.
294 DVLOG(1) << "Clearing out HTTPS resource: " << pb_resource->url(); 295 DVLOG(1) << "Clearing out HTTPS resource: " << pb_resource->url();
295 pb_resource->clear_request(); 296 pb_resource->clear_request();
(...skipping 10 matching lines...) Expand all
306 307
307 // Send the report, using the SafeBrowsingService. 308 // Send the report, using the SafeBrowsingService.
308 std::string serialized; 309 std::string serialized;
309 if (!report_->SerializeToString(&serialized)) { 310 if (!report_->SerializeToString(&serialized)) {
310 DLOG(ERROR) << "Unable to serialize the malware report."; 311 DLOG(ERROR) << "Unable to serialize the malware report.";
311 return; 312 return;
312 } 313 }
313 314
314 ui_manager_->SendSerializedThreatDetails(serialized); 315 ui_manager_->SendSerializedThreatDetails(serialized);
315 } 316 }
317
318 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698