feature_promo_handle.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/user_education/common/feature_promo_handle.h"
  5. #include "components/user_education/common/feature_promo_controller.h"
  6. namespace user_education {
  7. FeaturePromoHandle::FeaturePromoHandle() = default;
  8. FeaturePromoHandle::FeaturePromoHandle(
  9. base::WeakPtr<FeaturePromoController> controller,
  10. const base::Feature* feature)
  11. : controller_(std::move(controller)), feature_(feature) {
  12. DCHECK(feature_);
  13. }
  14. FeaturePromoHandle::FeaturePromoHandle(FeaturePromoHandle&& other)
  15. : controller_(std::move(other.controller_)),
  16. feature_(std::exchange(other.feature_, nullptr)) {}
  17. FeaturePromoHandle::~FeaturePromoHandle() {
  18. Release();
  19. }
  20. FeaturePromoHandle& FeaturePromoHandle::operator=(FeaturePromoHandle&& other) {
  21. if (this != &other) {
  22. Release();
  23. controller_ = std::move(other.controller_);
  24. feature_ = std::exchange(other.feature_, nullptr);
  25. }
  26. return *this;
  27. }
  28. void FeaturePromoHandle::Release() {
  29. if (controller_)
  30. controller_->FinishContinuedPromo(*feature_);
  31. controller_.reset();
  32. feature_ = nullptr;
  33. }
  34. } // namespace user_education