// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/https_upgrades/model/https_upgrade_service_impl.h"

#import "base/time/default_clock.h"
#import "base/time/time.h"
#import "ios/chrome/browser/content_settings/model/host_content_settings_map_factory.h"

namespace {
// The default expiration for HTTPS-First Mode bypasses is 15 days.
const base::TimeDelta kDeltaDefaultExpiration = base::Days(15);
}  // namespace

HttpsUpgradeServiceImpl::HttpsUpgradeServiceImpl(
    bool off_the_record,
    HostContentSettingsMap* host_content_settings_map)
    : clock_(std::make_unique<base::DefaultClock>()),
      allowlist_(host_content_settings_map,
                 clock_.get(),
                 kDeltaDefaultExpiration),
      off_the_record_(off_the_record) {}

HttpsUpgradeServiceImpl::~HttpsUpgradeServiceImpl() = default;

bool HttpsUpgradeServiceImpl::IsHttpAllowedForHost(
    const std::string& host) const {
  return allowlist_.IsHttpAllowedForHost(host, off_the_record_);
}

void HttpsUpgradeServiceImpl::AllowHttpForHost(const std::string& host) {
  allowlist_.AllowHttpForHost(host, off_the_record_);
}

void HttpsUpgradeServiceImpl::ClearAllowlist(base::Time delete_begin,
                                             base::Time delete_end) {
  allowlist_.ClearAllowlist(delete_begin, delete_end);
}
