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_VERSION_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Asynchronously requests the version. | 46 // Asynchronously requests the version. |
47 // If |full_version| is true version string with extra info is extracted, | 47 // If |full_version| is true version string with extra info is extracted, |
48 // otherwise it's in short format x.x.xx.x. | 48 // otherwise it's in short format x.x.xx.x. |
49 CancelableTaskTracker::TaskId GetVersion(VersionFormat format, | 49 CancelableTaskTracker::TaskId GetVersion(VersionFormat format, |
50 const GetVersionCallback& callback, | 50 const GetVersionCallback& callback, |
51 CancelableTaskTracker* tracker); | 51 CancelableTaskTracker* tracker); |
52 | 52 |
53 CancelableTaskTracker::TaskId GetFirmware(const GetFirmwareCallback& callback, | 53 CancelableTaskTracker::TaskId GetFirmware(const GetFirmwareCallback& callback, |
54 CancelableTaskTracker* tracker); | 54 CancelableTaskTracker* tracker); |
55 | 55 |
56 static const char kFullVersionPrefix[]; | |
57 static const char kVersionPrefix[]; | |
58 static const char kFirmwarePrefix[]; | |
59 | |
60 private: | 56 private: |
61 FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseFullVersion); | |
62 FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseVersion); | |
63 FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseFirmware); | 57 FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseFirmware); |
64 | 58 |
65 // VersionLoader calls into the Backend in the blocking thread pool to load | 59 // VersionLoader calls into the Backend in the blocking thread pool to load |
66 // and extract the version. | 60 // and extract the version. |
67 class Backend : public base::RefCountedThreadSafe<Backend> { | 61 class Backend : public base::RefCountedThreadSafe<Backend> { |
68 public: | 62 public: |
69 Backend() {} | 63 Backend() {} |
70 | 64 |
71 // Calls ParseVersion to get the version # and notifies request. | 65 // Gets the version number from base::SysInfo. This is invoked on the |
72 // This is invoked in the blocking thread pool. | 66 // blocking thread pool. |
73 // If |full_version| is true then extra info is passed in version string. | |
74 void GetVersion(VersionFormat format, std::string* version); | 67 void GetVersion(VersionFormat format, std::string* version); |
75 | 68 |
76 // Calls ParseFirmware to get the firmware # and notifies request. | 69 // Calls ParseFirmware to get the firmware value. This is invoked on the |
77 // This is invoked in the blocking thread pool. | 70 // blocking thread pool. |
78 void GetFirmware(std::string* firmware); | 71 void GetFirmware(std::string* firmware); |
79 | 72 |
80 private: | 73 private: |
81 friend class base::RefCountedThreadSafe<Backend>; | 74 friend class base::RefCountedThreadSafe<Backend>; |
82 | 75 |
83 ~Backend() {} | 76 ~Backend() {} |
84 | 77 |
85 DISALLOW_COPY_AND_ASSIGN(Backend); | 78 DISALLOW_COPY_AND_ASSIGN(Backend); |
86 }; | 79 }; |
87 | 80 |
88 // Extracts the version from the file. | |
89 // |prefix| specifies what key defines version data. | |
90 static std::string ParseVersion(const std::string& contents, | |
91 const std::string& prefix); | |
92 | |
93 // Extracts the firmware from the file. | 81 // Extracts the firmware from the file. |
94 static std::string ParseFirmware(const std::string& contents); | 82 static std::string ParseFirmware(const std::string& contents); |
95 | 83 |
96 scoped_refptr<Backend> backend_; | 84 scoped_refptr<Backend> backend_; |
97 | 85 |
98 DISALLOW_COPY_AND_ASSIGN(VersionLoader); | 86 DISALLOW_COPY_AND_ASSIGN(VersionLoader); |
99 }; | 87 }; |
100 | 88 |
101 } // namespace chromeos | 89 } // namespace chromeos |
102 | 90 |
103 #endif // CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_ | 91 #endif // CHROME_BROWSER_CHROMEOS_VERSION_LOADER_H_ |
OLD | NEW |