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/installer/util/google_update_util.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/file_path.h" | |
9 #include "base/file_util.h" | |
10 #include "base/logging.h" | |
11 #include "base/process_util.h" | |
12 #include "base/string16.h" | |
13 #include "base/win/registry.h" | |
14 #include "base/win/scoped_handle.h" | |
15 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | |
16 #include "chrome/installer/util/google_update_constants.h" | |
17 #include "chrome/installer/util/google_update_settings.h" | |
18 | |
19 using base::win::RegKey; | |
20 | |
21 namespace google_update { | |
22 | |
23 namespace { | |
24 | |
25 const int kGoogleUpdateTimeoutMs = 20 * 1000; | |
26 | |
27 // Returns true if and only if Google Update is installed at the given level. | |
28 bool IsGoogleUpdateInstalled(bool system_install) { | |
29 // Using the existence of version key in the registry to decide. | |
30 return GoogleUpdateSettings::GetGoogleUpdateVersion(system_install).IsValid(); | |
31 } | |
32 | |
33 // Returns GoogleUpdateSetup.exe's executable path at |system_level|, | |
34 // or an empty path if none is found. | |
35 FilePath GetGoogleUpdateSetupExe(bool system_install) { | |
36 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
37 RegKey update_key; | |
38 | |
39 if (update_key.Open(root_key, kRegPathGoogleUpdate, KEY_QUERY_VALUE) == | |
40 ERROR_SUCCESS) { | |
41 string16 path_str; | |
42 string16 version_str; | |
43 if ((update_key.ReadValue(kRegPathField, &path_str) == ERROR_SUCCESS) && | |
44 (update_key.ReadValue(kRegGoogleUpdateVersion, &version_str) == | |
45 ERROR_SUCCESS)) { | |
46 FilePath google_update_setup(FilePath(path_str).DirName(). | |
47 Append(version_str). | |
48 Append(kGoogleUpdateSetupExe)); | |
49 if (file_util::PathExists(google_update_setup)) { | |
grt (UTC plus 2)
2012/09/21 14:20:33
i suggest you don't bother with this check. it's
huangs
2012/09/21 18:48:43
Done.
| |
50 return google_update_setup; | |
51 } else { | |
52 LOG(ERROR) << "Unexpectedly missing " << kGoogleUpdateSetupExe; | |
erikwright (departed)
2012/09/21 14:08:49
log google_update_setup instead (so full path is i
huangs
2012/09/21 18:48:43
Moot, as check is removed.
| |
53 } | |
54 } | |
55 } | |
56 return FilePath(); | |
57 } | |
58 | |
59 // Returns command line to install Google Update at user-level if Google Update | |
60 // is already installed at system-level,or an empty command line if none found. | |
61 // This is not in GoogleUpdateSettings because we build the command line, | |
erikwright (departed)
2012/09/21 14:08:49
Remove "This is not ..."
huangs
2012/09/21 18:48:43
Done.
| |
62 // instead of just reading it from the registry. | |
63 CommandLine GetUserLevelGoogleUpdateInstallCommandLine() { | |
64 CommandLine cmd(CommandLine::NO_PROGRAM); | |
65 FilePath google_update_setup(GetGoogleUpdateSetupExe(true)); // system-level. | |
66 if (!google_update_setup.empty()) { | |
67 cmd.SetProgram(google_update_setup); | |
68 // Appends parameter "/install runtime=true&needsadmin=false /silent" | |
69 // Constants are found in code.google.com/p/omaha/common/const_cmd_line.h. | |
70 cmd.AppendArg("/install"); | |
71 // The "&" can be used in base::LaunchProcess() without quotation | |
72 // (this is problematic only if run from command prompt). | |
73 cmd.AppendArg("runtime=true&needsadmin=false"); | |
74 cmd.AppendArg("/silent"); | |
75 } | |
76 return cmd; | |
77 } | |
78 | |
79 bool ExecuteGoogleUpdateCommand(const string16& cmd_string, | |
grt (UTC plus 2)
2012/09/21 14:20:33
please add a doc comment
huangs
2012/09/21 18:48:43
Moot: Routine inlined.
| |
80 const string16& cmd_name, | |
81 base::win::ScopedHandle* process) { | |
82 bool success = false; | |
83 if (cmd_string.empty()) { // Command not rendered. | |
grt (UTC plus 2)
2012/09/21 14:20:33
remove this whole block and let an empty cmd_strin
huangs
2012/09/21 18:48:43
Moot: Routine inlined.
| |
84 LOG(ERROR) << "Failed to find " << cmd_name; | |
85 } else { | |
86 LOG(INFO) << "Launching " << cmd_name << ": " << cmd_string; | |
erikwright (departed)
2012/09/21 14:08:49
just log cmd_string instead of cmd_name here.
huangs
2012/09/21 18:48:43
Done.
| |
87 success = base::LaunchProcess(cmd_string, base::LaunchOptions(), | |
88 process->Receive()); | |
89 if (!success) { | |
90 PLOG(ERROR) << "Failed to launch " << cmd_name << " (" << cmd_string | |
erikwright (departed)
2012/09/21 14:08:49
no need to include cmd_name.
| |
91 << ")."; | |
grt (UTC plus 2)
2012/09/21 14:20:33
remove the period at the end here since PLOG will
huangs
2012/09/21 18:48:43
Done.
| |
92 } | |
93 } | |
94 return success; | |
95 } | |
96 | |
97 bool WaitForGoogleUpdateCommand(const string16& cmd_string, | |
98 const string16& cmd_name, | |
99 const base::win::ScopedHandle& process) { | |
erikwright (departed)
2012/09/21 14:08:49
Define |process| as a plain-old HANDLE. There is a
huangs
2012/09/21 18:48:43
Moot: Function inlined. Note extra complexity wit
| |
100 bool success = false; | |
101 int exit_code = 0; | |
102 if (base::WaitForExitCodeWithTimeout( | |
103 process, &exit_code, | |
grt (UTC plus 2)
2012/09/21 14:20:33
please move these to the previous line to conserve
huangs
2012/09/21 18:48:43
Done.
| |
104 base::TimeDelta::FromMilliseconds(kGoogleUpdateTimeoutMs))) { | |
105 if (exit_code == 0) { | |
106 LOG(INFO) << " normal exit."; | |
grt (UTC plus 2)
2012/09/21 14:20:33
i should never have put this there, please remove
huangs
2012/09/21 18:48:43
Done.
| |
107 success = true; | |
108 } else { | |
109 PLOG(ERROR) << cmd_name << " (" << cmd_string << ") exited with code " | |
erikwright (departed)
2012/09/21 14:08:49
no need for cmd_name here.
grt (UTC plus 2)
2012/09/21 14:20:33
PLOG -> LOG
huangs
2012/09/21 18:48:43
Done.
huangs
2012/09/21 18:48:43
Done.
| |
110 << exit_code << "."; | |
111 } | |
112 } else { | |
113 // The process didn't finish in time, or GetExitCodeProcess failed. | |
114 LOG(ERROR) << cmd_name << " (" << cmd_string | |
erikwright (departed)
2012/09/21 14:08:49
no need for cmd_name here.
grt (UTC plus 2)
2012/09/21 14:20:33
it's not clear to me that the process taking longe
huangs
2012/09/21 18:48:43
Done.
huangs
2012/09/21 18:48:43
As discussed, will wait indefinitely. However, th
| |
115 << ") is taking more than " << kGoogleUpdateTimeoutMs | |
116 << " milliseconds to complete."; | |
117 } | |
118 return success; | |
119 } | |
120 | |
121 } // namespace | |
122 | |
123 bool EnsureUserLevelGoogleUpdateInstalled() { | |
124 LOG(INFO) << "Ensuring Google Update is installed at user level."; | |
125 | |
126 if (IsGoogleUpdateInstalled(false)) { | |
127 LOG(INFO) << "Google Update is already installed."; | |
grt (UTC plus 2)
2012/09/21 14:20:33
i don't think this is needed. the log files get p
huangs
2012/09/21 18:48:43
Done.
| |
128 return true; | |
129 } else { | |
130 string16 cmd_name(L"Google Update installer"); | |
erikwright (departed)
2012/09/21 14:08:49
There's no need to pass around cmd_name. For the p
huangs
2012/09/21 18:48:43
Done.
| |
131 string16 install_cmd( | |
132 GetUserLevelGoogleUpdateInstallCommandLine().GetCommandLineString()); | |
133 base::win::ScopedHandle process; | |
grt (UTC plus 2)
2012/09/21 14:20:33
i think this should check that the command string
huangs
2012/09/21 18:48:43
Added check for empty string upstream.
| |
134 return ExecuteGoogleUpdateCommand(install_cmd, cmd_name, &process) && | |
grt (UTC plus 2)
2012/09/21 14:20:33
please combine these two into one function that do
huangs
2012/09/21 18:48:43
Refactored another way!
| |
135 WaitForGoogleUpdateCommand(install_cmd, cmd_name, process); | |
136 } | |
137 } | |
138 | |
139 bool UninstallGoogleUpdate(bool system_install) { | |
140 string16 cmd_name(L"Google Update uninstaller"); | |
141 string16 uninstall_cmd( | |
142 GoogleUpdateSettings::GetUninstallCommandLine(system_install)); | |
143 if (!uninstall_cmd.empty()) { | |
144 base::win::ScopedHandle process; | |
145 return ExecuteGoogleUpdateCommand(uninstall_cmd, cmd_name, &process) && | |
146 WaitForGoogleUpdateCommand(uninstall_cmd, cmd_name, process); | |
147 } | |
148 return true; | |
149 } | |
150 | |
151 } // namespace google_update | |
OLD | NEW |