security/sandbox/chromium/base/environment.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/environment.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_ENVIRONMENT_H_
     1.9 +#define BASE_ENVIRONMENT_H_
    1.10 +
    1.11 +#include <map>
    1.12 +#include <string>
    1.13 +
    1.14 +#include "base/base_export.h"
    1.15 +#include "base/memory/scoped_ptr.h"
    1.16 +#include "base/strings/string16.h"
    1.17 +#include "build/build_config.h"
    1.18 +
    1.19 +namespace base {
    1.20 +
    1.21 +namespace env_vars {
    1.22 +
    1.23 +#if defined(OS_POSIX)
    1.24 +BASE_EXPORT extern const char kHome[];
    1.25 +#endif
    1.26 +
    1.27 +}  // namespace env_vars
    1.28 +
    1.29 +class BASE_EXPORT Environment {
    1.30 + public:
    1.31 +  virtual ~Environment();
    1.32 +
    1.33 +  // Static factory method that returns the implementation that provide the
    1.34 +  // appropriate platform-specific instance.
    1.35 +  static Environment* Create();
    1.36 +
    1.37 +  // Gets an environment variable's value and stores it in |result|.
    1.38 +  // Returns false if the key is unset.
    1.39 +  virtual bool GetVar(const char* variable_name, std::string* result) = 0;
    1.40 +
    1.41 +  // Syntactic sugar for GetVar(variable_name, NULL);
    1.42 +  virtual bool HasVar(const char* variable_name);
    1.43 +
    1.44 +  // Returns true on success, otherwise returns false.
    1.45 +  virtual bool SetVar(const char* variable_name,
    1.46 +                      const std::string& new_value) = 0;
    1.47 +
    1.48 +  // Returns true on success, otherwise returns false.
    1.49 +  virtual bool UnSetVar(const char* variable_name) = 0;
    1.50 +};
    1.51 +
    1.52 +
    1.53 +#if defined(OS_WIN)
    1.54 +
    1.55 +typedef string16 NativeEnvironmentString;
    1.56 +typedef std::map<NativeEnvironmentString, NativeEnvironmentString>
    1.57 +    EnvironmentMap;
    1.58 +
    1.59 +// Returns a modified environment vector constructed from the given environment
    1.60 +// and the list of changes given in |changes|. Each key in the environment is
    1.61 +// matched against the first element of the pairs. In the event of a match, the
    1.62 +// value is replaced by the second of the pair, unless the second is empty, in
    1.63 +// which case the key-value is removed.
    1.64 +//
    1.65 +// This Windows version takes and returns a Windows-style environment block
    1.66 +// which is a concatenated list of null-terminated 16-bit strings. The end is
    1.67 +// marked by a double-null terminator. The size of the returned string will
    1.68 +// include the terminators.
    1.69 +BASE_EXPORT string16 AlterEnvironment(const wchar_t* env,
    1.70 +                                      const EnvironmentMap& changes);
    1.71 +
    1.72 +#elif defined(OS_POSIX)
    1.73 +
    1.74 +typedef std::string NativeEnvironmentString;
    1.75 +typedef std::map<NativeEnvironmentString, NativeEnvironmentString>
    1.76 +    EnvironmentMap;
    1.77 +
    1.78 +// See general comments for the Windows version above.
    1.79 +//
    1.80 +// This Posix version takes and returns a Posix-style environment block, which
    1.81 +// is a null-terminated list of pointers to null-terminated strings. The
    1.82 +// returned array will have appended to it the storage for the array itself so
    1.83 +// there is only one pointer to manage, but this means that you can't copy the
    1.84 +// array without keeping the original around.
    1.85 +BASE_EXPORT scoped_ptr<char*[]> AlterEnvironment(
    1.86 +    const char* const* env,
    1.87 +    const EnvironmentMap& changes);
    1.88 +
    1.89 +#endif
    1.90 +
    1.91 +}  // namespace base
    1.92 +
    1.93 +#endif  // BASE_ENVIRONMENT_H_

mercurial