Repository: electron/electron
File: shell/browser/api/electron_api_session.cc (C++)

Code before:
    }

    void Start(BrowsingDataRemover* remover,
               BrowsingDataRemover::DataType data_type_mask,
               std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
      remover->RemoveWithFilterAndReply(base::Time::Min(), base::Time::Max(),
                                        data_type_mask, kClearOriginTypeAll,
                                        std::move(filter_builder), this);
    }

    // BrowsingDataRemover::Observer:
    void OnBrowsingDataRemoverDone(
        BrowsingDataRemover::DataType failed_data_types) override {
      task_->OnOperationFinished(this, failed_data_types);
    }

   private:
    raw_ptr<ClearDataTask> task_;
    base::ScopedObservation<BrowsingDataRemover, BrowsingDataRemover::Observer>
        observation_{this};
  };

  explicit ClearDataTask(gin_helper::Promise<void> promise)
      : promise_(std::move(promise)) {}

  ~ClearDataTask() override { operations_.clear(); }

  static void StartOperation(
      ClearDataTask* task,
      BrowsingDataRemover* remover,
      BrowsingDataRemover::DataType data_type_mask,
      std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
    // Track this operation
    task->operations_running_ += 1;

    auto operation = std::make_unique<ClearDataOperation>(task, remover);
    operation->Start(remover, data_type_mask, std::move(filter_builder));
    task->operations_.push_back(std::move(operation));
  }

  void OnOperationFinished(
      ClearDataOperation* operation,
      std::optional<BrowsingDataRemover::DataType> failed_data_types) {
    DCHECK_GT(operations_running_, 0);
    operations_running_ -= 1;

    if (failed_data_types.has_value()) {
      failed_data_types_ |= failed_data_types.value();
    }

    if (operation) {

Review comment (suggestion):
Not needed this should already happen when the `operations_` container gets destroyed.
```suggestion
```

Code after:
        : task_(task) {
      observation_.Observe(remover);
    }

    void Start(BrowsingDataRemover* remover,
               BrowsingDataRemover::DataType data_type_mask,
               std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
      remover->RemoveWithFilterAndReply(base::Time::Min(), base::Time::Max(),
                                        data_type_mask, kClearOriginTypeAll,
                                        std::move(filter_builder), this);
    }

    // BrowsingDataRemover::Observer:
    void OnBrowsingDataRemoverDone(
        BrowsingDataRemover::DataType failed_data_types) override {
      task_->OnOperationFinished(this, failed_data_types);
    }

   private:
    raw_ptr<ClearDataTask> task_;
    base::ScopedObservation<BrowsingDataRemover, BrowsingDataRemover::Observer>
        observation_{this};
  };

  explicit ClearDataTask(gin_helper::Promise<void> promise)
      : promise_(std::move(promise)) {}

  static void StartOperation(
      ClearDataTask* task,
      BrowsingDataRemover* remover,
      BrowsingDataRemover::DataType data_type_mask,
      std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
    // Track this operation
    task->operations_running_ += 1;

    auto& operation = task->operations_.emplace_back(
        std::make_unique<ClearDataOperation>(task, remover));
    operation->Start(remover, data_type_mask, std::move(filter_builder));
  }

  void OnOperationFinished(
      ClearDataOperation* operation,
      std::optional<BrowsingDataRemover::DataType> failed_data_types) {
    DCHECK_GT(operations_running_, 0);
    operations_running_ -= 1;

    if (failed_data_types.has_value()) {
      failed_data_types_ |= failed_data_types.value();
    }

    if (operation) {