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

Side by Side Diff: chrome/browser/renderer_host/safe_browsing_resource_throttle.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 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" 5 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 } // namespace 65 } // namespace
66 66
67 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more 67 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more
68 // unit test coverage. 68 // unit test coverage.
69 69
70 // static 70 // static
71 SafeBrowsingResourceThrottle* SafeBrowsingResourceThrottle::MaybeCreate( 71 SafeBrowsingResourceThrottle* SafeBrowsingResourceThrottle::MaybeCreate(
72 net::URLRequest* request, 72 net::URLRequest* request,
73 content::ResourceType resource_type, 73 content::ResourceType resource_type,
74 SafeBrowsingService* sb_service) { 74 safe_browsing::SafeBrowsingService* sb_service) {
75 if (sb_service->database_manager()->IsSupported()) { 75 if (sb_service->database_manager()->IsSupported()) {
76 return new SafeBrowsingResourceThrottle(request, resource_type, sb_service); 76 return new SafeBrowsingResourceThrottle(request, resource_type, sb_service);
77 } 77 }
78 return nullptr; 78 return nullptr;
79 } 79 }
80 80
81 SafeBrowsingResourceThrottle::SafeBrowsingResourceThrottle( 81 SafeBrowsingResourceThrottle::SafeBrowsingResourceThrottle(
82 const net::URLRequest* request, 82 const net::URLRequest* request,
83 content::ResourceType resource_type, 83 content::ResourceType resource_type,
84 SafeBrowsingService* sb_service) 84 safe_browsing::SafeBrowsingService* sb_service)
85 : state_(STATE_NONE), 85 : state_(STATE_NONE),
86 defer_state_(DEFERRED_NONE), 86 defer_state_(DEFERRED_NONE),
87 threat_type_(SB_THREAT_TYPE_SAFE), 87 threat_type_(safe_browsing::SB_THREAT_TYPE_SAFE),
88 database_manager_(sb_service->database_manager()), 88 database_manager_(sb_service->database_manager()),
89 ui_manager_(sb_service->ui_manager()), 89 ui_manager_(sb_service->ui_manager()),
90 request_(request), 90 request_(request),
91 resource_type_(resource_type), 91 resource_type_(resource_type),
92 bound_net_log_(net::BoundNetLog::Make(request->net_log().net_log(), 92 bound_net_log_(net::BoundNetLog::Make(request->net_log().net_log(),
93 NetLog::SOURCE_SAFE_BROWSING)) {} 93 NetLog::SOURCE_SAFE_BROWSING)) {}
94 94
95 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { 95 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() {
96 if (defer_state_ != DEFERRED_NONE) { 96 if (defer_state_ != DEFERRED_NONE) {
97 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); 97 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 195
196 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const { 196 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const {
197 return "SafeBrowsingResourceThrottle"; 197 return "SafeBrowsingResourceThrottle";
198 } 198 }
199 199
200 // SafeBrowsingService::Client implementation, called on the IO thread once 200 // SafeBrowsingService::Client implementation, called on the IO thread once
201 // the URL has been classified. 201 // the URL has been classified.
202 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( 202 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult(
203 const GURL& url, 203 const GURL& url,
204 SBThreatType threat_type, 204 safe_browsing::SBThreatType threat_type,
205 const std::string& metadata) { 205 const std::string& metadata) {
206 CHECK_EQ(state_, STATE_CHECKING_URL); 206 CHECK_EQ(state_, STATE_CHECKING_URL);
207 CHECK_EQ(url, url_being_checked_); 207 CHECK_EQ(url, url_being_checked_);
208 208
209 timer_.Stop(); // Cancel the timeout timer. 209 timer_.Stop(); // Cancel the timeout timer.
210 threat_type_ = threat_type; 210 threat_type_ = threat_type;
211 state_ = STATE_NONE; 211 state_ = STATE_NONE;
212 212
213 if (defer_state_ != DEFERRED_NONE) { 213 if (defer_state_ != DEFERRED_NONE) {
214 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); 214 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr);
215 } 215 }
216 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, "result", 216 EndNetLogEvent(
217 threat_type_ == SB_THREAT_TYPE_SAFE ? "safe" : "unsafe"); 217 NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, "result",
218 threat_type_ == safe_browsing::SB_THREAT_TYPE_SAFE ? "safe" : "unsafe");
218 219
219 if (threat_type == SB_THREAT_TYPE_SAFE) { 220 if (threat_type == safe_browsing::SB_THREAT_TYPE_SAFE) {
220 RecordHistogramResourceTypeSafe(resource_type_); 221 RecordHistogramResourceTypeSafe(resource_type_);
221 if (defer_state_ != DEFERRED_NONE) { 222 if (defer_state_ != DEFERRED_NONE) {
222 // Log how much time the safe browsing check cost us. 223 // Log how much time the safe browsing check cost us.
223 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_); 224 ui_manager_->LogPauseDelay(base::TimeTicks::Now() - defer_start_time_);
224 ResumeRequest(); 225 ResumeRequest();
225 } else { 226 } else {
226 ui_manager_->LogPauseDelay(base::TimeDelta()); 227 ui_manager_->LogPauseDelay(base::TimeDelta());
227 } 228 }
228 return; 229 return;
229 } 230 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 298 }
298 299
299 // SafeBrowsingService::UrlCheckCallback implementation, called on the IO 300 // SafeBrowsingService::UrlCheckCallback implementation, called on the IO
300 // thread when the user has decided to proceed with the current request, or 301 // thread when the user has decided to proceed with the current request, or
301 // go back. 302 // go back.
302 void SafeBrowsingResourceThrottle::OnBlockingPageComplete(bool proceed) { 303 void SafeBrowsingResourceThrottle::OnBlockingPageComplete(bool proceed) {
303 CHECK_EQ(state_, STATE_DISPLAYING_BLOCKING_PAGE); 304 CHECK_EQ(state_, STATE_DISPLAYING_BLOCKING_PAGE);
304 state_ = STATE_NONE; 305 state_ = STATE_NONE;
305 306
306 if (proceed) { 307 if (proceed) {
307 threat_type_ = SB_THREAT_TYPE_SAFE; 308 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE;
308 if (defer_state_ != DEFERRED_NONE) { 309 if (defer_state_ != DEFERRED_NONE) {
309 ResumeRequest(); 310 ResumeRequest();
310 } 311 }
311 } else { 312 } else {
312 controller()->Cancel(); 313 controller()->Cancel();
313 } 314 }
314 } 315 }
315 316
316 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { 317 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) {
317 CHECK_EQ(state_, STATE_NONE); 318 CHECK_EQ(state_, STATE_NONE);
318 // To reduce aggregate latency on mobile, check only the most dangerous 319 // To reduce aggregate latency on mobile, check only the most dangerous
319 // resource types. 320 // resource types.
320 if (!database_manager_->CanCheckResourceType(resource_type_)) { 321 if (!database_manager_->CanCheckResourceType(resource_type_)) {
321 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Skipped", resource_type_, 322 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Skipped", resource_type_,
322 content::RESOURCE_TYPE_LAST_TYPE); 323 content::RESOURCE_TYPE_LAST_TYPE);
323 return true; 324 return true;
324 } 325 }
325 326
326 bool succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this); 327 bool succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this);
327 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Checked", resource_type_, 328 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Checked", resource_type_,
328 content::RESOURCE_TYPE_LAST_TYPE); 329 content::RESOURCE_TYPE_LAST_TYPE);
329 330
330 if (succeeded_synchronously) { 331 if (succeeded_synchronously) {
331 RecordHistogramResourceTypeSafe(resource_type_); 332 RecordHistogramResourceTypeSafe(resource_type_);
332 threat_type_ = SB_THREAT_TYPE_SAFE; 333 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE;
333 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. 334 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay.
334 return true; 335 return true;
335 } 336 }
336 337
337 state_ = STATE_CHECKING_URL; 338 state_ = STATE_CHECKING_URL;
338 url_being_checked_ = url; 339 url_being_checked_ = url;
339 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, url, nullptr, 340 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, url, nullptr,
340 nullptr); 341 nullptr);
341 342
342 // Start a timer to abort the check if it takes too long. 343 // Start a timer to abort the check if it takes too long.
343 // TODO(nparker): Set this only when we defer, based on remaining time, 344 // TODO(nparker): Set this only when we defer, based on remaining time,
344 // so we don't cancel earlier than necessary. 345 // so we don't cancel earlier than necessary.
345 timer_.Start(FROM_HERE, 346 timer_.Start(FROM_HERE,
346 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), 347 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs),
347 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); 348 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout);
348 349
349 return false; 350 return false;
350 } 351 }
351 352
352 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { 353 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() {
353 CHECK_EQ(state_, STATE_CHECKING_URL); 354 CHECK_EQ(state_, STATE_CHECKING_URL);
354 355
355 database_manager_->CancelCheck(this); 356 database_manager_->CancelCheck(this);
356 OnCheckBrowseUrlResult( 357 OnCheckBrowseUrlResult(
357 url_being_checked_, SB_THREAT_TYPE_SAFE, std::string()); 358 url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, std::string());
358 } 359 }
359 360
360 void SafeBrowsingResourceThrottle::ResumeRequest() { 361 void SafeBrowsingResourceThrottle::ResumeRequest() {
361 CHECK_EQ(state_, STATE_NONE); 362 CHECK_EQ(state_, STATE_NONE);
362 CHECK_NE(defer_state_, DEFERRED_NONE); 363 CHECK_NE(defer_state_, DEFERRED_NONE);
363 364
364 bool resume = true; 365 bool resume = true;
365 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { 366 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) {
366 // Save the redirect urls for possible malware detail reporting later. 367 // Save the redirect urls for possible malware detail reporting later.
367 redirect_urls_.push_back(unchecked_redirect_url_); 368 redirect_urls_.push_back(unchecked_redirect_url_);
368 if (!CheckUrl(unchecked_redirect_url_)) { 369 if (!CheckUrl(unchecked_redirect_url_)) {
369 // We're now waiting for the unchecked_redirect_url_. 370 // We're now waiting for the unchecked_redirect_url_.
370 defer_state_ = DEFERRED_REDIRECT; 371 defer_state_ = DEFERRED_REDIRECT;
371 resume = false; 372 resume = false;
372 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, 373 BeginNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED,
373 unchecked_redirect_url_, "defer_reason", 374 unchecked_redirect_url_, "defer_reason",
374 "resumed_redirect"); 375 "resumed_redirect");
375 } 376 }
376 } 377 }
377 378
378 if (resume) { 379 if (resume) {
379 defer_state_ = DEFERRED_NONE; 380 defer_state_ = DEFERRED_NONE;
380 controller()->Resume(); 381 controller()->Resume();
381 } 382 }
382 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698