OLD | NEW |
| (Empty) |
1 // Copyright 2013 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/setup/cf_migration.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/logging.h" | |
10 #include "base/process/launch.h" | |
11 #include "base/win/registry.h" | |
12 #include "chrome/installer/setup/setup_constants.h" | |
13 #include "chrome/installer/setup/setup_main.h" | |
14 #include "chrome/installer/setup/setup_util.h" | |
15 #include "chrome/installer/util/browser_distribution.h" | |
16 #include "chrome/installer/util/install_util.h" | |
17 #include "chrome/installer/util/installation_state.h" | |
18 #include "chrome/installer/util/installer_state.h" | |
19 #include "chrome/installer/util/master_preferences.h" | |
20 #include "chrome/installer/util/util_constants.h" | |
21 | |
22 namespace installer { | |
23 | |
24 bool LaunchChromeFrameMigrationProcess( | |
25 const ProductState& chrome_frame_product, | |
26 const CommandLine& command_line, | |
27 const base::FilePath& installer_directory, | |
28 bool system_level) { | |
29 // Before running the migration, mutate the CF ap value to include a | |
30 // "-migrate" beacon. This beacon value will be cleaned up by the "ap" | |
31 // cleanup in MigrateGoogleUpdateStateMultiToSingle that calls | |
32 // ChannelInfo::RemoveAllModifiersAndSuffixes(). | |
33 if (chrome_frame_product.is_multi_install()) { | |
34 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
35 base::win::RegKey state_key; | |
36 installer::ChannelInfo channel_info; | |
37 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | |
38 BrowserDistribution::CHROME_FRAME); | |
39 | |
40 LONG result = state_key.Open(root, dist->GetStateKey().c_str(), | |
41 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
42 if (result != ERROR_SUCCESS || !channel_info.Initialize(state_key)) { | |
43 LOG(ERROR) << "Failed to read CF channel to store beacon."; | |
44 } else if (!channel_info.SetMigratingSuffix(true)) { | |
45 LOG(WARNING) << "CF already has migration beacon in channel."; | |
46 } else { | |
47 VLOG(1) << "Writing CF migration beacon to channel: " | |
48 << channel_info.value(); | |
49 channel_info.Write(&state_key); | |
50 } | |
51 } | |
52 | |
53 // Call the installed setup.exe using the current installer command line and | |
54 // adding the migration flags. This seems like it could be unsafe, here's why | |
55 // it's safe today: | |
56 // 1) MigrateChromeFrameInChildProcess is called only during a multi update. | |
57 // 2) Multi update processing occurs after HandleNonInstallCmdLineOptions is | |
58 // called. | |
59 // 3) Setup exits if there were any non-install command line options handled. | |
60 // 4) Thus, the command line being copied will have no non-install command | |
61 // line options at time of copying. | |
62 // 5) kMigrateChromeFrame is a non-install command line option. | |
63 // 6) Thus, it will be handled (and the child setup process will exit) before | |
64 // the child setup process acts on any other flags on the command line. | |
65 // 7) Furthermore, --uncompressed-archive takes precedence over | |
66 // --install-archive, so it is safe to add the former to the command line | |
67 // without removing the latter. | |
68 CommandLine setup_cmd(command_line); | |
69 setup_cmd.SetProgram(installer_directory.Append(installer::kSetupExe)); | |
70 setup_cmd.AppendSwitchPath( | |
71 switches::kUncompressedArchive, | |
72 installer_directory.Append(installer::kChromeArchive)); | |
73 setup_cmd.AppendSwitch(switches::kMigrateChromeFrame); | |
74 | |
75 VLOG(1) << "Running Chrome Frame migration process with command line: " | |
76 << setup_cmd.GetCommandLineString(); | |
77 | |
78 base::LaunchOptions options; | |
79 options.force_breakaway_from_job_ = true; | |
80 if (!base::LaunchProcess(setup_cmd, options, NULL)) { | |
81 PLOG(ERROR) << "Launching Chrome Frame migration process failed. " | |
82 << "(Command line: " << setup_cmd.GetCommandLineString() << ")"; | |
83 return false; | |
84 } | |
85 | |
86 return true; | |
87 } | |
88 | |
89 InstallStatus MigrateChromeFrame(const InstallationState& original_state, | |
90 InstallerState* installer_state) { | |
91 const bool system_level = installer_state->system_install(); | |
92 | |
93 // Nothing to do if multi-install Chrome Frame is not installed. | |
94 const ProductState* multi_chrome_frame = original_state.GetProductState( | |
95 system_level, BrowserDistribution::CHROME_FRAME); | |
96 if (!multi_chrome_frame || !multi_chrome_frame->is_multi_install()) | |
97 return INVALID_STATE_FOR_OPTION; | |
98 | |
99 // Install SxS Chrome Frame. | |
100 InstallerState install_gcf(installer_state->level()); | |
101 { | |
102 scoped_ptr<Product> chrome_frame( | |
103 new Product(BrowserDistribution::GetSpecificDistribution( | |
104 BrowserDistribution::CHROME_FRAME))); | |
105 install_gcf.AddProduct(&chrome_frame); | |
106 } | |
107 DCHECK(!install_gcf.is_multi_install()); | |
108 | |
109 ArchiveType archive_type = UNKNOWN_ARCHIVE_TYPE; | |
110 bool delegated_to_existing = false; | |
111 InstallStatus install_status = InstallProductsHelper( | |
112 original_state, *CommandLine::ForCurrentProcess(), | |
113 MasterPreferences::ForCurrentProcess(), install_gcf, | |
114 NULL, &archive_type, &delegated_to_existing); | |
115 | |
116 if (!InstallUtil::GetInstallReturnCode(install_status)) { | |
117 // Migration was successful. There's no turning back now. The multi-install | |
118 // npchrome_frame.dll and/or chrome.exe may still be in use at this point, | |
119 // although the user-level helper will not be. It is not safe to delete the | |
120 // multi-install binaries until npchrome_frame.dll and chrome.exe are no | |
121 // longer in use. The remaining tasks here are best-effort. Failure does not | |
122 // do any harm. | |
123 MigrateGoogleUpdateStateMultiToSingle(system_level, | |
124 BrowserDistribution::CHROME_FRAME, | |
125 original_state); | |
126 } | |
127 | |
128 return install_status; | |
129 } | |
130 | |
131 } // namespace installer | |
OLD | NEW |