forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfake_statistics_provider.cc
82 lines (62 loc) · 2.52 KB
/
fake_statistics_provider.cc
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
77
78
79
80
81
82
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/system/fake_statistics_provider.h"
#include <utility>
#include "base/threading/sequenced_task_runner_handle.h"
namespace chromeos {
namespace system {
FakeStatisticsProvider::FakeStatisticsProvider() = default;
FakeStatisticsProvider::~FakeStatisticsProvider() = default;
void FakeStatisticsProvider::StartLoadingMachineStatistics(
bool load_oem_manifest) {
}
void FakeStatisticsProvider::ScheduleOnMachineStatisticsLoaded(
base::OnceClosure callback) {
// No load is required for FakeStatisticsProvider.
base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
std::move(callback));
}
bool FakeStatisticsProvider::GetMachineStatistic(const std::string& name,
std::string* result) {
std::map<std::string, std::string>::const_iterator match =
machine_statistics_.find(name);
if (match != machine_statistics_.end() && result)
*result = match->second;
return match != machine_statistics_.end();
}
bool FakeStatisticsProvider::GetMachineFlag(const std::string& name,
bool* result) {
std::map<std::string, bool>::const_iterator match = machine_flags_.find(name);
if (match != machine_flags_.end() && result)
*result = match->second;
return match != machine_flags_.end();
}
void FakeStatisticsProvider::Shutdown() {
}
bool FakeStatisticsProvider::IsRunningOnVm() {
std::string is_vm;
return GetMachineStatistic(kIsVmKey, &is_vm) && is_vm == kIsVmValueTrue;
}
void FakeStatisticsProvider::SetMachineStatistic(const std::string& key,
const std::string& value) {
machine_statistics_[key] = value;
}
void FakeStatisticsProvider::ClearMachineStatistic(const std::string& key) {
machine_statistics_.erase(key);
}
void FakeStatisticsProvider::SetMachineFlag(const std::string& key,
bool value) {
machine_flags_[key] = value;
}
void FakeStatisticsProvider::ClearMachineFlag(const std::string& key) {
machine_flags_.erase(key);
}
ScopedFakeStatisticsProvider::ScopedFakeStatisticsProvider() {
StatisticsProvider::SetTestProvider(this);
}
ScopedFakeStatisticsProvider::~ScopedFakeStatisticsProvider() {
StatisticsProvider::SetTestProvider(NULL);
}
} // namespace system
} // namespace chromeos