#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include <algorithm>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "build/build_config.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_service.h"
#include "components/policy/core/common/cloud/user_cloud_policy_store.h"
namespace policy {
namespace {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
BASE_FEATURE(…);
#endif
base::Clock* clock_for_testing_ = …;
const base::Clock* GetClock() { … }
base::TickClock* tick_clock_for_testing_ = …;
const base::TickClock* GetTickClock() { … }
}
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
const int64_t CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs =
24 * 60 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kUnmanagedRefreshDelayMs =
24 * 60 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kWithInvalidationsRefreshDelayMs =
24 * 60 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kInitialErrorRetryDelayMs =
5 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kRefreshDelayMinMs =
30 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kRefreshDelayMaxMs =
7 * 24 * 60 * 60 * 1000;
const int64_t CloudPolicyRefreshScheduler::kRandomSaltDelayMaxValueMs =
5 * 60 * 1000;
#else
const int64_t CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs = …;
const int64_t CloudPolicyRefreshScheduler::kUnmanagedRefreshDelayMs = …;
const int64_t CloudPolicyRefreshScheduler::kWithInvalidationsRefreshDelayMs = …;
const int64_t CloudPolicyRefreshScheduler::kInitialErrorRetryDelayMs = …;
const int64_t CloudPolicyRefreshScheduler::kRefreshDelayMinMs = …;
const int64_t CloudPolicyRefreshScheduler::kRefreshDelayMaxMs = …;
const int64_t CloudPolicyRefreshScheduler::kRandomSaltDelayMaxValueMs = …;
#endif
CloudPolicyRefreshScheduler::CloudPolicyRefreshScheduler(
CloudPolicyClient* client,
CloudPolicyStore* store,
CloudPolicyService* service,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
network::NetworkConnectionTrackerGetter network_connection_tracker_getter)
: … { … }
CloudPolicyRefreshScheduler::~CloudPolicyRefreshScheduler() { … }
void CloudPolicyRefreshScheduler::SetDesiredRefreshDelay(
int64_t refresh_delay) { … }
int64_t CloudPolicyRefreshScheduler::GetActualRefreshDelay() const { … }
void CloudPolicyRefreshScheduler::RefreshSoon(PolicyFetchReason reason) { … }
void CloudPolicyRefreshScheduler::SetInvalidationServiceAvailability(
bool is_available) { … }
void CloudPolicyRefreshScheduler::OnPolicyFetched(CloudPolicyClient* client) { … }
void CloudPolicyRefreshScheduler::OnRegistrationStateChanged(
CloudPolicyClient* client) { … }
void CloudPolicyRefreshScheduler::OnClientError(CloudPolicyClient* client) { … }
void CloudPolicyRefreshScheduler::OnStoreLoaded(CloudPolicyStore* store) { … }
void CloudPolicyRefreshScheduler::OnStoreError(CloudPolicyStore* store) { … }
void CloudPolicyRefreshScheduler::OnConnectionChanged(
network::mojom::ConnectionType type) { … }
void CloudPolicyRefreshScheduler::UpdateLastRefreshFromPolicy() { … }
void CloudPolicyRefreshScheduler::ScheduleRefresh() { … }
void CloudPolicyRefreshScheduler::PerformRefresh(PolicyFetchReason reason) { … }
void CloudPolicyRefreshScheduler::RefreshAfter(int delta_ms,
PolicyFetchReason reason) { … }
void CloudPolicyRefreshScheduler::CancelRefresh() { … }
void CloudPolicyRefreshScheduler::UpdateLastRefresh() { … }
void CloudPolicyRefreshScheduler::OnPolicyRefreshed(bool success) { … }
base::ScopedClosureRunner CloudPolicyRefreshScheduler::OverrideClockForTesting(
base::Clock* clock_for_testing) { … }
base::ScopedClosureRunner
CloudPolicyRefreshScheduler::OverrideTickClockForTesting(
base::TickClock* tick_clock_for_testing) { … }
void CloudPolicyRefreshScheduler::AddObserver(
CloudPolicyRefreshSchedulerObserver* observer) { … }
void CloudPolicyRefreshScheduler::RemoveObserver(
CloudPolicyRefreshSchedulerObserver* observer) { … }
}