Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_ENVIRONMENT_H_ |
michael@0 | 6 | #define BASE_ENVIRONMENT_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <map> |
michael@0 | 9 | #include <string> |
michael@0 | 10 | |
michael@0 | 11 | #include "base/base_export.h" |
michael@0 | 12 | #include "base/memory/scoped_ptr.h" |
michael@0 | 13 | #include "base/strings/string16.h" |
michael@0 | 14 | #include "build/build_config.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace base { |
michael@0 | 17 | |
michael@0 | 18 | namespace env_vars { |
michael@0 | 19 | |
michael@0 | 20 | #if defined(OS_POSIX) |
michael@0 | 21 | BASE_EXPORT extern const char kHome[]; |
michael@0 | 22 | #endif |
michael@0 | 23 | |
michael@0 | 24 | } // namespace env_vars |
michael@0 | 25 | |
michael@0 | 26 | class BASE_EXPORT Environment { |
michael@0 | 27 | public: |
michael@0 | 28 | virtual ~Environment(); |
michael@0 | 29 | |
michael@0 | 30 | // Static factory method that returns the implementation that provide the |
michael@0 | 31 | // appropriate platform-specific instance. |
michael@0 | 32 | static Environment* Create(); |
michael@0 | 33 | |
michael@0 | 34 | // Gets an environment variable's value and stores it in |result|. |
michael@0 | 35 | // Returns false if the key is unset. |
michael@0 | 36 | virtual bool GetVar(const char* variable_name, std::string* result) = 0; |
michael@0 | 37 | |
michael@0 | 38 | // Syntactic sugar for GetVar(variable_name, NULL); |
michael@0 | 39 | virtual bool HasVar(const char* variable_name); |
michael@0 | 40 | |
michael@0 | 41 | // Returns true on success, otherwise returns false. |
michael@0 | 42 | virtual bool SetVar(const char* variable_name, |
michael@0 | 43 | const std::string& new_value) = 0; |
michael@0 | 44 | |
michael@0 | 45 | // Returns true on success, otherwise returns false. |
michael@0 | 46 | virtual bool UnSetVar(const char* variable_name) = 0; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | #if defined(OS_WIN) |
michael@0 | 51 | |
michael@0 | 52 | typedef string16 NativeEnvironmentString; |
michael@0 | 53 | typedef std::map<NativeEnvironmentString, NativeEnvironmentString> |
michael@0 | 54 | EnvironmentMap; |
michael@0 | 55 | |
michael@0 | 56 | // Returns a modified environment vector constructed from the given environment |
michael@0 | 57 | // and the list of changes given in |changes|. Each key in the environment is |
michael@0 | 58 | // matched against the first element of the pairs. In the event of a match, the |
michael@0 | 59 | // value is replaced by the second of the pair, unless the second is empty, in |
michael@0 | 60 | // which case the key-value is removed. |
michael@0 | 61 | // |
michael@0 | 62 | // This Windows version takes and returns a Windows-style environment block |
michael@0 | 63 | // which is a concatenated list of null-terminated 16-bit strings. The end is |
michael@0 | 64 | // marked by a double-null terminator. The size of the returned string will |
michael@0 | 65 | // include the terminators. |
michael@0 | 66 | BASE_EXPORT string16 AlterEnvironment(const wchar_t* env, |
michael@0 | 67 | const EnvironmentMap& changes); |
michael@0 | 68 | |
michael@0 | 69 | #elif defined(OS_POSIX) |
michael@0 | 70 | |
michael@0 | 71 | typedef std::string NativeEnvironmentString; |
michael@0 | 72 | typedef std::map<NativeEnvironmentString, NativeEnvironmentString> |
michael@0 | 73 | EnvironmentMap; |
michael@0 | 74 | |
michael@0 | 75 | // See general comments for the Windows version above. |
michael@0 | 76 | // |
michael@0 | 77 | // This Posix version takes and returns a Posix-style environment block, which |
michael@0 | 78 | // is a null-terminated list of pointers to null-terminated strings. The |
michael@0 | 79 | // returned array will have appended to it the storage for the array itself so |
michael@0 | 80 | // there is only one pointer to manage, but this means that you can't copy the |
michael@0 | 81 | // array without keeping the original around. |
michael@0 | 82 | BASE_EXPORT scoped_ptr<char*[]> AlterEnvironment( |
michael@0 | 83 | const char* const* env, |
michael@0 | 84 | const EnvironmentMap& changes); |
michael@0 | 85 | |
michael@0 | 86 | #endif |
michael@0 | 87 | |
michael@0 | 88 | } // namespace base |
michael@0 | 89 | |
michael@0 | 90 | #endif // BASE_ENVIRONMENT_H_ |