sgk@google.com | e1f4a24 | 2009-04-22 02:20:10 +0900 | [diff] [blame] | 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 BASE_LINUX_UTIL_H__ |
| 6 | #define BASE_LINUX_UTIL_H__ |
| 7 | |
| 8 | #include <stdint.h> |
craig.schlenter@chromium.org | fd4599a | 2009-10-30 03:21:30 +0900 | [diff] [blame^] | 9 | #include <sys/types.h> |
sgk@google.com | e1f4a24 | 2009-04-22 02:20:10 +0900 | [diff] [blame] | 10 | |
thestig@chromium.org | a5a2b6e | 2009-07-17 14:55:51 +0900 | [diff] [blame] | 11 | #include <string> |
| 12 | |
sgk@google.com | e1f4a24 | 2009-04-22 02:20:10 +0900 | [diff] [blame] | 13 | namespace base { |
| 14 | |
| 15 | // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. |
| 16 | // The caller is responsible for free()ing the data. If |stride| is 0, |
| 17 | // it's assumed to be 4 * |width|. |
| 18 | uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); |
| 19 | |
thestig@chromium.org | a5a2b6e | 2009-07-17 14:55:51 +0900 | [diff] [blame] | 20 | // Get the Linux Distro if we can, or return "Unknown", similar to |
| 21 | // GetWinVersion() in base/win_util.h. |
| 22 | std::string GetLinuxDistro(); |
| 23 | |
mattm@chromium.org | 625865e | 2009-07-22 09:22:49 +0900 | [diff] [blame] | 24 | // These are used to derive mocks for unittests. |
| 25 | class EnvironmentVariableGetter { |
| 26 | public: |
| 27 | virtual ~EnvironmentVariableGetter() {} |
| 28 | // Gets an environment variable's value and stores it in |
| 29 | // result. Returns false if the key is unset. |
| 30 | virtual bool Getenv(const char* variable_name, std::string* result) = 0; |
| 31 | |
| 32 | // Create an instance of EnvironmentVariableGetter |
| 33 | static EnvironmentVariableGetter* Create(); |
| 34 | }; |
| 35 | |
evan@chromium.org | 01e3d87 | 2009-07-24 07:10:53 +0900 | [diff] [blame] | 36 | enum DesktopEnvironment { |
| 37 | DESKTOP_ENVIRONMENT_OTHER, |
| 38 | DESKTOP_ENVIRONMENT_GNOME, |
mdm@chromium.org | 6a0e499 | 2009-08-21 08:14:57 +0900 | [diff] [blame] | 39 | // KDE3 and KDE4 are sufficiently different that we count |
| 40 | // them as two different desktop environments here. |
| 41 | DESKTOP_ENVIRONMENT_KDE3, |
| 42 | DESKTOP_ENVIRONMENT_KDE4, |
evan@chromium.org | 01e3d87 | 2009-07-24 07:10:53 +0900 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | // Return an entry from the DesktopEnvironment enum with a best guess |
| 46 | // of which desktop environment we're using. We use this to know when |
| 47 | // to attempt to use preferences from the desktop environment -- |
| 48 | // proxy settings, password manager, etc. |
| 49 | DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env); |
mattm@chromium.org | 625865e | 2009-07-22 09:22:49 +0900 | [diff] [blame] | 50 | |
mdm@chromium.org | 6a0e499 | 2009-08-21 08:14:57 +0900 | [diff] [blame] | 51 | // Return a string representation of the given desktop environment. |
| 52 | // May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER. |
| 53 | const char* GetDesktopEnvironmentName(DesktopEnvironment env); |
| 54 | // Convenience wrapper that calls GetDesktopEnvironment() first. |
| 55 | const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env); |
| 56 | |
thestig@chromium.org | 2feb1c8 | 2009-10-29 13:02:55 +0900 | [diff] [blame] | 57 | // Return the inode number for the UNIX domain socket |fd|. |
| 58 | bool FileDescriptorGetInode(ino_t* inode_out, int fd); |
| 59 | |
| 60 | // Find the process which holds the given socket, named by inode number. If |
| 61 | // multiple processes hold the socket, this function returns false. |
| 62 | bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode); |
| 63 | |
sgk@google.com | e1f4a24 | 2009-04-22 02:20:10 +0900 | [diff] [blame] | 64 | } // namespace base |
| 65 | |
| 66 | #endif // BASE_LINUX_UTIL_H__ |