Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 720163003: Safe Browsing: Add Omnibox Interaction Incident Reporter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/leak_tracker.h" 13 #include "base/debug/leak_tracker.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/prefs/pref_change_registrar.h" 16 #include "base/prefs/pref_change_registrar.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" 24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 27 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
28 #include "chrome/browser/safe_browsing/database_manager.h" 28 #include "chrome/browser/safe_browsing/database_manager.h"
29 #include "chrome/browser/safe_browsing/download_protection_service.h" 29 #include "chrome/browser/safe_browsing/download_protection_service.h"
30 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.h"
30 #include "chrome/browser/safe_browsing/malware_details.h" 31 #include "chrome/browser/safe_browsing/malware_details.h"
31 #include "chrome/browser/safe_browsing/ping_manager.h" 32 #include "chrome/browser/safe_browsing/ping_manager.h"
32 #include "chrome/browser/safe_browsing/protocol_manager.h" 33 #include "chrome/browser/safe_browsing/protocol_manager.h"
33 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 34 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
34 #include "chrome/browser/safe_browsing/ui_manager.h" 35 #include "chrome/browser/safe_browsing/ui_manager.h"
35 #include "chrome/common/chrome_constants.h" 36 #include "chrome/common/chrome_constants.h"
36 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
39 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Track the safe browsing preference of existing profiles. 240 // Track the safe browsing preference of existing profiles.
240 // The SafeBrowsingService will be started if any existing profile has the 241 // The SafeBrowsingService will be started if any existing profile has the
241 // preference enabled. It will also listen for updates to the preferences. 242 // preference enabled. It will also listen for updates to the preferences.
242 ProfileManager* profile_manager = g_browser_process->profile_manager(); 243 ProfileManager* profile_manager = g_browser_process->profile_manager();
243 if (profile_manager) { 244 if (profile_manager) {
244 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 245 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
245 for (size_t i = 0; i < profiles.size(); ++i) { 246 for (size_t i = 0; i < profiles.size(); ++i) {
246 if (profiles[i]->IsOffTheRecord()) 247 if (profiles[i]->IsOffTheRecord())
247 continue; 248 continue;
248 AddPrefService(profiles[i]->GetPrefs()); 249 AddPrefService(profiles[i]->GetPrefs());
250 AddOmniboxWatcher(profiles[i]);
249 } 251 }
250 } 252 }
251 253
252 // Track profile creation and destruction. 254 // Track profile creation and destruction.
253 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, 255 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
254 content::NotificationService::AllSources()); 256 content::NotificationService::AllSources());
255 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 257 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
256 content::NotificationService::AllSources()); 258 content::NotificationService::AllSources());
257 259
258 #if defined(FULL_SAFE_BROWSING) 260 #if defined(FULL_SAFE_BROWSING)
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 base::Bind(&SafeBrowsingService::StopOnIOThread, this, shutdown)); 517 base::Bind(&SafeBrowsingService::StopOnIOThread, this, shutdown));
516 } 518 }
517 519
518 void SafeBrowsingService::Observe(int type, 520 void SafeBrowsingService::Observe(int type,
519 const content::NotificationSource& source, 521 const content::NotificationSource& source,
520 const content::NotificationDetails& details) { 522 const content::NotificationDetails& details) {
521 switch (type) { 523 switch (type) {
522 case chrome::NOTIFICATION_PROFILE_CREATED: { 524 case chrome::NOTIFICATION_PROFILE_CREATED: {
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
524 Profile* profile = content::Source<Profile>(source).ptr(); 526 Profile* profile = content::Source<Profile>(source).ptr();
525 if (!profile->IsOffTheRecord()) 527 if (!profile->IsOffTheRecord()) {
526 AddPrefService(profile->GetPrefs()); 528 AddPrefService(profile->GetPrefs());
529 AddOmniboxWatcher(profile);
530 }
527 break; 531 break;
528 } 532 }
529 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 533 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
531 Profile* profile = content::Source<Profile>(source).ptr(); 535 Profile* profile = content::Source<Profile>(source).ptr();
532 if (!profile->IsOffTheRecord()) 536 if (!profile->IsOffTheRecord()) {
533 RemovePrefService(profile->GetPrefs()); 537 RemovePrefService(profile->GetPrefs());
538 RemoveOmniboxWatcher(profile);
539 }
534 break; 540 break;
535 } 541 }
536 default: 542 default:
537 NOTREACHED(); 543 NOTREACHED();
538 } 544 }
539 } 545 }
540 546
541 void SafeBrowsingService::AddPrefService(PrefService* pref_service) { 547 void SafeBrowsingService::AddPrefService(PrefService* pref_service) {
542 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end()); 548 DCHECK(prefs_map_.find(pref_service) == prefs_map_.end());
543 PrefChangeRegistrar* registrar = new PrefChangeRegistrar(); 549 PrefChangeRegistrar* registrar = new PrefChangeRegistrar();
544 registrar->Init(pref_service); 550 registrar->Init(pref_service);
545 registrar->Add(prefs::kSafeBrowsingEnabled, 551 registrar->Add(prefs::kSafeBrowsingEnabled,
546 base::Bind(&SafeBrowsingService::RefreshState, 552 base::Bind(&SafeBrowsingService::RefreshState,
547 base::Unretained(this))); 553 base::Unretained(this)));
548 prefs_map_[pref_service] = registrar; 554 prefs_map_[pref_service] = registrar;
549 RefreshState(); 555 RefreshState();
550 } 556 }
551 557
552 void SafeBrowsingService::RemovePrefService(PrefService* pref_service) { 558 void SafeBrowsingService::RemovePrefService(PrefService* pref_service) {
553 if (prefs_map_.find(pref_service) != prefs_map_.end()) { 559 if (prefs_map_.find(pref_service) != prefs_map_.end()) {
554 delete prefs_map_[pref_service]; 560 delete prefs_map_[pref_service];
555 prefs_map_.erase(pref_service); 561 prefs_map_.erase(pref_service);
556 RefreshState(); 562 RefreshState();
557 } else { 563 } else {
558 NOTREACHED(); 564 NOTREACHED();
559 } 565 }
560 } 566 }
561 567
568 void SafeBrowsingService::AddOmniboxWatcher(Profile* profile) {
569 if (!incident_service_)
570 return;
571 DCHECK(omnibox_watcher_map_.find(profile) == omnibox_watcher_map_.end());
572 omnibox_watcher_map_[profile] =
573 new safe_browsing::OmniboxWatcher::OmniboxWatcher(
574 incident_service_->GetAddIncidentCallback(profile));
575 }
576
577 void SafeBrowsingService::RemoveOmniboxWatcher(Profile* profile) {
578 if (!incident_service_)
579 return;
580 if (omnibox_watcher_map_.find(profile) != omnibox_watcher_map_.end()) {
581 delete omnibox_watcher_map_[profile];
582 omnibox_watcher_map_.erase(profile);
583 } else {
584 NOTREACHED();
585 }
586 }
587
562 void SafeBrowsingService::RefreshState() { 588 void SafeBrowsingService::RefreshState() {
563 // Check if any profile requires the service to be active. 589 // Check if any profile requires the service to be active.
564 bool enable = false; 590 bool enable = false;
565 std::map<PrefService*, PrefChangeRegistrar*>::iterator iter; 591 std::map<PrefService*, PrefChangeRegistrar*>::iterator iter;
566 for (iter = prefs_map_.begin(); iter != prefs_map_.end(); ++iter) { 592 for (iter = prefs_map_.begin(); iter != prefs_map_.end(); ++iter) {
567 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) { 593 if (iter->first->GetBoolean(prefs::kSafeBrowsingEnabled)) {
568 enable = true; 594 enable = true;
569 break; 595 break;
570 } 596 }
571 } 597 }
572 598
573 if (enable) 599 if (enable)
574 Start(); 600 Start();
575 else 601 else
576 Stop(false); 602 Stop(false);
577 603
578 #if defined(FULL_SAFE_BROWSING) 604 #if defined(FULL_SAFE_BROWSING)
579 if (csd_service_) 605 if (csd_service_)
580 csd_service_->SetEnabledAndRefreshState(enable); 606 csd_service_->SetEnabledAndRefreshState(enable);
581 if (download_service_) 607 if (download_service_)
582 download_service_->SetEnabled(enable); 608 download_service_->SetEnabled(enable);
583 #endif 609 #endif
584 } 610 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698