// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_BROWSING_DATA_MODEL_BROWSING_DATA_REMOVER_H_
#define IOS_CHROME_BROWSER_BROWSING_DATA_MODEL_BROWSING_DATA_REMOVER_H_
#include "base/functional/callback.h"
#include "base/observer_list.h"
#include "components/browsing_data/core/browsing_data_utils.h"
#include "components/keyed_service/core/keyed_service.h"
#include "ios/chrome/browser/browsing_data/model/browsing_data_remove_mask.h"
#import "ios/chrome/browser/browsing_data/model/tabs_closure_util.h"
class BrowsingDataRemoverObserver;
// BrowsingDataRemover is responsible for removing data related to
// browsing: history, downloads, cookies, ...
class BrowsingDataRemover : public KeyedService {
public:
BrowsingDataRemover();
BrowsingDataRemover(const BrowsingDataRemover&) = delete;
BrowsingDataRemover& operator=(const BrowsingDataRemover&) = delete;
~BrowsingDataRemover() override;
// Returns a weak pointer to BrowsingDataRemover.
base::WeakPtr<BrowsingDataRemover> AsWeakPtr();
// Is the service currently in the process of removing data?
virtual bool IsRemoving() const = 0;
// Removes browsing data for the given `time_period` with data types specified
// by `remove_mask`. The `callback` is invoked asynchronously when the data
// has been removed.
virtual void Remove(browsing_data::TimePeriod time_period,
BrowsingDataRemoveMask remove_mask,
base::OnceClosure callback) = 0;
// A version of `Remove` that removes browsing data between a given
// `start_time` and `end_time` instead of a pre-specified `TimePeriod`.
virtual void RemoveInRange(base::Time start_time,
base::Time end_time,
BrowsingDataRemoveMask mask,
base::OnceClosure callback) = 0;
// Allows the remover to have cached information in order to close tabs as
// part of the removal of browsing data.
virtual void SetCachedTabsInfo(
tabs_closure_util::WebStateIDToTime cached_tabs_info) = 0;
// Adds/removes `observer` from the list of observers notified when data is
// removed by BrowsingDataRemover.
void AddObserver(BrowsingDataRemoverObserver* observer);
void RemoveObserver(BrowsingDataRemoverObserver* observer);
protected:
// Invokes `OnBrowsingDataRemoved` on all registered observers.
void NotifyBrowsingDataRemoved(BrowsingDataRemoveMask mask);
private:
base::ObserverList<BrowsingDataRemoverObserver, true> observers_;
base::WeakPtrFactory<BrowsingDataRemover> weak_factory_{this};
};
#endif // IOS_CHROME_BROWSER_BROWSING_DATA_MODEL_BROWSING_DATA_REMOVER_H_