blob: f1e4646f18797172ba22f591cfbaaf274525b1a0 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "extensions/common/extension_id.h"
#include "net/base/backoff_entry.h"
namespace content {
class BrowserContext;
namespace extensions {
// Class that asks ExtensionService to reinstall corrupted policy extensions.
// If a reinstallation fails for some reason (e.g. network unavailability) then
// it will retry reinstallation with backoff.
class PolicyExtensionReinstaller {
using ReinstallCallback =
base::RepeatingCallback<void(base::OnceClosure callback,
base::TimeDelta delay)>;
explicit PolicyExtensionReinstaller(content::BrowserContext* context);
// Notifies this reinstaller about a policy extension corruption.
void NotifyExtensionDisabledDueToCorruption();
// For tests, overrides the default action to take to initiate policy
// force-reinstalls.
static void set_policy_reinstall_action_for_test(ReinstallCallback* action);
void Fire();
base::TimeDelta GetNextFireDelay();
void ScheduleNextReinstallAttempt();
content::BrowserContext* const context_ = nullptr;
net::BackoffEntry backoff_entry_;
// Whether or not there is a pending PostTask to Fire().
bool scheduled_fire_pending_ = false;
base::WeakPtrFactory<PolicyExtensionReinstaller> weak_factory_{this};
} // namespace extensions