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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} | 250 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} |
251 | 251 |
252 // static | 252 // static |
253 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; | 253 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; |
254 | 254 |
255 // The default SafeBrowsingServiceFactory. Global, made a singleton so we | 255 // The default SafeBrowsingServiceFactory. Global, made a singleton so we |
256 // don't leak it. | 256 // don't leak it. |
257 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { | 257 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { |
258 public: | 258 public: |
259 SafeBrowsingService* CreateSafeBrowsingService() override { | 259 SafeBrowsingService* CreateSafeBrowsingService() override { |
260 return new SafeBrowsingService(); | 260 V4UsageStatus v4_usage_status; |
261 if (safe_browsing::V4FeatureList::IsV4OnlyEnabled()) { | |
Nathan Parker
2017/02/08 01:22:43
This block of code could go into a GetV4UsageStatu
vakh (use Gerrit instead)
2017/02/09 03:30:27
Done.
| |
262 v4_usage_status = V4UsageStatus::V4_ONLY; | |
263 } else if (safe_browsing::V4FeatureList::IsLocalDatabaseManagerEnabled()) { | |
264 v4_usage_status = V4UsageStatus::V4_INSTANTIATED; | |
265 } else { | |
266 v4_usage_status = V4UsageStatus::V4_DISABLED; | |
267 } | |
268 return new SafeBrowsingService(v4_usage_status); | |
261 } | 269 } |
262 | 270 |
263 private: | 271 private: |
264 friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; | 272 friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; |
265 | 273 |
266 SafeBrowsingServiceFactoryImpl() { } | 274 SafeBrowsingServiceFactoryImpl() { } |
267 | 275 |
268 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); | 276 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); |
269 }; | 277 }; |
270 | 278 |
(...skipping 14 matching lines...) Expand all Loading... | |
285 } | 293 } |
286 | 294 |
287 | 295 |
288 // static | 296 // static |
289 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 297 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
290 if (!factory_) | 298 if (!factory_) |
291 factory_ = g_safe_browsing_service_factory_impl.Pointer(); | 299 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
292 return factory_->CreateSafeBrowsingService(); | 300 return factory_->CreateSafeBrowsingService(); |
293 } | 301 } |
294 | 302 |
295 SafeBrowsingService::SafeBrowsingService() | 303 SafeBrowsingService::SafeBrowsingService(V4UsageStatus v4_usage_status) |
296 : services_delegate_(ServicesDelegate::Create(this)), | 304 : services_delegate_(ServicesDelegate::Create(this)), |
297 estimated_extended_reporting_by_prefs_(SBER_LEVEL_OFF), | 305 estimated_extended_reporting_by_prefs_(SBER_LEVEL_OFF), |
298 enabled_(false), | 306 enabled_(false), |
299 enabled_by_prefs_(false), | 307 enabled_by_prefs_(false), |
300 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} | 308 use_v4_only_(v4_usage_status == V4UsageStatus::V4_ONLY), |
309 v4_enabled_(v4_usage_status == V4UsageStatus::V4_INSTANTIATED || | |
310 v4_usage_status == V4UsageStatus::V4_ONLY) {} | |
301 | 311 |
302 SafeBrowsingService::~SafeBrowsingService() { | 312 SafeBrowsingService::~SafeBrowsingService() { |
303 // We should have already been shut down. If we're still enabled, then the | 313 // We should have already been shut down. If we're still enabled, then the |
304 // database isn't going to be closed properly, which could lead to corruption. | 314 // database isn't going to be closed properly, which could lead to corruption. |
305 DCHECK(!enabled_); | 315 DCHECK(!enabled_); |
306 } | 316 } |
307 | 317 |
308 void SafeBrowsingService::Initialize() { | 318 void SafeBrowsingService::Initialize() { |
309 // Ensure FileTypePolicies's Singleton is instantiated during startup. | 319 // Ensure FileTypePolicies's Singleton is instantiated during startup. |
310 // This guarantees we'll log UMA metrics about its state. | 320 // This guarantees we'll log UMA metrics about its state. |
311 FileTypePolicies::GetInstance(); | 321 FileTypePolicies::GetInstance(); |
312 | 322 |
313 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( | 323 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( |
314 g_browser_process->system_request_context()); | 324 g_browser_process->system_request_context()); |
315 | 325 |
316 ui_manager_ = CreateUIManager(); | 326 ui_manager_ = CreateUIManager(); |
317 | 327 |
318 if (!enabled_v4_only_) { | 328 if (!use_v4_only_) { |
319 database_manager_ = CreateDatabaseManager(); | 329 database_manager_ = CreateDatabaseManager(); |
320 } | 330 } |
321 | 331 |
322 if (base::FeatureList::IsEnabled( | 332 if (base::FeatureList::IsEnabled( |
323 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) { | 333 SafeBrowsingNavigationObserverManager::kDownloadAttribution)) { |
324 navigation_observer_manager_ = new SafeBrowsingNavigationObserverManager(); | 334 navigation_observer_manager_ = new SafeBrowsingNavigationObserverManager(); |
325 } | 335 } |
326 | 336 |
327 services_delegate_->Initialize(); | 337 services_delegate_->Initialize(v4_enabled_); |
328 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); | 338 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); |
329 | 339 |
330 // Track the safe browsing preference of existing profiles. | 340 // Track the safe browsing preference of existing profiles. |
331 // The SafeBrowsingService will be started if any existing profile has the | 341 // The SafeBrowsingService will be started if any existing profile has the |
332 // preference enabled. It will also listen for updates to the preferences. | 342 // preference enabled. It will also listen for updates to the preferences. |
333 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 343 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
334 if (profile_manager) { | 344 if (profile_manager) { |
335 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 345 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
336 // TODO(felt): I believe this for-loop is dead code. Confirm this and | 346 // TODO(felt): I believe this for-loop is dead code. Confirm this and |
337 // remove in a future CL. See https://codereview.chromium.org/1341533002/ | 347 // remove in a future CL. See https://codereview.chromium.org/1341533002/ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 url_request_context_getter_->DisableQuicOnIOThread(); | 418 url_request_context_getter_->DisableQuicOnIOThread(); |
409 } | 419 } |
410 | 420 |
411 const scoped_refptr<SafeBrowsingUIManager>& | 421 const scoped_refptr<SafeBrowsingUIManager>& |
412 SafeBrowsingService::ui_manager() const { | 422 SafeBrowsingService::ui_manager() const { |
413 return ui_manager_; | 423 return ui_manager_; |
414 } | 424 } |
415 | 425 |
416 const scoped_refptr<SafeBrowsingDatabaseManager>& | 426 const scoped_refptr<SafeBrowsingDatabaseManager>& |
417 SafeBrowsingService::database_manager() const { | 427 SafeBrowsingService::database_manager() const { |
418 return enabled_v4_only_ ? v4_local_database_manager() : database_manager_; | 428 return use_v4_only_ ? v4_local_database_manager() : database_manager_; |
419 } | 429 } |
420 | 430 |
421 scoped_refptr<SafeBrowsingNavigationObserverManager> | 431 scoped_refptr<SafeBrowsingNavigationObserverManager> |
422 SafeBrowsingService::navigation_observer_manager() { | 432 SafeBrowsingService::navigation_observer_manager() { |
423 return navigation_observer_manager_; | 433 return navigation_observer_manager_; |
424 } | 434 } |
425 | 435 |
426 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { | 436 SafeBrowsingProtocolManager* SafeBrowsingService::protocol_manager() const { |
427 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 437 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
428 #if defined(SAFE_BROWSING_DB_LOCAL) | 438 #if defined(SAFE_BROWSING_DB_LOCAL) |
429 DCHECK(!enabled_v4_only_); | 439 DCHECK(!use_v4_only_); |
430 return protocol_manager_.get(); | 440 return protocol_manager_.get(); |
431 #else | 441 #else |
432 return nullptr; | 442 return nullptr; |
433 #endif | 443 #endif |
434 } | 444 } |
435 | 445 |
436 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { | 446 SafeBrowsingPingManager* SafeBrowsingService::ping_manager() const { |
437 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 447 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
438 return ping_manager_.get(); | 448 return ping_manager_.get(); |
439 } | 449 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 #endif // defined(OS_WIN) | 559 #endif // defined(OS_WIN) |
550 | 560 |
551 return client_name; | 561 return client_name; |
552 } | 562 } |
553 | 563 |
554 // Any tests that create a DatabaseManager that isn't derived from | 564 // Any tests that create a DatabaseManager that isn't derived from |
555 // LocalSafeBrowsingDatabaseManager should override this to return NULL. | 565 // LocalSafeBrowsingDatabaseManager should override this to return NULL. |
556 SafeBrowsingProtocolManagerDelegate* | 566 SafeBrowsingProtocolManagerDelegate* |
557 SafeBrowsingService::GetProtocolManagerDelegate() { | 567 SafeBrowsingService::GetProtocolManagerDelegate() { |
558 #if defined(SAFE_BROWSING_DB_LOCAL) | 568 #if defined(SAFE_BROWSING_DB_LOCAL) |
559 DCHECK(!enabled_v4_only_); | 569 DCHECK(!use_v4_only_); |
560 return static_cast<LocalSafeBrowsingDatabaseManager*>( | 570 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
561 database_manager_.get()); | 571 database_manager_.get()); |
562 #else | 572 #else |
563 NOTREACHED(); | 573 NOTREACHED(); |
564 return NULL; | 574 return NULL; |
565 #endif | 575 #endif |
566 } | 576 } |
567 | 577 |
568 void SafeBrowsingService::StartOnIOThread( | 578 void SafeBrowsingService::StartOnIOThread( |
569 net::URLRequestContextGetter* url_request_context_getter) { | 579 net::URLRequestContextGetter* url_request_context_getter) { |
570 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 580 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
571 if (enabled_) | 581 if (enabled_) |
572 return; | 582 return; |
573 enabled_ = true; | 583 enabled_ = true; |
574 | 584 |
575 SafeBrowsingProtocolConfig config = GetProtocolConfig(); | 585 SafeBrowsingProtocolConfig config = GetProtocolConfig(); |
576 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); | 586 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); |
577 | 587 |
578 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); | 588 services_delegate_->StartOnIOThread(url_request_context_getter, v4_config); |
579 | 589 |
580 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 590 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
581 if (!enabled_v4_only_) { | 591 if (!use_v4_only_) { |
582 DCHECK(database_manager_.get()); | 592 DCHECK(database_manager_.get()); |
583 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); | 593 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); |
584 } | 594 } |
585 #endif | 595 #endif |
586 | 596 |
587 #if defined(SAFE_BROWSING_DB_LOCAL) | 597 #if defined(SAFE_BROWSING_DB_LOCAL) |
588 if (!enabled_v4_only_) { | 598 if (!use_v4_only_) { |
589 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = | 599 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = |
590 GetProtocolManagerDelegate(); | 600 GetProtocolManagerDelegate(); |
591 if (protocol_manager_delegate) { | 601 if (protocol_manager_delegate) { |
592 protocol_manager_ = SafeBrowsingProtocolManager::Create( | 602 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
593 protocol_manager_delegate, url_request_context_getter, config); | 603 protocol_manager_delegate, url_request_context_getter, config); |
594 protocol_manager_->Initialize(); | 604 protocol_manager_->Initialize(); |
595 } | 605 } |
596 } | 606 } |
597 #endif | 607 #endif |
598 | 608 |
599 DCHECK(!ping_manager_); | 609 DCHECK(!ping_manager_); |
600 ping_manager_ = SafeBrowsingPingManager::Create( | 610 ping_manager_ = SafeBrowsingPingManager::Create( |
601 url_request_context_getter, config); | 611 url_request_context_getter, config); |
602 } | 612 } |
603 | 613 |
604 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 614 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
605 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 615 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
606 | 616 |
607 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) | 617 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) |
608 if (!enabled_v4_only_) { | 618 if (!use_v4_only_) { |
609 database_manager_->StopOnIOThread(shutdown); | 619 database_manager_->StopOnIOThread(shutdown); |
610 } | 620 } |
611 #endif | 621 #endif |
612 ui_manager_->StopOnIOThread(shutdown); | 622 ui_manager_->StopOnIOThread(shutdown); |
613 | 623 |
614 services_delegate_->StopOnIOThread(shutdown); | 624 services_delegate_->StopOnIOThread(shutdown); |
615 | 625 |
616 if (enabled_) { | 626 if (enabled_) { |
617 enabled_ = false; | 627 enabled_ = false; |
618 | 628 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 ping_manager()->ReportThreatDetails(report); | 769 ping_manager()->ReportThreatDetails(report); |
760 } | 770 } |
761 | 771 |
762 void SafeBrowsingService::ProcessResourceRequest( | 772 void SafeBrowsingService::ProcessResourceRequest( |
763 const ResourceRequestInfo& request) { | 773 const ResourceRequestInfo& request) { |
764 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 774 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
765 services_delegate_->ProcessResourceRequest(&request); | 775 services_delegate_->ProcessResourceRequest(&request); |
766 } | 776 } |
767 | 777 |
768 } // namespace safe_browsing | 778 } // namespace safe_browsing |
OLD | NEW |