summaryrefslogtreecommitdiffstats
path: root/chromeos/system/fake_statistics_provider.h
blob: 7ea8ec2399630b120e33d671fd36d0e3453d45df (plain)
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
// 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.

#ifndef CHROMEOS_SYSTEM_FAKE_STATISTICS_PROVIDER_H_
#define CHROMEOS_SYSTEM_FAKE_STATISTICS_PROVIDER_H_

#include <map>
#include <string>

#include "chromeos/system/statistics_provider.h"

namespace chromeos {
namespace system {

// A fake StatisticsProvider implementation that is useful in tests.
class FakeStatisticsProvider : public StatisticsProvider {
 public:
  FakeStatisticsProvider();
  ~FakeStatisticsProvider() override;

  // StatisticsProvider implementation:
  void StartLoadingMachineStatistics(
      const scoped_refptr<base::TaskRunner>& file_task_runner,
      bool load_oem_manifest) override;
  bool GetMachineStatistic(const std::string& name,
                           std::string* result) override;
  bool HasMachineStatistic(const std::string& name) override;
  bool GetMachineFlag(const std::string& name, bool* result) override;
  bool HasMachineFlag(const std::string& name) override;
  void Shutdown() override;

  void SetMachineStatistic(const std::string& key, const std::string& value);
  void ClearMachineStatistic(const std::string& key);
  void SetMachineFlag(const std::string& key, bool value);
  void ClearMachineFlag(const std::string& key);

 private:
  std::map<std::string, std::string> machine_statistics_;
  std::map<std::string, bool> machine_flags_;

  DISALLOW_COPY_AND_ASSIGN(FakeStatisticsProvider);
};

// A convenience subclass that automatically registers itself as the test
// StatisticsProvider during construction and cleans up at destruction.
class ScopedFakeStatisticsProvider : public FakeStatisticsProvider {
 public:
  ScopedFakeStatisticsProvider();
  ~ScopedFakeStatisticsProvider() override;

 private:
  DISALLOW_COPY_AND_ASSIGN(ScopedFakeStatisticsProvider);
};

}  // namespace system
}  // namespace chromeos

#endif  // CHROMEOS_SYSTEM_FAKE_STATISTICS_PROVIDER_H_