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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | |
17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/stl_util.h" | |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
23 #include "base/threading/worker_pool.h" | 23 #include "base/threading/worker_pool.h" |
24 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 326 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
327 content::NotificationService::AllSources()); | 327 content::NotificationService::AllSources()); |
328 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 328 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
329 content::NotificationService::AllSources()); | 329 content::NotificationService::AllSources()); |
330 | 330 |
331 // Register all the delayed analysis to the incident reporting service. | 331 // Register all the delayed analysis to the incident reporting service. |
332 RegisterAllDelayedAnalysis(); | 332 RegisterAllDelayedAnalysis(); |
333 } | 333 } |
334 | 334 |
335 void SafeBrowsingService::ShutDown() { | 335 void SafeBrowsingService::ShutDown() { |
336 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an | 336 // Delete the PrefChangeRegistrars, whose dtors also unregister |this| as an |
337 // observer of the preferences. | 337 // observer of the preferences. |
338 base::STLDeleteValues(&prefs_map_); | 338 prefs_map_.clear(); |
339 | 339 |
340 // Remove Profile creation/destruction observers. | 340 // Remove Profile creation/destruction observers. |
341 prefs_registrar_.RemoveAll(); | 341 prefs_registrar_.RemoveAll(); |
342 | 342 |
343 Stop(true); | 343 Stop(true); |
344 | 344 |
345 services_delegate_->ShutdownServices(); | 345 services_delegate_->ShutdownServices(); |
346 | 346 |
347 // Since URLRequestContextGetters are refcounted, can't count on clearing | 347 // Since URLRequestContextGetters are refcounted, can't count on clearing |
348 // |url_request_context_getter_| to delete it, so need to shut it down first, | 348 // |url_request_context_getter_| to delete it, so need to shut it down first, |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 RemovePrefService(profile->GetPrefs()); | 616 RemovePrefService(profile->GetPrefs()); |
617 break; | 617 break; |
618 } | 618 } |
619 default: | 619 default: |
620 NOTREACHED(); | 620 NOTREACHED(); |
621 } | 621 } |
622 } | 622 } |
623 | 623 |
624 void SafeBrowsingService::AddPrefService(PrefService* pref_service) { | 624 void SafeBrowsingService::AddPrefService(PrefService* pref_service) { |
625 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end()); | 625 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end()); |
626 PrefChangeRegistrar* registrar = new PrefChangeRegistrar(); | 626 std::unique_ptr<PrefChangeRegistrar> registrar = |
627 base::MakeUnique<PrefChangeRegistrar>(); | |
627 registrar->Init(pref_service); | 628 registrar->Init(pref_service); |
628 registrar->Add(prefs::kSafeBrowsingEnabled, | 629 registrar->Add(prefs::kSafeBrowsingEnabled, |
629 base::Bind(&SafeBrowsingService::RefreshState, | 630 base::Bind(&SafeBrowsingService::RefreshState, |
630 base::Unretained(this))); | 631 base::Unretained(this))); |
631 // ClientSideDetectionService will need to be refresh the models | 632 // ClientSideDetectionService will need to be refresh the models |
632 // renderers have if extended-reporting changes. | 633 // renderers have if extended-reporting changes. |
633 registrar->Add( | 634 registrar->Add( |
634 GetExtendedReportingPrefName(), | 635 GetExtendedReportingPrefName(), |
635 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); | 636 base::Bind(&SafeBrowsingService::RefreshState, base::Unretained(this))); |
636 prefs_map_[pref_service] = registrar; | 637 prefs_map_[pref_service] = std::move(registrar); |
637 RefreshState(); | 638 RefreshState(); |
638 | 639 |
639 // Record the current pref state. | 640 // Record the current pref state. |
640 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.General", | 641 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.General", |
641 pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 642 pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
642 // Extended Reporting metrics are handled together elsewhere. | 643 // Extended Reporting metrics are handled together elsewhere. |
643 RecordExtendedReportingMetrics(*pref_service); | 644 RecordExtendedReportingMetrics(*pref_service); |
644 } | 645 } |
645 | 646 |
646 void SafeBrowsingService::RemovePrefService(PrefService* pref_service) { | 647 void SafeBrowsingService::RemovePrefService(PrefService* pref_service) { |
647 if (prefs_map_.find(pref_service) != prefs_map_.end()) { | 648 if (prefs_map_.find(pref_service) != prefs_map_.end()) { |
648 delete prefs_map_[pref_service]; | |
649 prefs_map_.erase(pref_service); | 649 prefs_map_.erase(pref_service); |
650 RefreshState(); | 650 RefreshState(); |
651 } else { | 651 } else { |
652 NOTREACHED(); | 652 NOTREACHED(); |
653 } | 653 } |
654 } | 654 } |
655 | 655 |
656 std::unique_ptr<SafeBrowsingService::StateSubscription> | 656 std::unique_ptr<SafeBrowsingService::StateSubscription> |
657 SafeBrowsingService::RegisterStateCallback( | 657 SafeBrowsingService::RegisterStateCallback( |
658 const base::Callback<void(void)>& callback) { | 658 const base::Callback<void(void)>& callback) { |
659 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 659 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
660 return state_callback_list_.Add(callback); | 660 return state_callback_list_.Add(callback); |
661 } | 661 } |
662 | 662 |
663 void SafeBrowsingService::RefreshState() { | 663 void SafeBrowsingService::RefreshState() { |
664 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 664 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
665 // Check if any profile requires the service to be active. | 665 // Check if any profile requires the service to be active. |
666 bool enable = false; | 666 bool enable = false; |
667 std::map<PrefService*, PrefChangeRegistrar*>::iterator iter; | 667 for (auto iter = prefs_map_.begin(); iter != prefs_map_.end(); ++iter) { |
Nico
2016/10/24 18:41:02
nit: foreach?
Avi (use Gerrit)
2016/10/24 19:15:37
Done.
| |
668 for (iter = prefs_map_.begin(); iter != prefs_map_.end(); ++iter) { | |
669 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 668 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
670 enable = true; | 669 enable = true; |
671 break; | 670 break; |
672 } | 671 } |
673 } | 672 } |
674 | 673 |
675 enabled_by_prefs_ = enable; | 674 enabled_by_prefs_ = enable; |
676 | 675 |
677 if (enable) | 676 if (enable) |
678 Start(); | 677 Start(); |
(...skipping 21 matching lines...) Expand all Loading... | |
700 ping_manager()->ReportThreatDetails(report); | 699 ping_manager()->ReportThreatDetails(report); |
701 } | 700 } |
702 | 701 |
703 void SafeBrowsingService::ProcessResourceRequest( | 702 void SafeBrowsingService::ProcessResourceRequest( |
704 const ResourceRequestInfo& request) { | 703 const ResourceRequestInfo& request) { |
705 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 704 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
706 services_delegate_->ProcessResourceRequest(&request); | 705 services_delegate_->ProcessResourceRequest(&request); |
707 } | 706 } |
708 | 707 |
709 } // namespace safe_browsing | 708 } // namespace safe_browsing |
OLD | NEW |