OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ | |
7 | |
8 #include "chrome/browser/cancelable_request.h" | |
9 #include "testing/gtest/include/gtest/gtest_prod.h" | |
10 | |
11 class FilePath; | |
12 | |
13 // ChromeOSVersionLoader loads the version of Chrome OS from the file system. | |
14 // Loading is done asynchronously on the file thread. Once loaded, | |
15 // ChromeOSVersionLoader callsback to a method of your choice with the version | |
16 // (or an empty string if the version couldn't be found). | |
17 // To use ChromeOSVersionLoader do the following: | |
18 // | |
19 // . In your class define a member field of type ChromeOSVersionLoader and | |
20 // CancelableRequestConsumerBase. | |
21 // . Define the callback method, something like: | |
22 // void OnGetChromeOSVersion(ChromeOSVersionLoader::Handle, | |
23 // std::string version); | |
24 // . When you want the version invoke: loader.GetVersion(&consumer, callback); | |
25 class ChromeOSVersionLoader : public CancelableRequestProvider { | |
26 public: | |
27 ChromeOSVersionLoader(); | |
28 | |
29 // Signature | |
30 typedef Callback2<Handle, std::string>::Type GetVersionCallback; | |
31 | |
32 typedef CancelableRequest<GetVersionCallback> GetVersionRequest; | |
33 | |
34 // Asynchronously requests the version. | |
35 Handle GetVersion(CancelableRequestConsumerBase* consumer, | |
36 GetVersionCallback* callback); | |
37 | |
38 private: | |
39 FRIEND_TEST(ChromeOSVersionLoaderTest, ParseVersion); | |
40 | |
41 // ChromeOSVersionLoader calls into the Backend on the file thread to load | |
42 // and extract the version. | |
43 class Backend : public base::RefCountedThreadSafe<Backend> { | |
44 public: | |
45 Backend() {} | |
46 | |
47 // Calls ParseVersion to get the version # and notifies request. | |
48 // This is invoked on the file thread. | |
49 void GetVersion(scoped_refptr<GetVersionRequest> request); | |
50 | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(Backend); | |
53 }; | |
54 | |
55 // Extracts the version from the file. | |
56 static std::string ParseVersion(const std::string& contents); | |
57 | |
58 scoped_refptr<Backend> backend_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(ChromeOSVersionLoader); | |
61 }; | |
62 | |
63 #endif // CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ | |
OLD | NEW |