| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 return false; | 39 return false; |
| 40 env_value = ::getenv(alternate_case_var.c_str()); | 40 env_value = ::getenv(alternate_case_var.c_str()); |
| 41 if (env_value) { | 41 if (env_value) { |
| 42 *result = env_value; | 42 *result = env_value; |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // Not needed for OS_CHROMEOS. |
| 50 #if defined(OS_LINUX) |
| 49 enum LinuxDistroState { | 51 enum LinuxDistroState { |
| 50 STATE_DID_NOT_CHECK = 0, | 52 STATE_DID_NOT_CHECK = 0, |
| 51 STATE_CHECK_STARTED = 1, | 53 STATE_CHECK_STARTED = 1, |
| 52 STATE_CHECK_FINISHED = 2, | 54 STATE_CHECK_FINISHED = 2, |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 // Helper class for GetLinuxDistro(). | 57 // Helper class for GetLinuxDistro(). |
| 56 class LinuxDistroHelper { | 58 class LinuxDistroHelper { |
| 57 public: | 59 public: |
| 58 // Retrieves the Singleton. | 60 // Retrieves the Singleton. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 81 void CheckFinished() { | 83 void CheckFinished() { |
| 82 AutoLock scoped_lock(lock_); | 84 AutoLock scoped_lock(lock_); |
| 83 DCHECK(state_ == STATE_CHECK_STARTED); | 85 DCHECK(state_ == STATE_CHECK_STARTED); |
| 84 state_ = STATE_CHECK_FINISHED; | 86 state_ = STATE_CHECK_FINISHED; |
| 85 } | 87 } |
| 86 | 88 |
| 87 private: | 89 private: |
| 88 Lock lock_; | 90 Lock lock_; |
| 89 LinuxDistroState state_; | 91 LinuxDistroState state_; |
| 90 }; | 92 }; |
| 93 #endif // if defined(OS_LINUX) |
| 91 | 94 |
| 92 } // anonymous namespace | 95 } // anonymous namespace |
| 93 | 96 |
| 94 namespace base { | 97 namespace base { |
| 95 | 98 |
| 96 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { | 99 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { |
| 97 if (stride == 0) | 100 if (stride == 0) |
| 98 stride = width * 4; | 101 stride = width * 4; |
| 99 | 102 |
| 100 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); | 103 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); |
| 101 | 104 |
| 102 // We have to copy the pixels and swap from BGRA to RGBA. | 105 // We have to copy the pixels and swap from BGRA to RGBA. |
| 103 for (int i = 0; i < height; ++i) { | 106 for (int i = 0; i < height; ++i) { |
| 104 for (int j = 0; j < width; ++j) { | 107 for (int j = 0; j < width; ++j) { |
| 105 int idx = i * stride + j * 4; | 108 int idx = i * stride + j * 4; |
| 106 new_pixels[idx] = pixels[idx + 2]; | 109 new_pixels[idx] = pixels[idx + 2]; |
| 107 new_pixels[idx + 1] = pixels[idx + 1]; | 110 new_pixels[idx + 1] = pixels[idx + 1]; |
| 108 new_pixels[idx + 2] = pixels[idx]; | 111 new_pixels[idx + 2] = pixels[idx]; |
| 109 new_pixels[idx + 3] = pixels[idx + 3]; | 112 new_pixels[idx + 3] = pixels[idx + 3]; |
| 110 } | 113 } |
| 111 } | 114 } |
| 112 | 115 |
| 113 return new_pixels; | 116 return new_pixels; |
| 114 } | 117 } |
| 115 | 118 |
| 116 // We use this static string to hold the Linux distro info. If we | 119 // We use this static string to hold the Linux distro info. If we |
| 117 // crash, the crash handler code will send this in the crash dump. | 120 // crash, the crash handler code will send this in the crash dump. |
| 118 std::string linux_distro = "Unknown"; | 121 std::string linux_distro = |
| 122 #if defined(OS_CHROMEOS) |
| 123 "CrOS"; |
| 124 #else // if defined(OS_LINUX) |
| 125 "Unknown"; |
| 126 #endif |
| 119 | 127 |
| 120 std::string GetLinuxDistro() { | 128 std::string GetLinuxDistro() { |
| 129 #if defined(OS_CHROMEOS) |
| 130 return linux_distro; |
| 131 #else // if defined(OS_LINUX) |
| 121 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::Get(); | 132 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::Get(); |
| 122 LinuxDistroState state = distro_state_singleton->State(); | 133 LinuxDistroState state = distro_state_singleton->State(); |
| 123 if (STATE_DID_NOT_CHECK == state) { | 134 if (STATE_DID_NOT_CHECK == state) { |
| 124 #if defined(OS_CHROMEOS) | |
| 125 linux_distro = "CrOS"; | |
| 126 #else // if defined(OS_LINUX) | |
| 127 // We do this check only once per process. If it fails, there's | 135 // We do this check only once per process. If it fails, there's |
| 128 // little reason to believe it will work if we attempt to run | 136 // little reason to believe it will work if we attempt to run |
| 129 // lsb_release again. | 137 // lsb_release again. |
| 130 std::vector<std::string> argv; | 138 std::vector<std::string> argv; |
| 131 argv.push_back("lsb_release"); | 139 argv.push_back("lsb_release"); |
| 132 argv.push_back("-d"); | 140 argv.push_back("-d"); |
| 133 std::string output; | 141 std::string output; |
| 134 base::GetAppOutput(CommandLine(argv), &output); | 142 base::GetAppOutput(CommandLine(argv), &output); |
| 135 if (output.length() > 0) { | 143 if (output.length() > 0) { |
| 136 // lsb_release -d should return: Description:<tab>Distro Info | 144 // lsb_release -d should return: Description:<tab>Distro Info |
| 137 static const std::string field = "Description:\t"; | 145 static const std::string field = "Description:\t"; |
| 138 if (output.compare(0, field.length(), field) == 0) | 146 if (output.compare(0, field.length(), field) == 0) |
| 139 linux_distro = output.substr(field.length()); | 147 linux_distro = output.substr(field.length()); |
| 140 } | 148 } |
| 141 #endif | |
| 142 distro_state_singleton->CheckFinished(); | 149 distro_state_singleton->CheckFinished(); |
| 143 return linux_distro; | 150 return linux_distro; |
| 144 } else if (STATE_CHECK_STARTED == state) { | 151 } else if (STATE_CHECK_STARTED == state) { |
| 145 // If the distro check above is in progress in some other thread, we're | 152 // If the distro check above is in progress in some other thread, we're |
| 146 // not going to wait for the results. | 153 // not going to wait for the results. |
| 147 return "Unknown"; | 154 return "Unknown"; |
| 148 } else { | 155 } else { |
| 149 // In STATE_CHECK_FINISHED, no more writing to |linux_distro|. | 156 // In STATE_CHECK_FINISHED, no more writing to |linux_distro|. |
| 150 return linux_distro; | 157 return linux_distro; |
| 151 } | 158 } |
| 159 #endif |
| 152 } | 160 } |
| 153 | 161 |
| 154 // static | 162 // static |
| 155 EnvironmentVariableGetter* EnvironmentVariableGetter::Create() { | 163 EnvironmentVariableGetter* EnvironmentVariableGetter::Create() { |
| 156 return new EnvironmentVariableGetterImpl(); | 164 return new EnvironmentVariableGetterImpl(); |
| 157 } | 165 } |
| 158 | 166 |
| 159 DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env) { | 167 DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env) { |
| 160 std::string desktop_session; | 168 std::string desktop_session; |
| 161 if (env->Getenv("DESKTOP_SESSION", &desktop_session)) { | 169 if (env->Getenv("DESKTOP_SESSION", &desktop_session)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return "KDE4"; | 201 return "KDE4"; |
| 194 } | 202 } |
| 195 return NULL; | 203 return NULL; |
| 196 } | 204 } |
| 197 | 205 |
| 198 const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env) { | 206 const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env) { |
| 199 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); | 207 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); |
| 200 } | 208 } |
| 201 | 209 |
| 202 } // namespace base | 210 } // namespace base |
| OLD | NEW |