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 // Retrieve the named machine statistic (e.g. "hardware_class"). |
18 // This does not update the statistcs. If the |name| is not set, |result| | 20 // This does not update the statistcs. |result| is not updated if |name| is |
19 // preserves old value. | 21 // not set. |
22 // This call may block if the statistics aren't ready yet, up to a timeout; | |
23 // it may also fail because the statistics weren't ready before the timeout. | |
24 // To make sure this won't block nor fail, invoke GetMachineStatistic() after | |
25 // WhenReady() has invoked its callback. | |
20 virtual bool GetMachineStatistic(const std::string& name, | 26 virtual bool GetMachineStatistic(const std::string& name, |
jar (doing other things)
2012/04/24 18:37:40
nit: I had to read the comment a few times to pars
Joao da Silva
2012/04/27 09:47:48
Thanks, that's a much better wording :-)
| |
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. | |
32 virtual void WhenReady(const base::Closure& callback) = 0; | |
jar (doing other things)
2012/04/24 18:37:40
You should probably use a more standard pattern, a
Joao da Silva
2012/04/27 09:47:48
I've been encouraged in other CLs to use callbacks
jar (doing other things)
2012/04/27 18:00:38
I like callbacks better, as you noted, when there
Joao da Silva
2012/05/15 13:52:47
Added an observer as suggested.
| |
33 | |
23 static StatisticsProvider* GetInstance(); | 34 static StatisticsProvider* GetInstance(); |
24 | 35 |
25 protected: | 36 protected: |
26 virtual ~StatisticsProvider() {} | 37 virtual ~StatisticsProvider() {} |
27 }; | 38 }; |
28 | 39 |
29 } // namespace system | 40 } // namespace system |
30 } // namespace chromeos | 41 } // namespace chromeos |
31 | 42 |
32 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ | 43 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ |
OLD | NEW |