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

Side by Side Diff: chrome/browser/first_run/upgrade_util_win.cc

Issue 7353030: Cause new_chrome.exe to always be written if Chrome Frame is in use, resulting in updates being d... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/installer/setup/install_worker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/first_run/upgrade_util.h" 5 #include "chrome/browser/first_run/upgrade_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/process_util.h" 17 #include "base/process_util.h"
18 #include "base/string_util.h"
18 #include "base/win/registry.h" 19 #include "base/win/registry.h"
19 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
20 #include "chrome/browser/first_run/upgrade_util_win.h" 21 #include "chrome/browser/first_run/upgrade_util_win.h"
21 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/chrome_switches.h"
22 #include "chrome/installer/util/browser_distribution.h" 24 #include "chrome/installer/util/browser_distribution.h"
23 #include "chrome/installer/util/google_update_constants.h" 25 #include "chrome/installer/util/google_update_constants.h"
24 #include "chrome/installer/util/install_util.h" 26 #include "chrome/installer/util/install_util.h"
25 #include "chrome/installer/util/shell_util.h" 27 #include "chrome/installer/util/shell_util.h"
26 #include "chrome/installer/util/util_constants.h" 28 #include "chrome/installer/util/util_constants.h"
27 #include "google_update_idl.h" 29 #include "google_update_idl.h"
28 30
29 namespace { 31 namespace {
30 32
31 bool GetNewerChromeFile(FilePath* path) { 33 bool GetNewerChromeFile(FilePath* path) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 bool SwapNewChromeExeIfPresent() { 80 bool SwapNewChromeExeIfPresent() {
79 FilePath new_chrome_exe; 81 FilePath new_chrome_exe;
80 if (!GetNewerChromeFile(&new_chrome_exe)) 82 if (!GetNewerChromeFile(&new_chrome_exe))
81 return false; 83 return false;
82 if (!file_util::PathExists(new_chrome_exe)) 84 if (!file_util::PathExists(new_chrome_exe))
83 return false; 85 return false;
84 FilePath cur_chrome_exe; 86 FilePath cur_chrome_exe;
85 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) 87 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe))
86 return false; 88 return false;
87 89
88 // First try to rename exe by launching rename command ourselves. 90 // Open up the registry key containing current version and rename information.
89 bool user_install = 91 bool user_install =
90 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str()); 92 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str());
91 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 93 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
92 BrowserDistribution *dist = BrowserDistribution::GetDistribution(); 94 BrowserDistribution *dist = BrowserDistribution::GetDistribution();
93 base::win::RegKey key; 95 base::win::RegKey key;
94 std::wstring rename_cmd; 96 if (key.Open(reg_root, dist->GetVersionKey().c_str(),
95 if ((key.Open(reg_root, dist->GetVersionKey().c_str(), 97 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
96 KEY_READ) == ERROR_SUCCESS) && 98
97 (key.ReadValue(google_update::kRegRenameCmdField, 99 // Having just ascertained that we can swap, now check that we should: if
98 &rename_cmd) == ERROR_SUCCESS)) { 100 // we are given an explicit --chrome-version flag, don't rename unless the
99 base::ProcessHandle handle; 101 // specified version matches the "pv" value. In practice, this is used to
100 if (base::LaunchApp(rename_cmd, true, true, &handle)) { 102 // defer Chrome Frame updates until the current version of the Chrome Frame
101 DWORD exit_code; 103 // DLL component is loaded.
102 ::GetExitCodeProcess(handle, &exit_code); 104 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
103 ::CloseHandle(handle); 105 if (cmd_line.HasSwitch(switches::kChromeVersion)) {
104 if (exit_code == installer::RENAME_SUCCESSFUL) 106 std::string version_string =
105 return true; 107 cmd_line.GetSwitchValueASCII(switches::kChromeVersion);
108 scoped_ptr<Version> cmd_version(
109 Version::GetVersionFromString(version_string));
110
111 std::wstring pv_value;
112 if (key.ReadValue(google_update::kRegVersionField,
113 &pv_value) == ERROR_SUCCESS) {
114 scoped_ptr<Version> pv_version(
115 Version::GetVersionFromString(WideToASCII(pv_value)));
116 if (cmd_version.get() && pv_version.get() &&
117 !cmd_version->Equals(*pv_version.get())) {
118 return false;
119 }
120 }
121 }
122
123 // First try to rename exe by launching rename command ourselves.
124 std::wstring rename_cmd;
125 if (key.ReadValue(google_update::kRegRenameCmdField,
126 &rename_cmd) == ERROR_SUCCESS) {
127 base::ProcessHandle handle;
128 if (base::LaunchApp(rename_cmd, true, true, &handle)) {
129 DWORD exit_code;
130 ::GetExitCodeProcess(handle, &exit_code);
131 ::CloseHandle(handle);
132 if (exit_code == installer::RENAME_SUCCESSFUL)
133 return true;
134 }
106 } 135 }
107 } 136 }
108 137
109 // Rename didn't work so try to rename by calling Google Update 138 // Rename didn't work so try to rename by calling Google Update
110 return InvokeGoogleUpdateForRename(); 139 return InvokeGoogleUpdateForRename();
111 } 140 }
112 141
113 bool DoUpgradeTasks(const CommandLine& command_line) { 142 bool DoUpgradeTasks(const CommandLine& command_line) {
114 if (!SwapNewChromeExeIfPresent()) 143 if (!SwapNewChromeExeIfPresent())
115 return false; 144 return false;
116 // At this point the chrome.exe has been swapped with the new one. 145 // At this point the chrome.exe has been swapped with the new one.
117 if (!RelaunchChromeBrowser(command_line)) { 146 if (!RelaunchChromeBrowser(command_line)) {
118 // The re-launch fails. Feel free to panic now. 147 // The re-launch fails. Feel free to panic now.
119 NOTREACHED(); 148 NOTREACHED();
120 } 149 }
121 return true; 150 return true;
122 } 151 }
123 152
124 } // namespace upgrade_util 153 } // namespace upgrade_util
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/setup/install_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698