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

Side by Side Diff: base/environment.cc

Issue 614103004: replace 'virtual ... OVERRIDE' with '... override' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: process base/ Created 6 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 12
13 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #elif defined(OS_WIN) 15 #elif defined(OS_WIN)
16 #include <windows.h> 16 #include <windows.h>
17 #endif 17 #endif
18 18
19 namespace base { 19 namespace base {
20 20
21 namespace { 21 namespace {
22 22
23 class EnvironmentImpl : public base::Environment { 23 class EnvironmentImpl : public base::Environment {
24 public: 24 public:
25 virtual bool GetVar(const char* variable_name, 25 bool GetVar(const char* variable_name, std::string* result) override {
26 std::string* result) OVERRIDE {
27 if (GetVarImpl(variable_name, result)) 26 if (GetVarImpl(variable_name, result))
28 return true; 27 return true;
29 28
30 // Some commonly used variable names are uppercase while others 29 // Some commonly used variable names are uppercase while others
31 // are lowercase, which is inconsistent. Let's try to be helpful 30 // are lowercase, which is inconsistent. Let's try to be helpful
32 // and look for a variable name with the reverse case. 31 // and look for a variable name with the reverse case.
33 // 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.
34 char first_char = variable_name[0]; 33 char first_char = variable_name[0];
35 std::string alternate_case_var; 34 std::string alternate_case_var;
36 if (first_char >= 'a' && first_char <= 'z') 35 if (first_char >= 'a' && first_char <= 'z')
37 alternate_case_var = StringToUpperASCII(std::string(variable_name)); 36 alternate_case_var = StringToUpperASCII(std::string(variable_name));
38 else if (first_char >= 'A' && first_char <= 'Z') 37 else if (first_char >= 'A' && first_char <= 'Z')
39 alternate_case_var = base::StringToLowerASCII(std::string(variable_name)); 38 alternate_case_var = base::StringToLowerASCII(std::string(variable_name));
40 else 39 else
41 return false; 40 return false;
42 return GetVarImpl(alternate_case_var.c_str(), result); 41 return GetVarImpl(alternate_case_var.c_str(), result);
43 } 42 }
44 43
45 virtual bool SetVar(const char* variable_name, 44 bool SetVar(const char* variable_name,
46 const std::string& new_value) OVERRIDE { 45 const std::string& new_value) override {
47 return SetVarImpl(variable_name, new_value); 46 return SetVarImpl(variable_name, new_value);
48 } 47 }
49 48
50 virtual bool UnSetVar(const char* variable_name) OVERRIDE { 49 bool UnSetVar(const char* variable_name) override {
51 return UnSetVarImpl(variable_name); 50 return UnSetVarImpl(variable_name);
52 } 51 }
53 52
54 private: 53 private:
55 bool GetVarImpl(const char* variable_name, std::string* result) { 54 bool GetVarImpl(const char* variable_name, std::string* result) {
56 #if defined(OS_POSIX) 55 #if defined(OS_POSIX)
57 const char* env_value = getenv(variable_name); 56 const char* env_value = getenv(variable_name);
58 if (!env_value) 57 if (!env_value)
59 return false; 58 return false;
60 // Note that the variable may be defined but empty. 59 // Note that the variable may be defined but empty.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 for (size_t i = 0; i < result_indices.size(); i++) 227 for (size_t i = 0; i < result_indices.size(); i++)
229 result[i] = &storage_data[result_indices[i]]; 228 result[i] = &storage_data[result_indices[i]];
230 result[result_indices.size()] = 0; // Null terminator. 229 result[result_indices.size()] = 0; // Null terminator.
231 230
232 return result.Pass(); 231 return result.Pass();
233 } 232 }
234 233
235 #endif // OS_POSIX 234 #endif // OS_POSIX
236 235
237 } // namespace base 236 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698