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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 278 |
279 | 279 |
280 // static | 280 // static |
281 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 281 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
282 if (!factory_) | 282 if (!factory_) |
283 factory_ = g_safe_browsing_service_factory_impl.Pointer(); | 283 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
284 return factory_->CreateSafeBrowsingService(); | 284 return factory_->CreateSafeBrowsingService(); |
285 } | 285 } |
286 | 286 |
287 SafeBrowsingService::SafeBrowsingService() | 287 SafeBrowsingService::SafeBrowsingService() |
288 : services_delegate_(ServicesDelegate::Create(this)), | 288 : services_delegate_(ServicesDelegate::Create(this)) {} |
289 enabled_(false), | |
290 enabled_by_prefs_(false), | |
291 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} | |
292 | 289 |
293 SafeBrowsingService::~SafeBrowsingService() { | 290 SafeBrowsingService::~SafeBrowsingService() { |
294 // We should have already been shut down. If we're still enabled, then the | 291 // We should have already been shut down. If we're still enabled, then the |
295 // database isn't going to be closed properly, which could lead to corruption. | 292 // database isn't going to be closed properly, which could lead to corruption. |
296 DCHECK(!enabled_); | 293 DCHECK(!enabled_); |
297 } | 294 } |
298 | 295 |
299 void SafeBrowsingService::Initialize() { | 296 void SafeBrowsingService::Initialize() { |
300 // Ensure FileTypePolicies's Singleton is instantiated during startup. | 297 // Ensure FileTypePolicies's Singleton is instantiated during startup. |
301 // This guarantees we'll log UMA metrics about its state. | 298 // This guarantees we'll log UMA metrics about its state. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return false; | 383 return false; |
387 #endif | 384 #endif |
388 } | 385 } |
389 | 386 |
390 scoped_refptr<net::URLRequestContextGetter> | 387 scoped_refptr<net::URLRequestContextGetter> |
391 SafeBrowsingService::url_request_context() { | 388 SafeBrowsingService::url_request_context() { |
392 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 389 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
393 return url_request_context_getter_; | 390 return url_request_context_getter_; |
394 } | 391 } |
395 | 392 |
| 393 // TODO(ntfschr): componentize this once BaseSafeBrowsingUIManager contains a |
| 394 // SafeBrowsingService |
396 const scoped_refptr<SafeBrowsingUIManager>& | 395 const scoped_refptr<SafeBrowsingUIManager>& |
397 SafeBrowsingService::ui_manager() const { | 396 SafeBrowsingService::ui_manager() const { |
398 return ui_manager_; | 397 return ui_manager_; |
399 } | 398 } |
400 | 399 |
401 const scoped_refptr<SafeBrowsingDatabaseManager>& | 400 const scoped_refptr<SafeBrowsingDatabaseManager>& |
402 SafeBrowsingService::database_manager() const { | 401 SafeBrowsingService::database_manager() const { |
403 return enabled_v4_only_ ? v4_local_database_manager() : database_manager_; | 402 return enabled_v4_only_ ? v4_local_database_manager() : database_manager_; |
404 } | 403 } |
405 | 404 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 TRACE_EVENT1("loader", "SafeBrowsingService::OnResourceRequest", "url", | 455 TRACE_EVENT1("loader", "SafeBrowsingService::OnResourceRequest", "url", |
457 request->url().spec()); | 456 request->url().spec()); |
458 | 457 |
459 ResourceRequestInfo info = ResourceRequestDetector::GetRequestInfo(request); | 458 ResourceRequestInfo info = ResourceRequestDetector::GetRequestInfo(request); |
460 BrowserThread::PostTask( | 459 BrowserThread::PostTask( |
461 BrowserThread::UI, FROM_HERE, | 460 BrowserThread::UI, FROM_HERE, |
462 base::Bind(&SafeBrowsingService::ProcessResourceRequest, this, info)); | 461 base::Bind(&SafeBrowsingService::ProcessResourceRequest, this, info)); |
463 #endif | 462 #endif |
464 } | 463 } |
465 | 464 |
| 465 // TODO(ntfschr): componentize this once BaseSafeBrowsingUIManager contains a |
| 466 // SafeBrowsingService |
466 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { | 467 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { |
467 return new SafeBrowsingUIManager(this); | 468 return new SafeBrowsingUIManager(this); |
468 } | 469 } |
469 | 470 |
470 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { | 471 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { |
471 #if defined(SAFE_BROWSING_DB_LOCAL) | 472 #if defined(SAFE_BROWSING_DB_LOCAL) |
472 return new LocalSafeBrowsingDatabaseManager(this); | 473 return new LocalSafeBrowsingDatabaseManager(this); |
473 #elif defined(SAFE_BROWSING_DB_REMOTE) | 474 #elif defined(SAFE_BROWSING_DB_REMOTE) |
474 return new RemoteSafeBrowsingDatabaseManager(); | 475 return new RemoteSafeBrowsingDatabaseManager(); |
475 #else | 476 #else |
(...skipping 28 matching lines...) Expand all Loading... |
504 | 505 |
505 V4ProtocolConfig | 506 V4ProtocolConfig |
506 SafeBrowsingService::GetV4ProtocolConfig() const { | 507 SafeBrowsingService::GetV4ProtocolConfig() const { |
507 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 508 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
508 return V4ProtocolConfig( | 509 return V4ProtocolConfig( |
509 GetProtocolConfigClientName(), | 510 GetProtocolConfigClientName(), |
510 cmdline->HasSwitch(::switches::kDisableBackgroundNetworking), | 511 cmdline->HasSwitch(::switches::kDisableBackgroundNetworking), |
511 google_apis::GetAPIKey(), SafeBrowsingProtocolManagerHelper::Version()); | 512 google_apis::GetAPIKey(), SafeBrowsingProtocolManagerHelper::Version()); |
512 } | 513 } |
513 | 514 |
514 std::string SafeBrowsingService::GetProtocolConfigClientName() const { | |
515 std::string client_name; | |
516 // On Windows, get the safe browsing client name from the browser | |
517 // distribution classes in installer util. These classes don't yet have | |
518 // an analog on non-Windows builds so just keep the name specified here. | |
519 #if defined(OS_WIN) | |
520 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
521 client_name = dist->GetSafeBrowsingName(); | |
522 #else | |
523 #if defined(GOOGLE_CHROME_BUILD) | |
524 client_name = "googlechrome"; | |
525 #else | |
526 client_name = "chromium"; | |
527 #endif | |
528 | |
529 // Mark client string to allow server to differentiate mobile. | |
530 #if defined(OS_ANDROID) | |
531 client_name.append("-a"); | |
532 #endif | |
533 | |
534 #endif // defined(OS_WIN) | |
535 | |
536 return client_name; | |
537 } | |
538 | |
539 // Any tests that create a DatabaseManager that isn't derived from | 515 // Any tests that create a DatabaseManager that isn't derived from |
540 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 516 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
541 SafeBrowsingProtocolManagerDelegate* | 517 SafeBrowsingProtocolManagerDelegate* |
542 SafeBrowsingService::GetProtocolManagerDelegate() { | 518 SafeBrowsingService::GetProtocolManagerDelegate() { |
543 #if defined(SAFE_BROWSING_DB_LOCAL) | 519 #if defined(SAFE_BROWSING_DB_LOCAL) |
544 DCHECK(!enabled_v4_only_); | 520 DCHECK(!enabled_v4_only_); |
545 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 521 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
546 database_manager_.get()); | 522 database_manager_.get()); |
547 #else | 523 #else |
548 NOTREACHED(); | 524 NOTREACHED(); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 ping_manager()->ReportThreatDetails(report); | 716 ping_manager()->ReportThreatDetails(report); |
741 } | 717 } |
742 | 718 |
743 void SafeBrowsingService::ProcessResourceRequest( | 719 void SafeBrowsingService::ProcessResourceRequest( |
744 const ResourceRequestInfo& request) { | 720 const ResourceRequestInfo& request) { |
745 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 721 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
746 services_delegate_->ProcessResourceRequest(&request); | 722 services_delegate_->ProcessResourceRequest(&request); |
747 } | 723 } |
748 | 724 |
749 } // namespace safe_browsing | 725 } // namespace safe_browsing |
OLD | NEW |