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

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: Renamed app_host_upgrade.* to update.*; changed how App Host version is obtained; moved code to upd… 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
17 namespace { 18 namespace {
18 19
19 // TODO(erikwright): These constants are duplicated all over the place. 20 // TODO(huangs) Refactor the constants:
20 // Consolidate them somehow. 21 // http://code.google.com/p/chromium/issues/detail?id=148538
grt (UTC plus 2) 2012/09/13 20:04:12 same comment about shrinking this
huangs 2012/09/13 22:25:37 Done.
grt (UTC plus 2) 2012/09/14 14:26:52 Same comment about putting bug number on same line
21 const wchar_t kChromeRegClientStateKey[] = 22 const wchar_t kChromeBinariesRegClientStateKey[] =
22 L"Software\\Google\\Update\\ClientState\\" 23 L"Software\\Google\\Update\\ClientState\\"
23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 24 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
24 25
25 const wchar_t kUninstallStringField[] = L"UninstallString"; 26 const wchar_t kUninstallStringField[] = L"UninstallString";
26 27
28 // Copied from util_constants.cc.
27 const wchar_t kChromeExe[] = L"chrome.exe"; 29 const wchar_t kChromeExe[] = L"chrome.exe";
28 30
29 #ifndef OFFICIAL_BUILD 31 #ifndef OFFICIAL_BUILD
30 FilePath GetDevelopmentChrome() { 32 FilePath GetDevelopmentChrome() {
31 FilePath current_directory; 33 FilePath current_directory;
32 if (PathService::Get(base::DIR_EXE, &current_directory)) { 34 if (PathService::Get(base::DIR_EXE, &current_directory)) {
33 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); 35 FilePath chrome_exe_path(current_directory.Append(kChromeExe));
34 if (file_util::PathExists(chrome_exe_path)) 36 if (file_util::PathExists(chrome_exe_path))
35 return chrome_exe_path; 37 return chrome_exe_path;
36 } 38 }
37 return FilePath(); 39 return FilePath();
38 } 40 }
39 #endif 41 #endif
40 42
41 } // namespace 43 } // namespace
42 44
43 namespace chrome_launcher_support { 45 namespace chrome_launcher_support {
44 46
45 FilePath GetAnyChromePath() { 47 FilePath GetAnyChromePath() {
huangs 2012/09/13 22:25:37 Moving this routine to the end, so dependency prop
46 FilePath chrome_path; 48 FilePath chrome_path;
47 #ifndef OFFICIAL_BUILD 49 #ifndef OFFICIAL_BUILD
48 // For development mode, chrome.exe should be in same dir as the stub. 50 // For development mode, chrome.exe should be in same dir as the stub.
49 chrome_path = GetDevelopmentChrome(); 51 chrome_path = GetDevelopmentChrome();
50 #endif 52 #endif
51 if (chrome_path.empty()) 53 if (chrome_path.empty())
52 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 54 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
53 if (chrome_path.empty()) 55 if (chrome_path.empty())
54 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 56 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
55 57
56 return chrome_path; 58 return chrome_path;
57 } 59 }
58 60
59 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 61 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
60 using base::win::RegKey; 62 using base::win::RegKey;
61 HKEY root_key = (level == USER_LEVEL_INSTALLATION ? 63 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
62 HKEY_CURRENT_USER : 64 HKEY_CURRENT_USER :
63 HKEY_LOCAL_MACHINE); 65 HKEY_LOCAL_MACHINE);
64 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); 66 RegKey reg_key;
65 67 if (reg_key.Open(root_key, kChromeBinariesRegClientStateKey,
erikwright (departed) 2012/09/13 19:27:49 If we can't find the ChromeBinaries, next try Chro
huangs 2012/09/13 22:25:37 Sorry for the no-op; misread comments! Done. Extr
66 FilePath chrome_exe_path; 68 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
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; 69 string16 uninstall;
72 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { 70 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) {
73 // The uninstall path contains the path to setup.exe which is two levels 71 FilePath setup_exe_path(uninstall);
74 // down from chrome.exe. Move up two levels (plus one to drop the file 72 if (file_util::PathExists(setup_exe_path))
75 // name) and look for chrome.exe from there. 73 return setup_exe_path;
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 } 74 }
86 } 75 }
87
88 if (file_util::PathExists(chrome_exe_path))
89 return chrome_exe_path;
90
91 return FilePath(); 76 return FilePath();
92 } 77 }
93 78
79 FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
80 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level));
81 if (!setup_exe_path.empty()) {
82 FilePath chrome_exe_path;
83 // The uninstall path contains the path to setup.exe which is two levels
84 // down from chrome.exe. Move up two levels (plus one to drop the file
85 // name) and look for chrome.exe from there.
86 chrome_exe_path =
87 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe);
88 if (!file_util::PathExists(chrome_exe_path)) {
89 // By way of mild future proofing, look up one to see if there's a
90 // chrome.exe in the version directory
91 chrome_exe_path = chrome_exe_path.DirName().DirName().Append(kChromeExe);
92 }
93 if (file_util::PathExists(chrome_exe_path))
94 return chrome_exe_path;
95 }
96 return FilePath();
97 }
98
94 } // namespace chrome_launcher_support 99 } // namespace chrome_launcher_support
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698