#include "chrome/browser/ssl/https_first_mode_settings_tracker.h"
#include <string_view>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/json/values_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/thread_pool.h"
#include "base/time/default_clock.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/ssl/https_upgrades_interceptor.h"
#include "chrome/browser/ssl/https_upgrades_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/content/https_only_mode_blocking_page.h"
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/variations/synthetic_trials.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif
const base::FeatureParam<int> kHttpsAddThreshold{ … };
const base::FeatureParam<int> kHttpsRemoveThreshold{ … };
const base::FeatureParam<int> kHttpAddThreshold{ … };
const base::FeatureParam<int> kHttpRemoveThreshold{ … };
const base::TimeDelta kFallbackEntriesRollingWindowSize = …;
const size_t kMaxRecentFallbackEntryCount = …;
const base::TimeDelta kMinTypicallySecureProfileAge = …;
const base::TimeDelta kMinTypicallySecureObservationTime = …;
const base::FeatureParam<int> kMinTotalEngagementPointsForTypicallySecureUser{ … };
const base::FeatureParam<int> kNavigationCounterRollingWindowSizeInDays{ … };
const base::FeatureParam<int> kMinRecentNavigationsForTypicallySecureUser{ … };
constexpr char kFallbackEventsKey[] = …;
constexpr char kHeuristicStartTimestampKey[] = …;
constexpr char kFallbackEventsPrefTimestampKey[] = …;
constexpr int kNavigationCounterDefaultSaveInterval = …;
namespace {
SiteEngagementHeuristicState;
const char kHttpsFirstModeServiceName[] = …;
const char kHttpsFirstModeSyntheticFieldTrialName[] = …;
const char kHttpsFirstModeSyntheticFieldTrialEnabledGroup[] = …;
const char kHttpsFirstModeSyntheticFieldTrialBalancedGroup[] = …;
const char kHttpsFirstModeSyntheticFieldTrialDisabledGroup[] = …;
base::Clock* g_clock = …;
base::Clock* GetClock() { … }
GURL GetHttpUrlFromHttps(const GURL& https_url) { … }
GURL GetHttpsUrlFromHttp(const GURL& http_url) { … }
std::unique_ptr<KeyedService> BuildService(content::BrowserContext* context) { … }
base::Time GetTimestamp(const base::Value::Dict& dict, const char* key) { … }
std::string GetSyntheticFieldTrialGroupName(HttpsFirstModeSetting setting) { … }
}
HttpsFirstModeService::HttpsFirstModeService(Profile* profile,
base::Clock* clock)
: … { … }
void HttpsFirstModeService::AfterStartup() { … }
void HttpsFirstModeService::
CheckUserIsTypicallySecureAndMaybeEnableHttpsFirstMode() { … }
HttpsFirstModeService::~HttpsFirstModeService() = default;
void HttpsFirstModeService::OnHttpsFirstModePrefChanged() { … }
void HttpsFirstModeService::OnAdvancedProtectionStatusChanged(bool enabled) { … }
bool HttpsFirstModeService::
IsInterstitialEnabledByTypicallySecureUserHeuristic() const { … }
void HttpsFirstModeService::RecordHttpsUpgradeFallbackEvent() { … }
bool HttpsFirstModeService::IsUserTypicallySecure() { … }
bool HttpsFirstModeService::UpdateFallbackEntries(bool add_new_entry) { … }
void HttpsFirstModeService::MaybeEnableHttpsFirstModeForEngagedSites(
base::OnceClosure done_callback) { … }
void HttpsFirstModeService::ProcessEngagedSitesList(
base::OnceClosure done_callback,
const std::vector<site_engagement::mojom::SiteEngagementDetails>& details) { … }
void HttpsFirstModeService::MaybeEnableHttpsFirstModeForUrl(
const GURL& url,
site_engagement::SiteEngagementService* engagement_service,
StatefulSSLHostStateDelegate* state) { … }
HttpsFirstModeSetting HttpsFirstModeService::GetCurrentSetting() const { … }
void HttpsFirstModeService::IncrementRecentNavigationCount() { … }
size_t HttpsFirstModeService::GetRecentNavigationCount() const { … }
void HttpsFirstModeService::SetClockForTesting(base::Clock* clock) { … }
size_t HttpsFirstModeService::GetFallbackEntryCountForTesting() const { … }
HttpsFirstModeService* HttpsFirstModeServiceFactory::GetForProfile(
Profile* profile) { … }
HttpsFirstModeServiceFactory* HttpsFirstModeServiceFactory::GetInstance() { … }
BrowserContextKeyedServiceFactory::TestingFactory
HttpsFirstModeServiceFactory::GetDefaultFactoryForTesting() { … }
HttpsFirstModeServiceFactory::HttpsFirstModeServiceFactory()
: … { … }
HttpsFirstModeServiceFactory::~HttpsFirstModeServiceFactory() = default;
std::unique_ptr<KeyedService>
HttpsFirstModeServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const { … }
base::Clock* HttpsFirstModeServiceFactory::SetClockForTesting(
base::Clock* clock) { … }