OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_ENV_VAR_H_ | 5 #ifndef BASE_ENV_VAR_H_ |
6 #define BASE_ENV_VAR_H_ | 6 #define BASE_ENV_VAR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace env_vars { | 15 namespace env_vars { |
16 | 16 |
17 #if defined(OS_POSIX) | 17 #if defined(OS_POSIX) |
18 extern const char kHome[]; | 18 extern const char kHome[]; |
19 #endif | 19 #endif |
20 | 20 |
21 } // namespace env_vars | 21 } // namespace env_vars |
22 | 22 |
23 // These are used to derive mocks for unittests. | |
24 class EnvVarGetter { | 23 class EnvVarGetter { |
25 public: | 24 public: |
26 virtual ~EnvVarGetter(); | 25 virtual ~EnvVarGetter(); |
27 | 26 |
27 // Static factory method that returns the implementation that provide the | |
28 // appropriate platform-specific instance. | |
29 static EnvVarGetter* Create(); | |
30 | |
28 // Gets an environment variable's value and stores it in |result|. | 31 // Gets an environment variable's value and stores it in |result|. |
29 // Returns false if the key is unset. | 32 // Returns false if the key is unset. |
30 virtual bool GetEnv(const char* variable_name, std::string* result) = 0; | 33 virtual bool GetEnv(const char* variable_name, std::string* result) = 0; |
31 | 34 |
32 // Syntactic sugar for GetEnv(variable_name, NULL); | 35 // Syntactic sugar for GetEnv(variable_name, NULL); |
33 virtual bool HasEnv(const char* variable_name); | 36 virtual bool HasEnv(const char* variable_name); |
34 | 37 |
35 // Returns true on success, otherwise returns false. | 38 // Returns true on success, otherwise returns false. |
36 virtual bool SetEnv(const char* variable_name, | 39 virtual bool SetEnv(const char* variable_name, |
37 const std::string& new_value) = 0; | 40 const std::string& new_value) = 0; |
38 | 41 |
39 // Create an instance of EnvVarGetter | 42 // Returns true on success, otherwise returns false. |
40 static EnvVarGetter* Create(); | 43 virtual bool UnSetEnv(const char* variable_name) = 0; |
viettrungluu
2010/08/03 06:02:13
Even more after-the-fact drive-by nit: "unset" is
| |
41 }; | 44 }; |
42 | 45 |
43 } // namespace base | 46 } // namespace base |
44 | 47 |
45 #endif // BASE_ENV_VAR_H_ | 48 #endif // BASE_ENV_VAR_H_ |
OLD | NEW |