-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_platform_features.h
70 lines (51 loc) · 2.21 KB
/
fake_platform_features.h
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
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FEATURED_FAKE_PLATFORM_FEATURES_H_
#define FEATURED_FAKE_PLATFORM_FEATURES_H_
#include <map>
#include <string>
#include <vector>
#include <base/memory/scoped_refptr.h>
#include <base/synchronization/lock.h>
#include <base/task/task_runner.h>
#include <dbus/bus.h>
#include "featured/c_feature_library.h" // for enums
#include "featured/feature_export.h"
#include "featured/feature_library.h"
namespace feature {
// Fake class for testing, which returns a specified value for each feature.
class FEATURE_EXPORT FakePlatformFeatures : public PlatformFeaturesInterface {
public:
explicit FakePlatformFeatures(scoped_refptr<dbus::Bus> bus) : bus_(bus) {}
FakePlatformFeatures(const FakePlatformFeatures&) = delete;
FakePlatformFeatures& operator=(const FakePlatformFeatures&) = delete;
void IsEnabled(const VariationsFeature& feature,
IsEnabledCallback callback) override;
bool IsEnabledBlockingWithTimeout(const VariationsFeature& feature,
int timeout_ms) override;
void GetParamsAndEnabled(
const std::vector<const VariationsFeature*>& features,
GetParamsCallback callback) override;
ParamsResult GetParamsAndEnabledBlocking(
const std::vector<const VariationsFeature*>& features) override;
void SetEnabled(const std::string& feature, bool enabled);
void ClearEnabled(const std::string& feature);
void SetParam(const std::string& feature,
const std::string& key,
const std::string& value);
void ClearParams(const std::string& feature);
void ShutdownBus();
void ListenForRefetchNeeded(
base::RepeatingCallback<void(void)> signal_callback,
base::OnceCallback<void(bool)> attached_callback) override;
void TriggerRefetchSignal();
private:
scoped_refptr<dbus::Bus> bus_;
base::Lock enabled_lock_;
std::map<std::string, bool> enabled_;
std::map<std::string, std::map<std::string, std::string>> params_;
std::vector<base::RepeatingCallback<void(void)>> signal_callbacks_;
};
} // namespace feature
#endif // FEATURED_FAKE_PLATFORM_FEATURES_H_