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

Code before:
    }

    // This static method counts as an operation.
    task->OnOperationFinished(nullptr, std::nullopt);
  }

 private:
  // An individual |content::BrowsingDataRemover::Remove...| operation as part
  // of a full |ClearDataTask|. This class is owned by ClearDataTask and cleaned
  // up either when the operation completes or when ClearDataTask is destroyed.
  class ClearDataOperation : private BrowsingDataRemover::Observer {
   public:
    ClearDataOperation(ClearDataTask* task, BrowsingDataRemover* remover)
        : 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)) {}

  ~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);

Review comment (refactor):
How about the following, it would simplify the changeset.

```
static std::unique_ptr<ClearDataOperation> Run(ClearDataTask* task,
                    BrowsingDataRemover* remover,
                    BrowsingDataRemover::DataType data_type_mask,
                    std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
      auto operation = std::make_unique<ClearDataOperation>(task, remover);

      remover->RemoveWithFilterAndReply(base::Time::Min(), base::Time::Max(),
                                        data_type_mask, kClearOriginTypeAll,
                                        std::move(filter_builder), operation.get());
         return operation;
    }

Code after:

      StartOperation(task, remover, data_type_mask, std::move(filter_builder));
    }

    // This static method counts as an operation.
    task->OnOperationFinished(nullptr, std::nullopt);
  }

 private:
  // An individual |content::BrowsingDataRemover::Remove...| operation as part
  // of a full |ClearDataTask|. This class is owned by ClearDataTask and cleaned
  // up either when the operation completes or when ClearDataTask is destroyed.
  class ClearDataOperation : private BrowsingDataRemover::Observer {
   public:
    ClearDataOperation(ClearDataTask* task, BrowsingDataRemover* remover)
        : 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(