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

Side by Side Diff: chrome/installer/launcher_support/chrome_launcher_support.cc

Issue 10905238: If Chrome Binaries version > App Host version, then update App Host. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Renaming main update routine to LaunchAppHostUpdate(); fixing parameters of helper routines. Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/installer/launcher_support/chrome_launcher_support.h" 5 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <tchar.h> 8 #include <tchar.h>
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h"
11 #ifndef OFFICIAL_BUILD 12 #ifndef OFFICIAL_BUILD
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #endif 14 #endif
14 #include "base/string16.h" 15 #include "base/string16.h"
15 #include "base/win/registry.h" 16 #include "base/win/registry.h"
16 17
18 namespace chrome_launcher_support {
19
17 namespace { 20 namespace {
18 21
19 // TODO(erikwright): These constants are duplicated all over the place. 22 // http://crbug.com/148538
20 // Consolidate them somehow. 23 // TODO(huangs) Refactor the constants.
21 const wchar_t kChromeRegClientStateKey[] = 24 const wchar_t kGoogleRegClientStateKey[] =
22 L"Software\\Google\\Update\\ClientState\\" 25 L"Software\\Google\\Update\\ClientState\\";
23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 26
27 // Copied from chrome_appid.cc and google_chrome_binaries_distribution.cc.
28 const wchar_t kChromeBinariesAppGuid[] =
grt (UTC plus 2) 2012/09/14 14:26:52 can you remove some line wrapping throughout this
huangs 2012/09/14 16:34:24 Done. Also changed in update.cc.
29 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
30 const wchar_t kChromeAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
grt (UTC plus 2) 2012/09/14 14:26:52 this constant is from google_chrome_distribution.c
huangs 2012/09/14 16:34:24 Done.
24 31
25 const wchar_t kUninstallStringField[] = L"UninstallString"; 32 const wchar_t kUninstallStringField[] = L"UninstallString";
26 33
34 // Copied from util_constants.cc.
27 const wchar_t kChromeExe[] = L"chrome.exe"; 35 const wchar_t kChromeExe[] = L"chrome.exe";
28 36
29 #ifndef OFFICIAL_BUILD 37 #ifndef OFFICIAL_BUILD
30 FilePath GetDevelopmentChrome() { 38 FilePath GetDevelopmentChrome() {
31 FilePath current_directory; 39 FilePath current_directory;
32 if (PathService::Get(base::DIR_EXE, &current_directory)) { 40 if (PathService::Get(base::DIR_EXE, &current_directory)) {
33 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); 41 FilePath chrome_exe_path(current_directory.Append(kChromeExe));
34 if (file_util::PathExists(chrome_exe_path)) 42 if (file_util::PathExists(chrome_exe_path))
35 return chrome_exe_path; 43 return chrome_exe_path;
36 } 44 }
37 return FilePath(); 45 return FilePath();
38 } 46 }
39 #endif 47 #endif
40 48
49 // Reads the path to setup.exe from the value "UninstallString" within the
50 // specified product's "ClientState" registry key. Returns an empty FilePath if
51 // an error occurs or the product is not installed at the specified level.
52 FilePath GetSetupExeFromRegistry(InstallationLevel level,
53 const wchar_t* app_guid) {
54 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
55 HKEY_CURRENT_USER :
grt (UTC plus 2) 2012/09/14 14:26:52 these need to be indented four more spaces, no?
huangs 2012/09/14 16:34:24 Done. Also shifted brackets.
56 HKEY_LOCAL_MACHINE);
57 string16 subkey(kGoogleRegClientStateKey);
58 subkey.append(app_guid);
59 base::win::RegKey reg_key;
60 if (reg_key.Open(root_key, subkey.c_str(),
61 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
62 string16 uninstall;
63 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) {
64 FilePath setup_exe_path(uninstall);
65 if (file_util::PathExists(setup_exe_path))
66 return setup_exe_path;
67 }
68 }
69 return FilePath();
70 }
71
41 } // namespace 72 } // namespace
42 73
43 namespace chrome_launcher_support { 74 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
75 // Look in the registry for Chrome Binaries first.
76 FilePath setup_exe_path(
77 GetSetupExeFromRegistry(level, kChromeBinariesAppGuid));
78 // If the above fails, look in the registry for Chrome next.
79 if (setup_exe_path.empty()) {
80 setup_exe_path =
81 GetSetupExeFromRegistry(level, kChromeAppGuid);
grt (UTC plus 2) 2012/09/14 14:26:52 move up to previous line and get rid of braces.
huangs 2012/09/14 16:34:24 Done.
82 }
83 // If we fail again, then setup_exe_path would be empty.
84 return setup_exe_path;
85 }
86
87 FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
88 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level));
89 if (!setup_exe_path.empty()) {
90 // The uninstall path contains the path to setup.exe which is two levels
91 // down from chrome.exe. Move up two levels (plus one to drop the file
92 // name) and look for chrome.exe from there.
93 FilePath chrome_exe_path(
94 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe));
95 if (!file_util::PathExists(chrome_exe_path)) {
96 // By way of mild future proofing, look up one to see if there's a
97 // chrome.exe in the version directory
98 chrome_exe_path = chrome_exe_path.DirName().DirName().Append(kChromeExe);
99 }
100 if (file_util::PathExists(chrome_exe_path))
101 return chrome_exe_path;
102 }
103 return FilePath();
104 }
44 105
45 FilePath GetAnyChromePath() { 106 FilePath GetAnyChromePath() {
46 FilePath chrome_path; 107 FilePath chrome_path;
47 #ifndef OFFICIAL_BUILD 108 #ifndef OFFICIAL_BUILD
48 // For development mode, chrome.exe should be in same dir as the stub. 109 // For development mode, chrome.exe should be in same dir as the stub.
49 chrome_path = GetDevelopmentChrome(); 110 chrome_path = GetDevelopmentChrome();
50 #endif 111 #endif
51 if (chrome_path.empty()) 112 if (chrome_path.empty())
52 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 113 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
53 if (chrome_path.empty()) 114 if (chrome_path.empty())
54 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 115 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
55
56 return chrome_path; 116 return chrome_path;
57 } 117 }
58 118
59 FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
60 using base::win::RegKey;
61 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
62 HKEY_CURRENT_USER :
63 HKEY_LOCAL_MACHINE);
64 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE);
65
66 FilePath chrome_exe_path;
67
68 if (reg_key.Valid()) {
69 // Now grab the uninstall string from the appropriate ClientState key
70 // and use that as the base for a path to chrome.exe.
71 string16 uninstall;
72 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) {
73 // The uninstall path contains the path to setup.exe which is two levels
74 // down from chrome.exe. Move up two levels (plus one to drop the file
75 // name) and look for chrome.exe from there.
76 FilePath uninstall_path(uninstall);
77 chrome_exe_path =
78 uninstall_path.DirName().DirName().DirName().Append(kChromeExe);
79 if (!file_util::PathExists(chrome_exe_path)) {
80 // By way of mild future proofing, look up one to see if there's a
81 // chrome.exe in the version directory
82 chrome_exe_path =
83 uninstall_path.DirName().DirName().Append(kChromeExe);
84 }
85 }
86 }
87
88 if (file_util::PathExists(chrome_exe_path))
89 return chrome_exe_path;
90
91 return FilePath();
92 }
93
94 } // namespace chrome_launcher_support 119 } // namespace chrome_launcher_support
OLDNEW
« chrome/chrome.gyp ('K') | « chrome/installer/launcher_support/chrome_launcher_support.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698