Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/tools/launcher_support/chrome_launcher_support.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 #include <tchar.h> | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/path_service.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "base/win/registry.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // TODO(erikwright): These constants are duplicated all over the place. | |
| 18 // 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
| |
| 19 const wchar_t kChromeRegClientStateKey[] = | |
| 20 L"Software\\Google\\Update\\ClientState\\" | |
| 21 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
| 22 | |
| 23 const wchar_t kGoogleChromeExePath[] = | |
| 24 L"Google\\Chrome\\Application\\chrome.exe"; | |
| 25 | |
| 26 const wchar_t kUninstallStringField[] = L"UninstallString"; | |
| 27 | |
| 28 const wchar_t kChromeExe[] = L"chrome.exe"; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 namespace chrome_launcher_support { | |
| 33 | |
| 34 FilePath GetAnyChromePath() { | |
| 35 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.
| |
| 36 SYSTEM_LEVEL_INSTALLATION); | |
| 37 if (!chrome_path.empty()) | |
| 38 return chrome_path; | |
| 39 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); | |
| 40 if (!chrome_path.empty()) | |
| 41 return chrome_path; | |
| 42 if (PathService::Get(base::DIR_PROGRAM_FILES, &chrome_path)) { | |
| 43 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
| |
| 44 if (file_util::PathExists(chrome_path)) | |
| 45 return chrome_path; | |
| 46 } | |
| 47 return FilePath(); | |
| 48 } | |
| 49 | |
| 50 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
| |
| 51 using base::win::RegKey; | |
| 52 HKEY root_key = (level == USER_LEVEL_INSTALLATION ? | |
| 53 HKEY_CURRENT_USER : | |
| 54 HKEY_LOCAL_MACHINE); | |
| 55 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); | |
| 56 | |
| 57 FilePath chrome_exe_path; | |
| 58 | |
| 59 if (reg_key.Valid()) { | |
| 60 // Now grab the uninstall string from the appropriate ClientState key | |
| 61 // and use that as the base for a path to chrome.exe. | |
| 62 string16 uninstall; | |
| 63 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { | |
| 64 // The uninstall path contains the path to setup.exe which is two levels | |
| 65 // down from chrome.exe. Move up two levels (plus one to drop the file | |
| 66 // name) and look for chrome.exe from there. | |
| 67 FilePath uninstall_path(uninstall); | |
| 68 chrome_exe_path = | |
| 69 uninstall_path.DirName().DirName().DirName().Append(kChromeExe); | |
| 70 if (!file_util::PathExists(chrome_exe_path)) { | |
| 71 // By way of mild future proofing, look up one to see if there's a | |
| 72 // chrome.exe in the version directory | |
| 73 chrome_exe_path = | |
| 74 uninstall_path.DirName().DirName().Append(kChromeExe); | |
| 75 } | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 if (file_util::PathExists(chrome_exe_path)) | |
| 80 return chrome_exe_path; | |
| 81 | |
| 82 return FilePath(); | |
| 83 } | |
| 84 | |
| 85 } // namespace chrome_launcher_support | |
| OLD | NEW |