Chromium Code Reviews| Index: chrome/tools/launcher_support/chrome_launcher_support.cc |
| diff --git a/chrome/tools/launcher_support/chrome_launcher_support.cc b/chrome/tools/launcher_support/chrome_launcher_support.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4cafe7e194722a9af1da855dfe78d05ee1252cbd |
| --- /dev/null |
| +++ b/chrome/tools/launcher_support/chrome_launcher_support.cc |
| @@ -0,0 +1,85 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/tools/launcher_support/chrome_launcher_support.h" |
| + |
| +#include <windows.h> |
| +#include <tchar.h> |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/path_service.h" |
| +#include "base/string16.h" |
| +#include "base/win/registry.h" |
| + |
| +namespace { |
| + |
| +// TODO(erikwright): These constants are duplicated all over the place. |
| +// Consolidate them somehow. |
|
robertshield
2012/06/13 18:01:53
There are similarly worded TODO(robertshield)s els
Vitaly Buka (NO REVIEWS)
2012/06/13 18:08:19
Please keep in mind that we'd like to avoid depend
erikwright (departed)
2012/06/13 19:43:43
Absolutely. My client of this library is under a s
|
| +const wchar_t kChromeRegClientStateKey[] = |
| + L"Software\\Google\\Update\\ClientState\\" |
| + L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| + |
| +const wchar_t kGoogleChromeExePath[] = |
| + L"Google\\Chrome\\Application\\chrome.exe"; |
| + |
| +const wchar_t kUninstallStringField[] = L"UninstallString"; |
| + |
| +const wchar_t kChromeExe[] = L"chrome.exe"; |
| + |
| +} // namespace |
| + |
| +namespace chrome_launcher_support { |
| + |
| +FilePath GetAnyChromePath() { |
| + FilePath chrome_path = GetChromePathForInstallationLevel( |
|
grt (UTC plus 2)
2012/06/13 18:00:10
i've been told repeatedly that chromium prefers Fi
erikwright (departed)
2012/06/13 19:43:43
Done.
|
| + SYSTEM_LEVEL_INSTALLATION); |
| + if (!chrome_path.empty()) |
| + return chrome_path; |
| + chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); |
| + if (!chrome_path.empty()) |
| + return chrome_path; |
| + if (PathService::Get(base::DIR_PROGRAM_FILES, &chrome_path)) { |
| + chrome_path.Append(kGoogleChromeExePath); |
|
grt (UTC plus 2)
2012/06/13 18:00:10
chrome_path = chrome_path.Append(kGoogleChromeExeP
erikwright (departed)
2012/06/13 19:43:43
Ouch! Perhaps that's a sign that I can just remove
Vitaly Buka (NO REVIEWS)
2012/06/13 20:18:37
Yep. My mistake. But I still believe it might be u
|
| + if (file_util::PathExists(chrome_path)) |
| + return chrome_path; |
| + } |
| + return FilePath(); |
| +} |
| + |
| +FilePath GetChromePathForInstallationLevel(InstallationLevel level) { |
|
grt (UTC plus 2)
2012/06/13 18:00:10
will this ever be used by code that wishes to find
erikwright (departed)
2012/06/13 19:43:43
I would say probably not. But I'm not sure how to
|
| + using base::win::RegKey; |
| + HKEY root_key = (level == USER_LEVEL_INSTALLATION ? |
| + HKEY_CURRENT_USER : |
| + HKEY_LOCAL_MACHINE); |
| + RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); |
| + |
| + FilePath chrome_exe_path; |
| + |
| + if (reg_key.Valid()) { |
| + // Now grab the uninstall string from the appropriate ClientState key |
| + // and use that as the base for a path to chrome.exe. |
| + string16 uninstall; |
| + if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { |
| + // The uninstall path contains the path to setup.exe which is two levels |
| + // down from chrome.exe. Move up two levels (plus one to drop the file |
| + // name) and look for chrome.exe from there. |
| + FilePath uninstall_path(uninstall); |
| + chrome_exe_path = |
| + uninstall_path.DirName().DirName().DirName().Append(kChromeExe); |
| + if (!file_util::PathExists(chrome_exe_path)) { |
| + // By way of mild future proofing, look up one to see if there's a |
| + // chrome.exe in the version directory |
| + chrome_exe_path = |
| + uninstall_path.DirName().DirName().Append(kChromeExe); |
| + } |
| + } |
| + } |
| + |
| + if (file_util::PathExists(chrome_exe_path)) |
| + return chrome_exe_path; |
| + |
| + return FilePath(); |
| +} |
| + |
| +} // namespace chrome_launcher_support |