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

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

Issue 6288009: More installer refactoring in the interest of fixing some bugs and cleaning t... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
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/first_run.h" 5 #include "chrome/browser/first_run/first_run.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 10
11 #include <set> 11 #include <set>
12 #include <sstream> 12 #include <sstream>
13 13
14 #include "app/app_switches.h" 14 #include "app/app_switches.h"
15 #include "app/l10n_util.h" 15 #include "app/l10n_util.h"
16 #include "app/resource_bundle.h" 16 #include "app/resource_bundle.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/scoped_comptr_win.h" 20 #include "base/scoped_comptr_win.h"
21 #include "base/scoped_ptr.h" 21 #include "base/scoped_ptr.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/string_split.h" 23 #include "base/string_split.h"
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #include "base/win/object_watcher.h" 25 #include "base/win/object_watcher.h"
26 #include "base/win/registry.h"
27 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
28 #include "chrome/browser/extensions/extension_service.h" 27 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_updater.h" 28 #include "chrome/browser/extensions/extension_updater.h"
30 #include "chrome/browser/importer/importer.h" 29 #include "chrome/browser/importer/importer.h"
31 #include "chrome/browser/metrics/user_metrics.h" 30 #include "chrome/browser/metrics/user_metrics.h"
32 #include "chrome/browser/process_singleton.h" 31 #include "chrome/browser/process_singleton.h"
33 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/search_engines/template_url_model.h" 33 #include "chrome/browser/search_engines/template_url_model.h"
35 #include "chrome/browser/ui/views/first_run_search_engine_view.h" 34 #include "chrome/browser/ui/views/first_run_search_engine_view.h"
36 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/notification_service.h" 37 #include "chrome/common/notification_service.h"
39 #include "chrome/common/worker_thread_ticker.h" 38 #include "chrome/common/worker_thread_ticker.h"
40 #include "chrome/installer/util/browser_distribution.h" 39 #include "chrome/installer/util/browser_distribution.h"
41 #include "chrome/installer/util/google_update_constants.h" 40 #include "chrome/installer/util/google_update_constants.h"
42 #include "chrome/installer/util/google_update_settings.h" 41 #include "chrome/installer/util/google_update_settings.h"
42 #include "chrome/installer/util/helper.h"
43 #include "chrome/installer/util/install_util.h" 43 #include "chrome/installer/util/install_util.h"
44 #include "chrome/installer/util/installation_state.h"
44 #include "chrome/installer/util/shell_util.h" 45 #include "chrome/installer/util/shell_util.h"
45 #include "chrome/installer/util/util_constants.h" 46 #include "chrome/installer/util/util_constants.h"
46 #include "google_update_idl.h" 47 #include "google_update_idl.h"
47 #include "grit/chromium_strings.h" 48 #include "grit/chromium_strings.h"
48 #include "grit/generated_resources.h" 49 #include "grit/generated_resources.h"
49 #include "grit/locale_settings.h" 50 #include "grit/locale_settings.h"
50 #include "grit/theme_resources.h" 51 #include "grit/theme_resources.h"
51 #include "views/controls/button/image_button.h" 52 #include "views/controls/button/image_button.h"
52 #include "views/controls/button/radio_button.h" 53 #include "views/controls/button/radio_button.h"
53 #include "views/controls/image_view.h" 54 #include "views/controls/image_view.h"
54 #include "views/controls/link.h" 55 #include "views/controls/link.h"
55 #include "views/focus/accelerator_handler.h" 56 #include "views/focus/accelerator_handler.h"
56 #include "views/grid_layout.h" 57 #include "views/grid_layout.h"
57 #include "views/standard_layout.h" 58 #include "views/standard_layout.h"
58 #include "views/widget/root_view.h" 59 #include "views/widget/root_view.h"
59 #include "views/widget/widget_win.h" 60 #include "views/widget/widget_win.h"
60 #include "views/window/window.h" 61 #include "views/window/window.h"
61 62
62 namespace { 63 namespace {
63 64
64 bool GetNewerChromeFile(FilePath* path) { 65 bool GetNewerChromeFile(FilePath* path) {
65 if (!PathService::Get(base::DIR_EXE, path)) 66 if (!PathService::Get(base::DIR_EXE, path))
66 return false; 67 return false;
67 *path = path->Append(installer::kChromeNewExe); 68 *path = path->Append(installer::kChromeNewExe);
68 return true; 69 return true;
69 } 70 }
70 71
71 bool InvokeGoogleUpdateForRename() { 72 bool InvokeGoogleUpdateForRename(const std::wstring& app_guid) {
72 ScopedComPtr<IProcessLauncher> ipl; 73 ScopedComPtr<IProcessLauncher> ipl;
73 if (!FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass)))) { 74 if (!FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass)))) {
74 ULONG_PTR phandle = NULL; 75 ULONG_PTR phandle = NULL;
75 DWORD id = GetCurrentProcessId(); 76 DWORD id = GetCurrentProcessId();
76 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 77 if (!FAILED(ipl->LaunchCmdElevated(app_guid.c_str(),
77 if (!FAILED(ipl->LaunchCmdElevated(dist->GetAppGuid().c_str(),
78 google_update::kRegRenameCmdField, 78 google_update::kRegRenameCmdField,
79 id, &phandle))) { 79 id, &phandle))) {
80 HANDLE handle = HANDLE(phandle); 80 HANDLE handle = HANDLE(phandle);
81 WaitForSingleObject(handle, INFINITE); 81 WaitForSingleObject(handle, INFINITE);
82 DWORD exit_code; 82 DWORD exit_code;
83 ::GetExitCodeProcess(handle, &exit_code); 83 ::GetExitCodeProcess(handle, &exit_code);
84 ::CloseHandle(handle); 84 ::CloseHandle(handle);
85 if (exit_code == installer::RENAME_SUCCESSFUL) 85 if (exit_code == installer::RENAME_SUCCESSFUL)
86 return true; 86 return true;
87 } 87 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 return base::LaunchApp(command_line.command_line_string(), 260 return base::LaunchApp(command_line.command_line_string(),
261 false, false, NULL); 261 false, false, NULL);
262 } 262 }
263 263
264 bool Upgrade::SwapNewChromeExeIfPresent() { 264 bool Upgrade::SwapNewChromeExeIfPresent() {
265 FilePath new_chrome_exe; 265 FilePath new_chrome_exe;
266 if (!GetNewerChromeFile(&new_chrome_exe)) 266 if (!GetNewerChromeFile(&new_chrome_exe))
267 return false; 267 return false;
268 if (!file_util::PathExists(new_chrome_exe)) 268 if (!file_util::PathExists(new_chrome_exe))
269 return false; 269 return false;
270 FilePath cur_chrome_exe; 270 std::wstring app_guid;
271 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) 271 std::wstring rename_cmd = installer::GetRenameCommand(&app_guid);
tommi (sloooow) - chröme 2011/01/21 21:45:17 general style nit: We prefer std::string foo(Bar()
272 return false;
273 272
274 // First try to rename exe by launching rename command ourselves. 273 if (!rename_cmd.empty()) {
275 bool user_install =
276 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str());
277 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
278 BrowserDistribution *dist = BrowserDistribution::GetDistribution();
279 base::win::RegKey key;
280 std::wstring rename_cmd;
281 if ((key.Open(reg_root, dist->GetVersionKey().c_str(),
282 KEY_READ) == ERROR_SUCCESS) &&
283 (key.ReadValue(google_update::kRegRenameCmdField,
284 &rename_cmd) == ERROR_SUCCESS)) {
285 base::ProcessHandle handle; 274 base::ProcessHandle handle;
286 if (base::LaunchApp(rename_cmd, true, true, &handle)) { 275 if (base::LaunchApp(rename_cmd, true, true, &handle)) {
287 DWORD exit_code; 276 DWORD exit_code;
288 ::GetExitCodeProcess(handle, &exit_code); 277 ::GetExitCodeProcess(handle, &exit_code);
289 ::CloseHandle(handle); 278 ::CloseHandle(handle);
290 if (exit_code == installer::RENAME_SUCCESSFUL) 279 if (exit_code == installer::RENAME_SUCCESSFUL)
291 return true; 280 return true;
292 } 281 }
282 } else {
283 NOTREACHED() << "Empty command string found to rename new chrome.";
293 } 284 }
294 285
295 // Rename didn't work so try to rename by calling Google Update 286 // Rename didn't work so try to rename by calling Google Update
296 return InvokeGoogleUpdateForRename(); 287 return InvokeGoogleUpdateForRename(app_guid);
297 } 288 }
298 289
299 // static 290 // static
300 bool Upgrade::DoUpgradeTasks(const CommandLine& command_line) { 291 bool Upgrade::DoUpgradeTasks(const CommandLine& command_line) {
301 if (!Upgrade::SwapNewChromeExeIfPresent()) 292 if (!Upgrade::SwapNewChromeExeIfPresent())
302 return false; 293 return false;
303 // At this point the chrome.exe has been swapped with the new one. 294 // At this point the chrome.exe has been swapped with the new one.
304 if (!Upgrade::RelaunchChromeBrowser(command_line)) { 295 if (!Upgrade::RelaunchChromeBrowser(command_line)) {
305 // The re-launch fails. Feel free to panic now. 296 // The re-launch fails. Feel free to panic now.
306 NOTREACHED(); 297 NOTREACHED();
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 847
857 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { 848 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) {
858 if (version > 10000) { 849 if (version > 10000) {
859 // This is a test value. We want to make sure we exercise 850 // This is a test value. We want to make sure we exercise
860 // returning this early. See EarlyReturnTest test harness. 851 // returning this early. See EarlyReturnTest test harness.
861 return Upgrade::TD_NOT_NOW; 852 return Upgrade::TD_NOT_NOW;
862 } 853 }
863 TryChromeDialog td(version); 854 TryChromeDialog td(version);
864 return td.ShowModal(); 855 return td.ShowModal();
865 } 856 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_installer.gypi » ('j') | chrome/installer/setup/chrome_frame_ready_mode.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698