1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
ash / system / video_conference / effects / fake_video_conference_tray_effects_manager.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/video_conference/effects/fake_video_conference_tray_effects_manager.h"
#include <vector>
#include "ash/constants/ash_features.h"
#include "ash/system/video_conference/bubble/vc_tile_ui_controller.h"
#include "ash/system/video_conference/effects/video_conference_tray_effects_delegate.h"
#include "ash/system/video_conference/effects/video_conference_tray_effects_manager.h"
#include "ash/system/video_conference/effects/video_conference_tray_effects_manager_types.h"
namespace ash {
FakeVideoConferenceTrayEffectsManager::FakeVideoConferenceTrayEffectsManager() =
default;
FakeVideoConferenceTrayEffectsManager::
~FakeVideoConferenceTrayEffectsManager() = default;
void FakeVideoConferenceTrayEffectsManager::SetDlcIdsForEffectId(
VcEffectId effect_id,
std::vector<std::string> dlc_ids) {
dlc_ids_for_effect_id_[effect_id] = std::move(dlc_ids);
}
video_conference::VcTileUiController*
FakeVideoConferenceTrayEffectsManager::GetUiControllerForEffectId(
VcEffectId effect_id) {
CHECK(features::IsVcDlcUiEnabled());
auto toggle_effects = GetToggleEffects();
if (toggle_effects_index_ >= toggle_effects.size()) {
// If we're out of bounds try starting from the beginning again.
toggle_effects_index_ = 0;
}
// Re-use an existing tile UI controller if we have one.
if (toggle_effects_index_ < tile_ui_controllers_.size()) {
return tile_ui_controllers_[toggle_effects_index_].get();
}
// Otherwise create a new tile UI controller and return that.
auto* effect = toggle_effects[toggle_effects_index_++];
tile_ui_controllers_.push_back(
std::make_unique<video_conference::VcTileUiController>(effect));
return tile_ui_controllers_.back().get();
}
std::vector<std::string>
FakeVideoConferenceTrayEffectsManager::GetDlcIdsForEffectId(
VcEffectId effect_id) {
if (base::Contains(dlc_ids_for_effect_id_, effect_id)) {
return dlc_ids_for_effect_id_[effect_id];
}
return VideoConferenceTrayEffectsManager::GetDlcIdsForEffectId(effect_id);
}
void FakeVideoConferenceTrayEffectsManager::UnregisterDelegate(
VcEffectsDelegate* delegate) {
VideoConferenceTrayEffectsManager::UnregisterDelegate(delegate);
// Delete any tile UI controllers associated with any of `delegate`'s effects.
for (auto* effect : delegate->GetAllEffects(VcEffectType::kToggle)) {
const VcEffectId id = effect->id();
std::erase_if(
tile_ui_controllers_,
[&, id](const std::unique_ptr<video_conference::VcTileUiController>&
controller) {
return controller->effect_id_for_testing() == id;
});
}
}
} // namespace ash