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

Side by Side Diff: base/linux_util.cc

Issue 155792: Try again: Add proxy config (using gnome-network-preferences) (Closed)
Patch Set: nits fixed Created 11 years, 5 months 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
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 #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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/string_util.h"
14
15 namespace {
16
17 class EnvironmentVariableGetterImpl
18 : public base::EnvironmentVariableGetter {
19 public:
20 virtual bool Getenv(const char* variable_name, std::string* result) {
21 const char* env_value = ::getenv(variable_name);
22 if (env_value) {
23 // Note that the variable may be defined but empty.
24 *result = env_value;
25 return true;
26 }
27 // Some commonly used variable names are uppercase while others
28 // are lowercase, which is inconsistent. Let's try to be helpful
29 // and look for a variable name with the reverse case.
30 char first_char = variable_name[0];
31 std::string alternate_case_var;
32 if (first_char >= 'a' && first_char <= 'z')
33 alternate_case_var = StringToUpperASCII(std::string(variable_name));
34 else if (first_char >= 'A' && first_char <= 'Z')
35 alternate_case_var = StringToLowerASCII(std::string(variable_name));
36 else
37 return false;
38 env_value = ::getenv(alternate_case_var.c_str());
39 if (env_value) {
40 *result = env_value;
41 return true;
42 }
43 return false;
44 }
45 };
46
47 } // anonymous namespace
13 48
14 namespace base { 49 namespace base {
15 50
16 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { 51 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
17 if (stride == 0) 52 if (stride == 0)
18 stride = width * 4; 53 stride = width * 4;
19 54
20 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); 55 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
21 56
22 // We have to copy the pixels and swap from BGRA to RGBA. 57 // We have to copy the pixels and swap from BGRA to RGBA.
(...skipping 29 matching lines...) Expand all
52 linux_distro = output.substr(field.length()); 87 linux_distro = output.substr(field.length());
53 } 88 }
54 // We do this check only once per process. If it fails, there's 89 // We do this check only once per process. If it fails, there's
55 // little reason to believe it will work if we attempt to run 90 // little reason to believe it will work if we attempt to run
56 // lsb_release again. 91 // lsb_release again.
57 checked_distro = true; 92 checked_distro = true;
58 } 93 }
59 return linux_distro; 94 return linux_distro;
60 } 95 }
61 96
97 // static
98 EnvironmentVariableGetter* EnvironmentVariableGetter::Create() {
99 return new EnvironmentVariableGetterImpl();
100 }
101
102 bool UseGnomeForSettings(EnvironmentVariableGetter* env_var_getter) {
103 // GNOME_DESKTOP_SESSION_ID being defined is a good indication that
104 // we are probably running under GNOME.
105 // Note: KDE_FULL_SESSION is a corresponding env var to recognize KDE.
106 std::string dummy, desktop_session;
107 return env_var_getter->Getenv("GNOME_DESKTOP_SESSION_ID", &dummy)
108 || (env_var_getter->Getenv("DESKTOP_SESSION", &desktop_session)
109 && desktop_session == "gnome");
110 }
111
62 } // namespace base 112 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698