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