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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/task/cancelable_task_tracker.h"
16 // ChromeOSVersionLoader loads the version of Chrome OS from the file system.
17 // Loading is done asynchronously in the blocking thread pool. Once loaded,
18 // ChromeOSVersionLoader callback to a method of your choice with the version
19 // (or an empty string if the version couldn't be found).
20 // To use ChromeOSVersionLoader do the following:
22 // . In your class define a member field of type chromeos::VersionLoader and
23 // base::CancelableTaskTracker.
24 // . Define the callback method, something like:
25 // void OnGetChromeOSVersion(const std::string& version);
26 // . When you want the version invoke:
27 // VersionLoader::GetVersion()
29 // This class also provides the ability to load the bios firmware using
30 // VersionLoader::GetFirmware()
34 virtual ~VersionLoader();
38 VERSION_SHORT_WITH_DATE
,
43 typedef base::Callback
<void(const std::string
&)> GetVersionCallback
;
44 typedef base::Callback
<void(const std::string
&)> GetFirmwareCallback
;
46 // Asynchronously requests the version.
47 // If |full_version| is true version string with extra info is extracted,
48 // otherwise it's in short format x.x.xx.x.
49 base::CancelableTaskTracker::TaskId
GetVersion(
51 const GetVersionCallback
& callback
,
52 base::CancelableTaskTracker
* tracker
);
54 base::CancelableTaskTracker::TaskId
GetFirmware(
55 const GetFirmwareCallback
& callback
,
56 base::CancelableTaskTracker
* tracker
);
59 FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest
, ParseFirmware
);
61 // VersionLoader calls into the Backend in the blocking thread pool to load
62 // and extract the version.
63 class Backend
: public base::RefCountedThreadSafe
<Backend
> {
67 // Gets the version number from base::SysInfo. This is invoked on the
68 // blocking thread pool.
69 void GetVersion(VersionFormat format
, std::string
* version
);
71 // Calls ParseFirmware to get the firmware value. This is invoked on the
72 // blocking thread pool.
73 void GetFirmware(std::string
* firmware
);
76 friend class base::RefCountedThreadSafe
<Backend
>;
80 DISALLOW_COPY_AND_ASSIGN(Backend
);
83 // Extracts the firmware from the file.
84 static std::string
ParseFirmware(const std::string
& contents
);
86 scoped_refptr
<Backend
> backend_
;
88 DISALLOW_COPY_AND_ASSIGN(VersionLoader
);
91 } // namespace chromeos
93 #endif // CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_