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

Side by Side Diff: base/environment.cc

Issue 10004001: Add virtual and OVERRIDE to base/ implementation files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win Fix -> Missing header Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/file_descriptor_shuffle_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/environment.h" 5 #include "base/environment.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #elif defined(OS_WIN) 9 #elif defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #endif 11 #endif
12 12
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #endif 18 #endif
19 19
20 namespace { 20 namespace {
21 21
22 class EnvironmentImpl : public base::Environment { 22 class EnvironmentImpl : public base::Environment {
23 public: 23 public:
24 virtual bool GetVar(const char* variable_name, std::string* result) { 24 virtual bool GetVar(const char* variable_name,
25 std::string* result) OVERRIDE {
25 if (GetVarImpl(variable_name, result)) 26 if (GetVarImpl(variable_name, result))
26 return true; 27 return true;
27 28
28 // Some commonly used variable names are uppercase while others 29 // Some commonly used variable names are uppercase while others
29 // are lowercase, which is inconsistent. Let's try to be helpful 30 // are lowercase, which is inconsistent. Let's try to be helpful
30 // and look for a variable name with the reverse case. 31 // and look for a variable name with the reverse case.
31 // I.e. HTTP_PROXY may be http_proxy for some users/systems. 32 // I.e. HTTP_PROXY may be http_proxy for some users/systems.
32 char first_char = variable_name[0]; 33 char first_char = variable_name[0];
33 std::string alternate_case_var; 34 std::string alternate_case_var;
34 if (first_char >= 'a' && first_char <= 'z') 35 if (first_char >= 'a' && first_char <= 'z')
35 alternate_case_var = StringToUpperASCII(std::string(variable_name)); 36 alternate_case_var = StringToUpperASCII(std::string(variable_name));
36 else if (first_char >= 'A' && first_char <= 'Z') 37 else if (first_char >= 'A' && first_char <= 'Z')
37 alternate_case_var = StringToLowerASCII(std::string(variable_name)); 38 alternate_case_var = StringToLowerASCII(std::string(variable_name));
38 else 39 else
39 return false; 40 return false;
40 return GetVarImpl(alternate_case_var.c_str(), result); 41 return GetVarImpl(alternate_case_var.c_str(), result);
41 } 42 }
42 43
43 virtual bool SetVar(const char* variable_name, const std::string& new_value) { 44 virtual bool SetVar(const char* variable_name,
45 const std::string& new_value) OVERRIDE {
44 return SetVarImpl(variable_name, new_value); 46 return SetVarImpl(variable_name, new_value);
45 } 47 }
46 48
47 virtual bool UnSetVar(const char* variable_name) { 49 virtual bool UnSetVar(const char* variable_name) OVERRIDE {
48 return UnSetVarImpl(variable_name); 50 return UnSetVarImpl(variable_name);
49 } 51 }
50 52
51 private: 53 private:
52 bool GetVarImpl(const char* variable_name, std::string* result) { 54 bool GetVarImpl(const char* variable_name, std::string* result) {
53 #if defined(OS_POSIX) 55 #if defined(OS_POSIX)
54 const char* env_value = getenv(variable_name); 56 const char* env_value = getenv(variable_name);
55 if (!env_value) 57 if (!env_value)
56 return false; 58 return false;
57 // Note that the variable may be defined but empty. 59 // Note that the variable may be defined but empty.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // static 118 // static
117 Environment* Environment::Create() { 119 Environment* Environment::Create() {
118 return new EnvironmentImpl(); 120 return new EnvironmentImpl();
119 } 121 }
120 122
121 bool Environment::HasVar(const char* variable_name) { 123 bool Environment::HasVar(const char* variable_name) {
122 return GetVar(variable_name, NULL); 124 return GetVar(variable_name, NULL);
123 } 125 }
124 126
125 } // namespace base 127 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/file_descriptor_shuffle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698