Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chrome_password_protection_service.h" | 5 #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/metrics/field_trial_params.h" | |
| 8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" |
| 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 16 #include "components/browser_sync/profile_sync_service.h" | |
| 17 #include "components/safe_browsing/password_protection/password_protection_reque st.h" | |
| 18 #include "components/safe_browsing_db/database_manager.h" | |
| 14 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 19 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 15 | 20 |
| 16 using content::BrowserThread; | 21 using content::BrowserThread; |
| 17 | 22 |
| 18 namespace safe_browsing { | 23 namespace safe_browsing { |
| 19 | 24 |
| 20 namespace { | 25 namespace { |
| 21 // The number of user gestures we trace back for login event attribution. | 26 // The number of user gestures we trace back for login event attribution. |
| 22 const int kPasswordEventAttributionUserGestureLimit = 2; | 27 const int kPasswordEventAttributionUserGestureLimit = 2; |
| 23 } | 28 } |
| 24 | 29 |
| 25 const base::Feature kPasswordProtectionPingOnly{ | |
| 26 "PasswordProtectionPingOnly", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 27 | |
| 28 ChromePasswordProtectionService::ChromePasswordProtectionService( | 30 ChromePasswordProtectionService::ChromePasswordProtectionService( |
| 29 SafeBrowsingService* sb_service, | 31 SafeBrowsingService* sb_service, |
| 30 Profile* profile) | 32 Profile* profile) |
| 31 : PasswordProtectionService( | 33 : PasswordProtectionService( |
| 32 sb_service->database_manager(), | 34 sb_service->database_manager(), |
| 33 sb_service->url_request_context(), | 35 sb_service->url_request_context(), |
| 34 HistoryServiceFactory::GetForProfile( | 36 HistoryServiceFactory::GetForProfile( |
| 35 profile, | 37 profile, |
| 36 ServiceAccessType::EXPLICIT_ACCESS), | 38 ServiceAccessType::EXPLICIT_ACCESS), |
| 37 HostContentSettingsMapFactory::GetForProfile(profile)), | 39 HostContentSettingsMapFactory::GetForProfile(profile)), |
| 38 profile_(profile), | 40 profile_(profile), |
| 39 navigation_observer_manager_(sb_service->navigation_observer_manager()) { | 41 navigation_observer_manager_(sb_service->navigation_observer_manager()) { |
| 40 DCHECK(profile_); | 42 DCHECK(profile_); |
| 41 } | 43 } |
| 42 | 44 |
| 43 ChromePasswordProtectionService::~ChromePasswordProtectionService() { | 45 ChromePasswordProtectionService::~ChromePasswordProtectionService() { |
| 44 UMA_HISTOGRAM_COUNTS_1000( | 46 if (content_settings()) { |
| 45 "PasswordProtection.NumberOfCachedVerdictBeforeShutdown", | 47 UMA_HISTOGRAM_COUNTS_1000( |
| 46 GetStoredVerdictCount()); | 48 "PasswordProtection.NumberOfCachedVerdictBeforeShutdown", |
| 49 GetStoredVerdictCount()); | |
| 50 } | |
| 47 } | 51 } |
| 48 | 52 |
| 49 void ChromePasswordProtectionService::FillReferrerChain( | 53 void ChromePasswordProtectionService::FillReferrerChain( |
| 50 const GURL& event_url, | 54 const GURL& event_url, |
| 51 int event_tab_id, | 55 int event_tab_id, |
| 52 LoginReputationClientRequest::Frame* frame) { | 56 LoginReputationClientRequest::Frame* frame) { |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 54 SafeBrowsingNavigationObserverManager::AttributionResult result = | 58 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 55 navigation_observer_manager_->IdentifyReferrerChainByEventURL( | 59 navigation_observer_manager_->IdentifyReferrerChainByEventURL( |
| 56 event_url, event_tab_id, kPasswordEventAttributionUserGestureLimit, | 60 event_url, event_tab_id, kPasswordEventAttributionUserGestureLimit, |
| 57 frame->mutable_referrer_chain()); | 61 frame->mutable_referrer_chain()); |
| 58 UMA_HISTOGRAM_COUNTS_100( | 62 UMA_HISTOGRAM_COUNTS_100( |
| 59 "SafeBrowsing.ReferrerURLChainSize.PasswordEventAttribution", | 63 "SafeBrowsing.ReferrerURLChainSize.PasswordEventAttribution", |
| 60 frame->referrer_chain().size()); | 64 frame->referrer_chain().size()); |
| 61 UMA_HISTOGRAM_ENUMERATION( | 65 UMA_HISTOGRAM_ENUMERATION( |
| 62 "SafeBrowsing.ReferrerAttributionResult.PasswordEventAttribution", result, | 66 "SafeBrowsing.ReferrerAttributionResult.PasswordEventAttribution", result, |
| 63 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 67 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 64 } | 68 } |
| 65 | 69 |
| 66 bool ChromePasswordProtectionService::IsExtendedReporting() { | 70 bool ChromePasswordProtectionService::IsExtendedReporting() { |
| 67 return IsExtendedReportingEnabled(*profile_->GetPrefs()); | 71 return IsExtendedReportingEnabled(*profile_->GetPrefs()); |
| 68 } | 72 } |
| 69 | 73 |
| 70 bool ChromePasswordProtectionService::IsIncognito() { | 74 bool ChromePasswordProtectionService::IsIncognito() { |
| 71 DCHECK(profile_); | 75 DCHECK(profile_); |
| 72 return profile_->IsOffTheRecord(); | 76 return profile_->IsOffTheRecord(); |
| 73 } | 77 } |
| 74 | 78 |
| 75 bool ChromePasswordProtectionService::IsPingingEnabled() { | 79 bool ChromePasswordProtectionService::IsPingingEnabled( |
| 76 return base::FeatureList::IsEnabled(kPasswordProtectionPingOnly); | 80 const base::Feature& feature) { |
| 81 if (!base::FeatureList::IsEnabled(feature)) { | |
| 82 return false; | |
| 83 } | |
| 84 | |
| 85 bool allowed_incognito = | |
| 86 base::GetFieldTrialParamByFeatureAsBool(feature, "incognito", false); | |
| 87 if (IsIncognito() && !allowed_incognito) | |
| 88 return false; | |
| 89 | |
| 90 bool allowed_all_population = | |
| 91 base::GetFieldTrialParamByFeatureAsBool(feature, "all_population", false); | |
| 92 if (!allowed_all_population) { | |
|
Nathan Parker
2017/05/05 22:51:41
nit (or not, you decide which you like better):
i
Jialiu Lin
2017/05/05 22:58:51
Acknowledged.
| |
| 93 bool allowed_extended_reporting = base::GetFieldTrialParamByFeatureAsBool( | |
| 94 feature, "extended_reporting", false); | |
| 95 if (IsExtendedReporting() && allowed_extended_reporting) | |
| 96 return true; // Ping enabled because this user opted in extended | |
| 97 // reporting. | |
| 98 | |
| 99 bool allowed_history_sync = | |
| 100 base::GetFieldTrialParamByFeatureAsBool(feature, "history_sync", false); | |
| 101 if (IsHistorySyncEnabled() && allowed_history_sync) | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 return allowed_all_population; | |
| 77 } | 106 } |
| 78 | 107 |
| 108 bool ChromePasswordProtectionService::IsHistorySyncEnabled() { | |
| 109 browser_sync::ProfileSyncService* sync = | |
| 110 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | |
| 111 return sync && sync->IsSyncActive() && !sync->IsLocalSyncEnabled() && | |
| 112 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); | |
| 113 } | |
| 114 | |
| 115 ChromePasswordProtectionService::ChromePasswordProtectionService() | |
| 116 : PasswordProtectionService(nullptr, nullptr, nullptr, nullptr) {} | |
| 79 } // namespace safe_browsing | 117 } // namespace safe_browsing |
| OLD | NEW |