OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 namespace chromeos { | 11 namespace chromeos { |
12 namespace system { | 12 namespace system { |
13 | 13 |
14 // This interface provides access to Chrome OS statistics. | 14 // This interface provides access to Chrome OS statistics. |
15 class StatisticsProvider { | 15 class StatisticsProvider { |
16 public: | 16 public: |
17 // Retrieve the named machine statistic (e.g. "hardware_class"). | 17 class Observer { |
18 // This does not update the statistcs. If the |name| is not set, |result| | 18 public: |
19 // preserves old value. | 19 virtual ~Observer() {} |
| 20 |
| 21 // Invoked on the UI thread once the statistics have been loaded. |
| 22 // Any calls to GetMachineStatistic() after this callback are guaranteed |
| 23 // not to block. |
| 24 virtual void OnMachineStatisticsReady() = 0; |
| 25 }; |
| 26 |
| 27 // Get the machine statistic with a key of |name| (e.g., "hardware_class"). |
| 28 // Returns true if the key was found, and data was returned in |result|. |
| 29 // Returns false otherwise, and the contents of |result| are undefined. |
| 30 // This call may block for an arbitrary length of time (waiting for statistics |
| 31 // to load, or a timeout to take place). If this function is called anytime |
| 32 // after OnMachineStatisticsReady() has been invoked on an observer, |
| 33 // then this function is guaranteed not to block. |
20 virtual bool GetMachineStatistic(const std::string& name, | 34 virtual bool GetMachineStatistic(const std::string& name, |
21 std::string* result) = 0; | 35 std::string* result) = 0; |
22 | 36 |
| 37 // Invokes OnMachineStatisticsReady() on the |observer| once the machine |
| 38 // statistics are ready. That call can be executed synchronously if the |
| 39 // statistics are already ready. |
| 40 virtual void AddObserver(Observer* observer) = 0; |
| 41 |
| 42 // Removes the given |observer|. Observers must be removed before shutdown. |
| 43 virtual void RemoveObserver(Observer* observer) = 0; |
| 44 |
23 static StatisticsProvider* GetInstance(); | 45 static StatisticsProvider* GetInstance(); |
24 | 46 |
25 protected: | 47 protected: |
26 virtual ~StatisticsProvider() {} | 48 virtual ~StatisticsProvider() {} |
27 }; | 49 }; |
28 | 50 |
29 } // namespace system | 51 } // namespace system |
30 } // namespace chromeos | 52 } // namespace chromeos |
31 | 53 |
32 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ | 54 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ |
OLD | NEW |