#include "chrome/browser/web_applications/web_app_pref_guardrails.h"
#include <optional>
#include <string>
#include <string_view>
#include "base/check.h"
#include "base/json/values_util.h"
#include "base/strings/strcat.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_features.h"
namespace web_app {
namespace {
bool TimeOccurredWithinDays(std::optional<base::Time> time, int days) { … }
const base::Value::Dict* GetWebAppDictionary(const PrefService* pref_service,
const webapps::AppId& app_id) { … }
base::Value::Dict& UpdateWebAppDictionary(
ScopedDictPrefUpdate& web_apps_prefs_update,
const webapps::AppId& app_id) { … }
}
std::optional<int> GetIntWebAppPref(const PrefService* pref_service,
const webapps::AppId& app_id,
std::string_view path) { … }
std::optional<base::Time> GetTimeWebAppPref(const PrefService* pref_service,
const webapps::AppId& app_id,
std::string_view path) { … }
WebAppPrefGuardrails WebAppPrefGuardrails::GetForDesktopInstallIph(
PrefService* pref_service) { … }
WebAppPrefGuardrails WebAppPrefGuardrails::GetForMlInstallPrompt(
PrefService* pref_service) { … }
WebAppPrefGuardrails WebAppPrefGuardrails::GetForNavigationCapturingIph(
PrefService* pref_service) { … }
void WebAppPrefGuardrails::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
WebAppPrefGuardrails::~WebAppPrefGuardrails() = default;
void WebAppPrefGuardrails::RecordIgnore(const webapps::AppId& app_id,
base::Time time) { … }
void WebAppPrefGuardrails::RecordDismiss(const webapps::AppId& app_id,
base::Time time) { … }
void WebAppPrefGuardrails::RecordAccept(const webapps::AppId& app_id) { … }
bool WebAppPrefGuardrails::IsBlockedByGuardrails(const webapps::AppId& app_id) { … }
WebAppPrefGuardrails::WebAppPrefGuardrails(
PrefService* pref_service,
const GuardrailData& guardrail_data,
const GuardrailPrefNames& guardrail_pref_names,
std::optional<int> max_days_to_store_guardrails)
: … { … }
std::optional<std::string> WebAppPrefGuardrails::IsAppBlocked(
const webapps::AppId& app_id) { … }
std::optional<std::string> WebAppPrefGuardrails::IsGloballyBlocked() { … }
void WebAppPrefGuardrails::UpdateAppSpecificNotAcceptedPrefs(
const webapps::AppId& app_id,
base::Time time,
std::string_view time_path) { … }
void WebAppPrefGuardrails::UpdateGlobalNotAcceptedPrefs(
base::Time time,
std::string_view time_path) { … }
bool WebAppPrefGuardrails::ShouldResetGlobalGuardrails() { … }
void WebAppPrefGuardrails::ResetGlobalGuardrails(const webapps::AppId& app_id) { … }
bool WebAppPrefGuardrails::IsGlobalBlockActive() { … }
void WebAppPrefGuardrails::LogGlobalBlockReason(
ScopedDictPrefUpdate& global_update,
const std::string& reason) { … }
void WebAppPrefGuardrails::UpdateTimeWebAppPref(const webapps::AppId& app_id,
std::string_view path,
base::Time value) { … }
void WebAppPrefGuardrails::UpdateIntWebAppPref(const webapps::AppId& app_id,
std::string_view path,
int value) { … }
}