chromium/components/breadcrumbs/core/breadcrumbs_status.cc

// 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.

#include "components/breadcrumbs/core/breadcrumbs_status.h"

#include <atomic>
#include <optional>

#include "base/command_line.h"
#include "base/rand_util.h"
#include "base/time/time.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/variations_switches.h"
#include "components/version_info/channel.h"

namespace breadcrumbs {

namespace {

// Represents whether breadcrumbs is enabled/disabled from local prefs (the
// default and most common case) or forced to enabled/disabled.
enum class BreadcrumbsEnabledMode {};

// If set to `kFromLocalPrefs`, breadcrumbs is enabled or disabled based on
// Local State prefs like usual. Otherwise, breadcrumbs has been forced either
// on (e.g., for testing) or off (e.g., for Chrome on Android's minimal mode).
std::atomic<BreadcrumbsEnabledMode> breadcrumbs_enabled_mode =;

// The percentage at which breadcrumbs is enabled per channel.
// Enable on most pre-Stable clients to ensure crashes with only a few reports
// have enough breadcrumbs to be useful.
constexpr int kCanaryPercent =;
constexpr int kDevPercent =;
constexpr int kBetaPercent =;
// Enable on a small portion of Stable. This rate is expected to provide enough
// breadcrumbs data while not logging on more clients than necessary.
constexpr int kStablePercent =;

// How long logging should be enabled on a client before re-randomizing.
constexpr auto kEnabledDuration =;

// Returns a random boolean representing whether breadcrumbs should be enabled
// for `channel`. For example, if logging is enabled at 5% on `channel`, this
// has a 5% chance of returning true.
bool GetRandomIsEnabled(version_info::Channel channel) {}

// Returns true if `prefs` contains both breadcrumbs prefs, and the timestamp is
// valid and newer than `kEnabledDuration`.
bool HasRecentBreadcrumbsPrefs(PrefService* prefs) {}

bool IsEnabled(PrefService* prefs,
               std::optional<version_info::Channel> set_for_channel) {}

}  // namespace

constexpr char kEnabledPref[] =;
constexpr char kEnabledTimePref[] =;

bool IsEnabled(PrefService* prefs) {}

bool MaybeEnableBasedOnChannel(PrefService* prefs,
                               version_info::Channel channel) {}

void RegisterPrefs(PrefRegistrySimple* registry) {}

ScopedEnableBreadcrumbsForTesting::ScopedEnableBreadcrumbsForTesting() {}

ScopedEnableBreadcrumbsForTesting::~ScopedEnableBreadcrumbsForTesting() {}

}  // namespace breadcrumbs