OLD | NEW |
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/safe_browsing/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 327 |
328 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 328 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
329 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | 329 // url_request_context_getter_ is cleared, since the URLRequestContextGetter |
330 // will PostTask to IOTread to delete itself. | 330 // will PostTask to IOTread to delete itself. |
331 using base::debug::LeakTracker; | 331 using base::debug::LeakTracker; |
332 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); | 332 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); |
333 | 333 |
334 url_request_context_.reset(); | 334 url_request_context_.reset(); |
335 } | 335 } |
336 | 336 |
337 void SafeBrowsingService::StartOnIOThread( | 337 SafeBrowsingProtocolConfig SafeBrowsingService::GetProtocolConfig() const { |
338 net::URLRequestContextGetter* url_request_context_getter) { | |
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
340 if (enabled_) | |
341 return; | |
342 enabled_ = true; | |
343 | |
344 SafeBrowsingProtocolConfig config; | 338 SafeBrowsingProtocolConfig config; |
345 // On Windows, get the safe browsing client name from the browser | 339 // On Windows, get the safe browsing client name from the browser |
346 // distribution classes in installer util. These classes don't yet have | 340 // distribution classes in installer util. These classes don't yet have |
347 // an analog on non-Windows builds so just keep the name specified here. | 341 // an analog on non-Windows builds so just keep the name specified here. |
348 #if defined(OS_WIN) | 342 #if defined(OS_WIN) |
349 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 343 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
350 config.client_name = dist->GetSafeBrowsingName(); | 344 config.client_name = dist->GetSafeBrowsingName(); |
351 #else | 345 #else |
352 #if defined(GOOGLE_CHROME_BUILD) | 346 #if defined(GOOGLE_CHROME_BUILD) |
353 config.client_name = "googlechrome"; | 347 config.client_name = "googlechrome"; |
354 #else | 348 #else |
355 config.client_name = "chromium"; | 349 config.client_name = "chromium"; |
356 #endif | 350 #endif |
357 #endif | 351 #endif |
358 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 352 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
359 config.disable_auto_update = | 353 config.disable_auto_update = |
360 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || | 354 cmdline->HasSwitch(switches::kSbDisableAutoUpdate) || |
361 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); | 355 cmdline->HasSwitch(switches::kDisableBackgroundNetworking); |
362 if (cmdline->HasSwitch(switches::kSbURLPrefix)) { | 356 if (cmdline->HasSwitch(switches::kSbURLPrefix)) { |
363 config.url_prefix = cmdline->GetSwitchValueASCII(switches::kSbURLPrefix); | 357 config.url_prefix = cmdline->GetSwitchValueASCII(switches::kSbURLPrefix); |
364 } else { | 358 } else { |
365 config.url_prefix = kSbDefaultURLPrefix; | 359 config.url_prefix = kSbDefaultURLPrefix; |
366 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; | 360 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; |
367 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; | 361 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; |
368 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; | 362 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; |
369 } | 363 } |
370 | 364 |
| 365 return config; |
| 366 } |
| 367 |
| 368 void SafeBrowsingService::StartOnIOThread( |
| 369 net::URLRequestContextGetter* url_request_context_getter) { |
| 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 371 if (enabled_) |
| 372 return; |
| 373 enabled_ = true; |
| 374 |
| 375 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
| 376 |
371 #if defined(FULL_SAFE_BROWSING) | 377 #if defined(FULL_SAFE_BROWSING) |
372 DCHECK(database_manager_.get()); | 378 DCHECK(database_manager_.get()); |
373 database_manager_->StartOnIOThread(); | 379 database_manager_->StartOnIOThread(); |
374 | 380 |
375 DCHECK(!protocol_manager_); | 381 DCHECK(!protocol_manager_); |
376 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 382 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
377 database_manager_.get(), url_request_context_getter, config); | 383 database_manager_.get(), url_request_context_getter, config); |
378 protocol_manager_->Initialize(); | 384 protocol_manager_->Initialize(); |
379 #endif | 385 #endif |
380 | 386 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 #if defined(FULL_SAFE_BROWSING) | 490 #if defined(FULL_SAFE_BROWSING) |
485 if (csd_service_.get()) | 491 if (csd_service_.get()) |
486 csd_service_->SetEnabledAndRefreshState(enable); | 492 csd_service_->SetEnabledAndRefreshState(enable); |
487 if (download_service_.get()) { | 493 if (download_service_.get()) { |
488 download_service_->SetEnabled( | 494 download_service_->SetEnabled( |
489 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 495 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
490 switches::kDisableImprovedDownloadProtection)); | 496 switches::kDisableImprovedDownloadProtection)); |
491 } | 497 } |
492 #endif | 498 #endif |
493 } | 499 } |
OLD | NEW |