1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/safe_browsing/core/browser/realtime/policy_engine.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "components/enterprise/connectors/core/common.h"
#include "components/enterprise/connectors/core/connectors_prefs.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/utils.h"
#include "components/unified_consent/pref_names.h"
#include "components/user_prefs/user_prefs.h"
#include "components/variations/service/variations_service.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/metrics/field_trial_params.h"
#include "base/system/sys_info.h"
#endif
namespace {
// Enum representing reasons for the real time URL lookup to
// choose the consumer version instead of the enterprise version.
enum class ConsumerVersionReason {
// The total number of checks. This value should be used as the denominator
// when calculating the percentage of a specific reason below.
TOTAL_CHECKS = 0,
// IS_OFF_THE_RECORD = 1, deprecated.
INVALID_DM_TOKEN = 2,
POLICY_DISABLED = 3,
IS_INCOGNITO = 4,
kMaxValue = IS_INCOGNITO
};
} // namespace
namespace safe_browsing {
// static
bool RealTimePolicyEngine::IsInExcludedCountry(
const std::string& country_code) {
return base::Contains(GetExcludedCountries(), country_code);
}
// static
bool RealTimePolicyEngine::IsUserMbbOptedIn(PrefService* pref_service) {
return pref_service->GetBoolean(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled);
}
// static
bool RealTimePolicyEngine::IsUserEpOptedIn(PrefService* pref_service) {
return IsEnhancedProtectionEnabled(*pref_service);
}
// static
bool RealTimePolicyEngine::CanPerformFullURLLookup(
PrefService* pref_service,
bool is_off_the_record,
variations::VariationsService* variations_service) {
if (is_off_the_record) {
return false;
}
// |variations_service| can be nullptr during shutdown and in tests.
if (variations_service &&
IsInExcludedCountry(variations_service->GetLatestCountry())) {
return false;
}
return HasPrefPermissionsToPerformFullURLLookup(pref_service);
}
// static
bool RealTimePolicyEngine::CanPerformFullURLLookupWithToken(
PrefService* pref_service,
bool is_off_the_record,
ClientConfiguredForTokenFetchesCallback client_callback,
variations::VariationsService* variations_service) {
if (!CanPerformFullURLLookup(pref_service, is_off_the_record,
variations_service)) {
return false;
}
return std::move(client_callback).Run(IsUserEpOptedIn(pref_service));
}
// static
bool RealTimePolicyEngine::HasPrefPermissionsToPerformFullURLLookup(
PrefService* pref_service) {
return IsUserEpOptedIn(pref_service) || IsUserMbbOptedIn(pref_service);
}
// static
bool RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup(
const PrefService* pref_service,
bool has_valid_dm_token,
bool is_off_the_record,
bool is_guest_profile) {
base::UmaHistogramEnumeration("SafeBrowsing.RT.ConsumerVersionReason",
ConsumerVersionReason::TOTAL_CHECKS);
if (is_off_the_record && !is_guest_profile) {
base::UmaHistogramEnumeration("SafeBrowsing.RT.ConsumerVersionReason",
ConsumerVersionReason::IS_INCOGNITO);
return false;
}
if (!has_valid_dm_token) {
base::UmaHistogramEnumeration("SafeBrowsing.RT.ConsumerVersionReason",
ConsumerVersionReason::INVALID_DM_TOKEN);
return false;
}
if (pref_service->GetInteger(
enterprise_connectors::kEnterpriseRealTimeUrlCheckMode) !=
enterprise_connectors::REAL_TIME_CHECK_FOR_MAINFRAME_ENABLED) {
base::UmaHistogramEnumeration("SafeBrowsing.RT.ConsumerVersionReason",
ConsumerVersionReason::POLICY_DISABLED);
return false;
}
return true;
}
} // namespace safe_browsing
|