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

Side by Side Diff: base/environment.h

Issue 2094913002: Make base::Environment::Create() return unique_ptrs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit, rebase Created 4 years, 5 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
« no previous file with comments | « no previous file | base/environment.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 #ifndef BASE_ENVIRONMENT_H_ 5 #ifndef BASE_ENVIRONMENT_H_
6 #define BASE_ENVIRONMENT_H_ 6 #define BASE_ENVIRONMENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/string_piece.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 namespace env_vars { 19 namespace env_vars {
19 20
20 #if defined(OS_POSIX) 21 #if defined(OS_POSIX)
21 BASE_EXPORT extern const char kHome[]; 22 BASE_EXPORT extern const char kHome[];
22 #endif 23 #endif
23 24
24 } // namespace env_vars 25 } // namespace env_vars
25 26
26 class BASE_EXPORT Environment { 27 class BASE_EXPORT Environment {
27 public: 28 public:
28 virtual ~Environment(); 29 virtual ~Environment();
29 30
30 // Static factory method that returns the implementation that provide the 31 // Returns the appropriate platform-specific instance.
31 // appropriate platform-specific instance. 32 static std::unique_ptr<Environment> Create();
32 static Environment* Create();
33 33
34 // Gets an environment variable's value and stores it in |result|. 34 // Gets an environment variable's value and stores it in |result|.
35 // Returns false if the key is unset. 35 // Returns false if the key is unset.
36 virtual bool GetVar(const char* variable_name, std::string* result) = 0; 36 virtual bool GetVar(StringPiece variable_name, std::string* result) = 0;
37 37
38 // Syntactic sugar for GetVar(variable_name, NULL); 38 // Syntactic sugar for GetVar(variable_name, nullptr);
39 virtual bool HasVar(const char* variable_name); 39 virtual bool HasVar(StringPiece variable_name);
40 40
41 // Returns true on success, otherwise returns false. 41 // Returns true on success, otherwise returns false.
42 virtual bool SetVar(const char* variable_name, 42 virtual bool SetVar(StringPiece variable_name,
43 const std::string& new_value) = 0; 43 const std::string& new_value) = 0;
44 44
45 // Returns true on success, otherwise returns false. 45 // Returns true on success, otherwise returns false.
46 virtual bool UnSetVar(const char* variable_name) = 0; 46 virtual bool UnSetVar(StringPiece variable_name) = 0;
47 }; 47 };
48 48
49 49
50 #if defined(OS_WIN) 50 #if defined(OS_WIN)
51 51
52 typedef string16 NativeEnvironmentString; 52 typedef string16 NativeEnvironmentString;
53 typedef std::map<NativeEnvironmentString, NativeEnvironmentString> 53 typedef std::map<NativeEnvironmentString, NativeEnvironmentString>
54 EnvironmentMap; 54 EnvironmentMap;
55 55
56 // Returns a modified environment vector constructed from the given environment 56 // Returns a modified environment vector constructed from the given environment
(...skipping 24 matching lines...) Expand all
81 // array without keeping the original around. 81 // array without keeping the original around.
82 BASE_EXPORT std::unique_ptr<char* []> AlterEnvironment( 82 BASE_EXPORT std::unique_ptr<char* []> AlterEnvironment(
83 const char* const* env, 83 const char* const* env,
84 const EnvironmentMap& changes); 84 const EnvironmentMap& changes);
85 85
86 #endif 86 #endif
87 87
88 } // namespace base 88 } // namespace base
89 89
90 #endif // BASE_ENVIRONMENT_H_ 90 #endif // BASE_ENVIRONMENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698