interested_data_types_manager.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2020 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/sync/invalidations/interested_data_types_manager.h"
  5. #include <utility>
  6. #include "base/feature_list.h"
  7. #include "components/sync/base/features.h"
  8. #include "components/sync/base/model_type.h"
  9. #include "components/sync/invalidations/interested_data_types_handler.h"
  10. namespace syncer {
  11. InterestedDataTypesManager::InterestedDataTypesManager() = default;
  12. InterestedDataTypesManager::~InterestedDataTypesManager() {
  13. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  14. DCHECK(!interested_data_types_handler_);
  15. }
  16. void InterestedDataTypesManager::SetInterestedDataTypesHandler(
  17. InterestedDataTypesHandler* handler) {
  18. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  19. DCHECK(!interested_data_types_handler_ || !handler);
  20. interested_data_types_handler_ = handler;
  21. }
  22. absl::optional<ModelTypeSet>
  23. InterestedDataTypesManager::GetInterestedDataTypes() const {
  24. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  25. return data_types_;
  26. }
  27. void InterestedDataTypesManager::SetInterestedDataTypes(
  28. const ModelTypeSet& data_types) {
  29. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  30. DCHECK(interested_data_types_handler_);
  31. data_types_ = data_types;
  32. interested_data_types_handler_->OnInterestedDataTypesChanged();
  33. }
  34. void InterestedDataTypesManager::
  35. SetCommittedAdditionalInterestedDataTypesCallback(
  36. SyncInvalidationsService::InterestedDataTypesAppliedCallback callback) {
  37. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  38. DCHECK(interested_data_types_handler_);
  39. // Do not send an additional GetUpdates request when invalidations are
  40. // disabled.
  41. if (base::FeatureList::IsEnabled(kUseSyncInvalidations)) {
  42. interested_data_types_handler_
  43. ->SetCommittedAdditionalInterestedDataTypesCallback(
  44. std::move(callback));
  45. }
  46. }
  47. } // namespace syncer