1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64

ash / birch / birch_item_remover.h [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_BIRCH_BIRCH_ITEM_REMOVER_H_
#define ASH_BIRCH_BIRCH_ITEM_REMOVER_H_

#include <memory>

#include "ash/ash_export.h"
#include "ash/birch/birch_item.h"
#include "ash/birch/removed_items.pb.h"
#include "ash/utility/persistent_proto.h"
#include "base/functional/callback_forward.h"

namespace ash {

class BirchCalendarItem;
class BirchItem;
class BirchTabItem;

// Manages a list of BirchItems which have been removed by the user. Removed
// items are recorded using a persistent proto. BirchItem lists can be filtered
// to erase any items that have been removed by the user. Removed items are
// written to disk immediately as a posted task with no delay and no queueing.
class ASH_EXPORT BirchItemRemover {
 public:
  // `path` is the file path which the persistent proto is written to.
  // `on_init_callback` will be called once the underlying pesrsistent proto has
  // completed initialization.
  explicit BirchItemRemover(base::FilePath path,
                            base::OnceClosure on_init_callback);
  BirchItemRemover(const BirchItemRemover&) = delete;
  BirchItemRemover& operator=(const BirchItemRemover&) = delete;
  ~BirchItemRemover();

  // Whether the underlying persistent proto has been initialized.
  bool Initialized();

  // Record the BirchItem to be removed persistently.
  void RemoveItem(BirchItem* item);

  // Erases from the BirchItem list any items which have been removed by the
  // user. The list is mutated in place.
  void FilterRemovedTabs(std::vector<BirchTabItem>* tab_items);
  void FilterRemovedLastActiveItems(std::vector<BirchLastActiveItem>* items);
  void FilterRemovedMostVisitedItems(std::vector<BirchMostVisitedItem>* items);
  void FilterRemovedSelfShareItems(
      std::vector<BirchSelfShareItem>* self_share_items);
  void FilterRemovedCalendarItems(
      std::vector<BirchCalendarItem>* calendar_items);
  void FilterRemovedAttachmentItems(
      std::vector<BirchAttachmentItem>* file_items);
  void FilterRemovedFileItems(std::vector<BirchFileItem>* file_items);

  void SetProtoInitCallbackForTest(base::OnceClosure callback);

 private:
  PersistentProto<RemovedItemsProto> removed_items_proto_;
};

}  // namespace ash

#endif  // ASH_BIRCH_BIRCH_ITEM_REMOVER_H_