OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/linux_util.h" | 5 #include "base/linux_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <glib.h> | 10 #include <glib.h> |
(...skipping 20 matching lines...) Expand all Loading... |
31 enum LinuxDistroState { | 31 enum LinuxDistroState { |
32 STATE_DID_NOT_CHECK = 0, | 32 STATE_DID_NOT_CHECK = 0, |
33 STATE_CHECK_STARTED = 1, | 33 STATE_CHECK_STARTED = 1, |
34 STATE_CHECK_FINISHED = 2, | 34 STATE_CHECK_FINISHED = 2, |
35 }; | 35 }; |
36 | 36 |
37 // Helper class for GetLinuxDistro(). | 37 // Helper class for GetLinuxDistro(). |
38 class LinuxDistroHelper { | 38 class LinuxDistroHelper { |
39 public: | 39 public: |
40 // Retrieves the Singleton. | 40 // Retrieves the Singleton. |
41 static LinuxDistroHelper* Get() { | 41 static LinuxDistroHelper* GetInstance() { |
42 return Singleton<LinuxDistroHelper>::get(); | 42 return Singleton<LinuxDistroHelper>::get(); |
43 } | 43 } |
44 | 44 |
45 // The simple state machine goes from: | 45 // The simple state machine goes from: |
46 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. | 46 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. |
47 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} | 47 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} |
48 ~LinuxDistroHelper() {} | 48 ~LinuxDistroHelper() {} |
49 | 49 |
50 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, | 50 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, |
51 // we automatically move to STATE_CHECK_STARTED so nobody else will | 51 // we automatically move to STATE_CHECK_STARTED so nobody else will |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 #if defined(OS_CHROMEOS) | 134 #if defined(OS_CHROMEOS) |
135 "CrOS"; | 135 "CrOS"; |
136 #else // if defined(OS_LINUX) | 136 #else // if defined(OS_LINUX) |
137 "Unknown"; | 137 "Unknown"; |
138 #endif | 138 #endif |
139 | 139 |
140 std::string GetLinuxDistro() { | 140 std::string GetLinuxDistro() { |
141 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
142 return g_linux_distro; | 142 return g_linux_distro; |
143 #elif defined(OS_LINUX) | 143 #elif defined(OS_LINUX) |
144 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::Get(); | 144 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::GetInstance(); |
145 LinuxDistroState state = distro_state_singleton->State(); | 145 LinuxDistroState state = distro_state_singleton->State(); |
146 if (STATE_DID_NOT_CHECK == state) { | 146 if (STATE_DID_NOT_CHECK == state) { |
147 // We do this check only once per process. If it fails, there's | 147 // We do this check only once per process. If it fails, there's |
148 // little reason to believe it will work if we attempt to run | 148 // little reason to believe it will work if we attempt to run |
149 // lsb_release again. | 149 // lsb_release again. |
150 std::vector<std::string> argv; | 150 std::vector<std::string> argv; |
151 argv.push_back("lsb_release"); | 151 argv.push_back("lsb_release"); |
152 argv.push_back("-d"); | 152 argv.push_back("-d"); |
153 std::string output; | 153 std::string output; |
154 base::GetAppOutput(CommandLine(argv), &output); | 154 base::GetAppOutput(CommandLine(argv), &output); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 288 |
289 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), | 289 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), |
290 expected_data.length())) { | 290 expected_data.length())) { |
291 return current_tid; | 291 return current_tid; |
292 } | 292 } |
293 } | 293 } |
294 return -1; | 294 return -1; |
295 } | 295 } |
296 | 296 |
297 } // namespace base | 297 } // namespace base |
OLD | NEW |