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

Side by Side Diff: chrome/app/client_util.cc

Issue 3135036: Use Environment::GetVar instead of the obscure EnvQueryStr function. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: another fix Created 10 years, 4 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 | no next file » | 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) 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 #include <windows.h> 5 #include <windows.h>
6 #include <shlwapi.h> 6 #include <shlwapi.h>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Gets the path of the current exe with a trailing backslash. 70 // Gets the path of the current exe with a trailing backslash.
71 std::wstring GetExecutablePath() { 71 std::wstring GetExecutablePath() {
72 wchar_t path[MAX_PATH]; 72 wchar_t path[MAX_PATH];
73 ::GetModuleFileNameW(NULL, path, MAX_PATH); 73 ::GetModuleFileNameW(NULL, path, MAX_PATH);
74 if (!::PathRemoveFileSpecW(path)) 74 if (!::PathRemoveFileSpecW(path))
75 return std::wstring(); 75 return std::wstring();
76 std::wstring exe_path(path); 76 std::wstring exe_path(path);
77 return exe_path.append(L"\\"); 77 return exe_path.append(L"\\");
78 } 78 }
79 79
80 // Not generic, we only handle strings up to 128 chars.
81 bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) {
82 wchar_t out[128];
83 DWORD count = sizeof(out)/sizeof(out[0]);
84 DWORD rv = ::GetEnvironmentVariableW(key_name, out, count);
85 if ((rv == 0) || (rv >= count))
86 return false;
87 *value = out;
88 return true;
89 }
90
91 // Expects that |dir| has a trailing backslash. |dir| is modified so it 80 // Expects that |dir| has a trailing backslash. |dir| is modified so it
92 // contains the full path that was tried. Caller must check for the return 81 // contains the full path that was tried. Caller must check for the return
93 // value not being null to dermine if this path contains a valid dll. 82 // value not being null to dermine if this path contains a valid dll.
94 HMODULE LoadChromeWithDirectory(std::wstring* dir) { 83 HMODULE LoadChromeWithDirectory(std::wstring* dir) {
95 ::SetCurrentDirectoryW(dir->c_str()); 84 ::SetCurrentDirectoryW(dir->c_str());
96 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 85 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
97 #ifdef _WIN64 86 #ifdef _WIN64
98 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) == 87 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) ==
99 switches::kNaClBrokerProcess) || 88 switches::kNaClBrokerProcess) ||
100 (cmd_line.GetSwitchValueASCII(switches::kProcessType) == 89 (cmd_line.GetSwitchValueASCII(switches::kProcessType) ==
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // if we should stick with an older dll version even if a new one is available 188 // if we should stick with an older dll version even if a new one is available
200 // to support upgrade-in-place scenarios, and if that fails we finally we look 189 // to support upgrade-in-place scenarios, and if that fails we finally we look
201 // at the registry which should point us to the latest version. 190 // at the registry which should point us to the latest version.
202 HMODULE MainDllLoader::Load(std::wstring* version, std::wstring* file) { 191 HMODULE MainDllLoader::Load(std::wstring* version, std::wstring* file) {
203 std::wstring dir(GetExecutablePath()); 192 std::wstring dir(GetExecutablePath());
204 *file = dir; 193 *file = dir;
205 HMODULE dll = LoadChromeWithDirectory(file); 194 HMODULE dll = LoadChromeWithDirectory(file);
206 if (dll) 195 if (dll)
207 return dll; 196 return dll;
208 197
209 if (!EnvQueryStr( 198 scoped_ptr<base::Environment> env(base::Environment::Create());
210 BrowserDistribution::GetDistribution()->GetEnvVersionKey().c_str(), 199
211 version)) { 200 std::string version_value;
201 if (!env->GetVar(WideToUTF8(
202 BrowserDistribution::GetDistribution()->GetEnvVersionKey()).c_str(),
203 &version_value)) {
212 std::wstring reg_path(GetRegistryPath()); 204 std::wstring reg_path(GetRegistryPath());
205
206 *version = UTF8ToWide(version_value);
213 // Look into the registry to find the latest version. 207 // Look into the registry to find the latest version.
214 if (!GetVersion(dir.c_str(), reg_path.c_str(), version)) 208 if (!GetVersion(dir.c_str(), reg_path.c_str(), version))
215 return NULL; 209 return NULL;
216 } 210 }
217 211
218 *file = dir; 212 *file = dir;
219 file->append(*version).append(L"\\"); 213 file->append(*version).append(L"\\");
220 return LoadChromeWithDirectory(file); 214 return LoadChromeWithDirectory(file);
221 } 215 }
222 216
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 293 }
300 }; 294 };
301 295
302 MainDllLoader* MakeMainDllLoader() { 296 MainDllLoader* MakeMainDllLoader() {
303 #if defined(GOOGLE_CHROME_BUILD) 297 #if defined(GOOGLE_CHROME_BUILD)
304 return new ChromeDllLoader(); 298 return new ChromeDllLoader();
305 #else 299 #else
306 return new ChromiumDllLoader(); 300 return new ChromiumDllLoader();
307 #endif 301 #endif
308 } 302 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698