Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: base/linux_util.h

Issue 449048: Move some XDG code from chrome to base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix linux base_unittest Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base_paths_posix.cc ('k') | base/linux_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_LINUX_UTIL_H__ 5 #ifndef BASE_LINUX_UTIL_H__
6 #define BASE_LINUX_UTIL_H__ 6 #define BASE_LINUX_UTIL_H__
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
11 #include <string> 11 #include <string>
12 12
13 class FilePath;
14
13 namespace base { 15 namespace base {
14 16
15 static const char kFindInodeSwitch[] = "--find-inode"; 17 static const char kFindInodeSwitch[] = "--find-inode";
16 18
17 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. 19 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
18 // The caller is responsible for free()ing the data. If |stride| is 0, 20 // The caller is responsible for free()ing the data. If |stride| is 0,
19 // it's assumed to be 4 * |width|. 21 // it's assumed to be 4 * |width|.
20 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); 22 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride);
21 23
22 // Get the Linux Distro if we can, or return "Unknown", similar to 24 // Get the Linux Distro if we can, or return "Unknown", similar to
23 // GetWinVersion() in base/win_util.h. 25 // GetWinVersion() in base/win_util.h.
24 std::string GetLinuxDistro(); 26 std::string GetLinuxDistro();
25 27
26 // These are used to derive mocks for unittests. 28 // These are used to derive mocks for unittests.
27 class EnvironmentVariableGetter { 29 class EnvironmentVariableGetter {
28 public: 30 public:
29 virtual ~EnvironmentVariableGetter() {} 31 virtual ~EnvironmentVariableGetter() {}
30 // Gets an environment variable's value and stores it in 32 // Gets an environment variable's value and stores it in
31 // result. Returns false if the key is unset. 33 // result. Returns false if the key is unset.
32 virtual bool Getenv(const char* variable_name, std::string* result) = 0; 34 virtual bool Getenv(const char* variable_name, std::string* result) = 0;
33 35
34 // Create an instance of EnvironmentVariableGetter 36 // Create an instance of EnvironmentVariableGetter
35 static EnvironmentVariableGetter* Create(); 37 static EnvironmentVariableGetter* Create();
36 }; 38 };
37 39
40 // Get the home directory.
41 FilePath GetHomeDir(EnvironmentVariableGetter* env);
42
43 // Utility function for getting XDG directories.
44 // |env_name| is the name of an environment variable that we want to use to get
45 // a directory path. |fallback_dir| is the directory relative to $HOME that we
46 // use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL.
47 // Examples of |env_name| are XDG_CONFIG_HOME and XDG_DATA_HOME.
48 FilePath GetXDGDirectory(EnvironmentVariableGetter* env,
49 const char* env_name, const char* fallback_dir);
50
51 // Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs
52 // This looks up "well known" user directories like the desktop and music
53 // folder. Examples of |dir_name| are DESKTOP and MUSIC.
54 FilePath GetXDGUserDirectory(EnvironmentVariableGetter* env,
55 const char* dir_name, const char* fallback_dir);
56
38 enum DesktopEnvironment { 57 enum DesktopEnvironment {
39 DESKTOP_ENVIRONMENT_OTHER, 58 DESKTOP_ENVIRONMENT_OTHER,
40 DESKTOP_ENVIRONMENT_GNOME, 59 DESKTOP_ENVIRONMENT_GNOME,
41 // KDE3 and KDE4 are sufficiently different that we count 60 // KDE3 and KDE4 are sufficiently different that we count
42 // them as two different desktop environments here. 61 // them as two different desktop environments here.
43 DESKTOP_ENVIRONMENT_KDE3, 62 DESKTOP_ENVIRONMENT_KDE3,
44 DESKTOP_ENVIRONMENT_KDE4, 63 DESKTOP_ENVIRONMENT_KDE4,
45 }; 64 };
46 65
47 // Return an entry from the DesktopEnvironment enum with a best guess 66 // Return an entry from the DesktopEnvironment enum with a best guess
(...skipping 11 matching lines...) Expand all
59 // Return the inode number for the UNIX domain socket |fd|. 78 // Return the inode number for the UNIX domain socket |fd|.
60 bool FileDescriptorGetInode(ino_t* inode_out, int fd); 79 bool FileDescriptorGetInode(ino_t* inode_out, int fd);
61 80
62 // Find the process which holds the given socket, named by inode number. If 81 // Find the process which holds the given socket, named by inode number. If
63 // multiple processes hold the socket, this function returns false. 82 // multiple processes hold the socket, this function returns false.
64 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode); 83 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode);
65 84
66 } // namespace base 85 } // namespace base
67 86
68 #endif // BASE_LINUX_UTIL_H__ 87 #endif // BASE_LINUX_UTIL_H__
OLDNEW
« no previous file with comments | « base/base_paths_posix.cc ('k') | base/linux_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698