synthetic_trials_active_group_id_provider.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2017 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/variations/synthetic_trials_active_group_id_provider.h"
  5. #include "base/memory/singleton.h"
  6. #include "components/variations/variations_associated_data.h"
  7. #include "components/variations/variations_crash_keys.h"
  8. namespace variations {
  9. SyntheticTrialsActiveGroupIdProvider*
  10. SyntheticTrialsActiveGroupIdProvider::GetInstance() {
  11. return base::Singleton<SyntheticTrialsActiveGroupIdProvider>::get();
  12. }
  13. SyntheticTrialsActiveGroupIdProvider::SyntheticTrialsActiveGroupIdProvider() {}
  14. SyntheticTrialsActiveGroupIdProvider::~SyntheticTrialsActiveGroupIdProvider() {}
  15. void SyntheticTrialsActiveGroupIdProvider::GetActiveGroupIds(
  16. std::vector<ActiveGroupId>* output) {
  17. base::AutoLock scoped_lock(lock_);
  18. for (const auto& group_id : synthetic_trials_)
  19. output->push_back(group_id);
  20. }
  21. void SyntheticTrialsActiveGroupIdProvider::ResetForTesting() {
  22. base::AutoLock scoped_lock(lock_);
  23. synthetic_trials_.clear();
  24. }
  25. void SyntheticTrialsActiveGroupIdProvider::OnSyntheticTrialsChanged(
  26. const std::vector<SyntheticTrialGroup>& groups) {
  27. {
  28. base::AutoLock scoped_lock(lock_);
  29. synthetic_trials_.clear();
  30. for (const auto& group : groups)
  31. synthetic_trials_.push_back(group.id());
  32. }
  33. // Update the experiments list for crash reports.
  34. UpdateCrashKeysWithSyntheticTrials(groups);
  35. }
  36. } // namespace variations