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 #include "base/callback.h" |
| 12 |
11 namespace chromeos { | 13 namespace chromeos { |
12 namespace system { | 14 namespace system { |
13 | 15 |
14 // This interface provides access to Chrome OS statistics. | 16 // This interface provides access to Chrome OS statistics. |
15 class StatisticsProvider { | 17 class StatisticsProvider { |
16 public: | 18 public: |
17 // Retrieve the named machine statistic (e.g. "hardware_class"). | 19 // Get the machine statistic with a key of |name| (e.g., "hardware_class"). |
18 // This does not update the statistcs. If the |name| is not set, |result| | 20 // Returns true if the key was found, and data was returned in |result|. |
19 // preserves old value. | 21 // Returns false otherwise, and the contents of |result| are undefined. |
| 22 // This call may block for an arbitrary length of time (waiting for statistics |
| 23 // to load, or a timeout to take place). If this function is called anytime |
| 24 // after WhenReady() has invoked any callback, then this function is |
| 25 // guaranteed not to block. |
20 virtual bool GetMachineStatistic(const std::string& name, | 26 virtual bool GetMachineStatistic(const std::string& name, |
21 std::string* result) = 0; | 27 std::string* result) = 0; |
22 | 28 |
| 29 // Invokes |callback| on the UI loop once the statistics have been loaded. |
| 30 // |callback| is immediately posted to the UI loop if the statistics are |
| 31 // already available. All the statistics are available once |callback| is |
| 32 // invoked, and GetMachineStatistic() can be invoked as many times as |
| 33 // desired without blocking. |
| 34 virtual void WhenReady(const base::Closure& callback) = 0; |
| 35 |
23 static StatisticsProvider* GetInstance(); | 36 static StatisticsProvider* GetInstance(); |
24 | 37 |
25 protected: | 38 protected: |
26 virtual ~StatisticsProvider() {} | 39 virtual ~StatisticsProvider() {} |
27 }; | 40 }; |
28 | 41 |
29 } // namespace system | 42 } // namespace system |
30 } // namespace chromeos | 43 } // namespace chromeos |
31 | 44 |
32 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ | 45 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ |
OLD | NEW |