OLD | NEW |
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/util/installer_state.h" | 5 #include "chrome/installer/util/installer_state.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/file_version_info.h" | 13 #include "base/file_version_info.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/win/registry.h" | 18 #include "base/win/registry.h" |
19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
20 #include "chrome/installer/util/delete_tree_work_item.h" | 20 #include "chrome/installer/util/delete_tree_work_item.h" |
21 #include "chrome/installer/util/helper.h" | 21 #include "chrome/installer/util/helper.h" |
22 #include "chrome/installer/util/install_util.h" | 22 #include "chrome/installer/util/install_util.h" |
23 #include "chrome/installer/util/installation_state.h" | 23 #include "chrome/installer/util/installation_state.h" |
24 #include "chrome/installer/util/master_preferences.h" | 24 #include "chrome/installer/util/master_preferences.h" |
25 #include "chrome/installer/util/master_preferences_constants.h" | 25 #include "chrome/installer/util/master_preferences_constants.h" |
26 #include "chrome/installer/util/product.h" | 26 #include "chrome/installer/util/product.h" |
| 27 #include "chrome/installer/util/util_constants.h" |
27 #include "chrome/installer/util/work_item.h" | 28 #include "chrome/installer/util/work_item.h" |
28 #include "chrome/installer/util/work_item_list.h" | 29 #include "chrome/installer/util/work_item_list.h" |
29 | 30 |
30 namespace installer { | 31 namespace installer { |
31 | 32 |
32 bool InstallerState::IsMultiInstallUpdate(const MasterPreferences& prefs, | 33 bool InstallerState::IsMultiInstallUpdate(const MasterPreferences& prefs, |
33 const InstallationState& machine_state) { | 34 const InstallationState& machine_state) { |
34 // First, is the package present? | 35 // First, is the package present? |
35 const ProductState* package = | 36 const ProductState* package = |
36 machine_state.GetProductState(level_ == SYSTEM_LEVEL, | 37 machine_state.GetProductState(level_ == SYSTEM_LEVEL, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 72 |
72 InstallerState::InstallerState() | 73 InstallerState::InstallerState() |
73 : operation_(UNINITIALIZED), | 74 : operation_(UNINITIALIZED), |
74 multi_package_distribution_(NULL), | 75 multi_package_distribution_(NULL), |
75 level_(UNKNOWN_LEVEL), | 76 level_(UNKNOWN_LEVEL), |
76 package_type_(UNKNOWN_PACKAGE_TYPE), | 77 package_type_(UNKNOWN_PACKAGE_TYPE), |
77 state_type_(BrowserDistribution::CHROME_BROWSER), | 78 state_type_(BrowserDistribution::CHROME_BROWSER), |
78 root_key_(NULL), | 79 root_key_(NULL), |
79 msi_(false), | 80 msi_(false), |
80 verbose_logging_(false), | 81 verbose_logging_(false), |
81 ensure_google_update_present_(false) { | 82 ensure_google_update_present_(false), |
| 83 need_to_migrate_legacy_app_launcher_(false), |
| 84 create_app_launcher_shortcuts_(false) { |
82 } | 85 } |
83 | 86 |
84 InstallerState::InstallerState(Level level) | 87 InstallerState::InstallerState(Level level) |
85 : operation_(UNINITIALIZED), | 88 : operation_(UNINITIALIZED), |
86 multi_package_distribution_(NULL), | 89 multi_package_distribution_(NULL), |
87 level_(UNKNOWN_LEVEL), | 90 level_(UNKNOWN_LEVEL), |
88 package_type_(UNKNOWN_PACKAGE_TYPE), | 91 package_type_(UNKNOWN_PACKAGE_TYPE), |
89 state_type_(BrowserDistribution::CHROME_BROWSER), | 92 state_type_(BrowserDistribution::CHROME_BROWSER), |
90 root_key_(NULL), | 93 root_key_(NULL), |
91 msi_(false), | 94 msi_(false), |
92 verbose_logging_(false), | 95 verbose_logging_(false), |
93 ensure_google_update_present_(false) { | 96 ensure_google_update_present_(false), |
| 97 need_to_migrate_legacy_app_launcher_(false), |
| 98 create_app_launcher_shortcuts_(false) { |
94 // Use set_level() so that root_key_ is updated properly. | 99 // Use set_level() so that root_key_ is updated properly. |
95 set_level(level); | 100 set_level(level); |
96 } | 101 } |
97 | 102 |
98 void InstallerState::Initialize(const CommandLine& command_line, | 103 void InstallerState::Initialize(const CommandLine& command_line, |
99 const MasterPreferences& prefs, | 104 const MasterPreferences& prefs, |
100 const InstallationState& machine_state) { | 105 const InstallationState& machine_state) { |
101 bool pref_bool; | 106 bool pref_bool; |
102 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) | 107 if (!prefs.GetBool(master_preferences::kSystemLevel, &pref_bool)) |
103 pref_bool = false; | 108 pref_bool = false; |
104 set_level(pref_bool ? SYSTEM_LEVEL : USER_LEVEL); | 109 set_level(pref_bool ? SYSTEM_LEVEL : USER_LEVEL); |
105 | 110 |
106 if (!prefs.GetBool(master_preferences::kVerboseLogging, &verbose_logging_)) | 111 if (!prefs.GetBool(master_preferences::kVerboseLogging, &verbose_logging_)) |
107 verbose_logging_ = false; | 112 verbose_logging_ = false; |
108 | 113 |
109 if (!prefs.GetBool(master_preferences::kMultiInstall, &pref_bool)) | 114 if (!prefs.GetBool(master_preferences::kMultiInstall, &pref_bool)) |
110 pref_bool = false; | 115 pref_bool = false; |
111 set_package_type(pref_bool ? MULTI_PACKAGE : SINGLE_PACKAGE); | 116 set_package_type(pref_bool ? MULTI_PACKAGE : SINGLE_PACKAGE); |
112 | 117 |
113 if (!prefs.GetBool(master_preferences::kMsi, &msi_)) | 118 if (!prefs.GetBool(master_preferences::kMsi, &msi_)) |
114 msi_ = false; | 119 msi_ = false; |
115 | 120 |
116 ensure_google_update_present_ = | 121 ensure_google_update_present_ = |
117 command_line.HasSwitch(installer::switches::kEnsureGoogleUpdatePresent); | 122 command_line.HasSwitch(installer::switches::kEnsureGoogleUpdatePresent); |
118 | 123 |
119 const bool is_uninstall = command_line.HasSwitch(switches::kUninstall); | 124 const bool is_uninstall = command_line.HasSwitch(switches::kUninstall); |
120 | 125 |
121 if (prefs.install_chrome()) { | 126 // TODO(huangs): Remove by M30. |
122 Product* p = AddProductFromPreferences( | 127 if (!is_uninstall && !system_install() && prefs.is_multi_install()) { |
| 128 // Check the version of App Launcher ClientState to determine if legacy. |
| 129 const ProductState* app_launcher_state = machine_state.GetProductState( |
| 130 false, BrowserDistribution::CHROME_APP_HOST); |
| 131 if (app_launcher_state) { |
| 132 need_to_migrate_legacy_app_launcher_ = |
| 133 app_launcher_state->version().IsOlderThan("29.0.1508.0"); |
| 134 } |
| 135 } |
| 136 |
| 137 // App Launcher and Chrome are unified. |
| 138 if (prefs.install_chrome() || prefs.install_chrome_app_launcher() || |
| 139 need_to_migrate_legacy_app_launcher_) { |
| 140 Product* p1 = AddProductFromPreferences( |
123 BrowserDistribution::CHROME_BROWSER, prefs, machine_state); | 141 BrowserDistribution::CHROME_BROWSER, prefs, machine_state); |
124 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") | 142 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") |
125 << " distribution: " << p->distribution()->GetAppShortCutName(); | 143 << " distribution: " << p1->distribution()->GetAppShortCutName(); |
| 144 |
| 145 if (is_multi_install()) { |
| 146 Product* p2 = AddProductFromPreferences( |
| 147 BrowserDistribution::CHROME_APP_HOST, prefs, machine_state); |
| 148 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") |
| 149 << " distribution: " << p2->distribution()->GetAppShortCutName(); |
| 150 } |
126 } | 151 } |
| 152 // TODO(huangs): Remove by M30. |
| 153 // Create App Launcher shortcuts if --app-launcher is specified. |
| 154 create_app_launcher_shortcuts_ = need_to_migrate_legacy_app_launcher_ || |
| 155 prefs.install_chrome_app_launcher(); |
| 156 |
127 if (prefs.install_chrome_frame()) { | 157 if (prefs.install_chrome_frame()) { |
128 Product* p = AddProductFromPreferences( | 158 Product* p = AddProductFromPreferences( |
129 BrowserDistribution::CHROME_FRAME, prefs, machine_state); | 159 BrowserDistribution::CHROME_FRAME, prefs, machine_state); |
130 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") | 160 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") |
131 << " distribution: " << p->distribution()->GetAppShortCutName(); | 161 << " distribution: " << p->distribution()->GetAppShortCutName(); |
132 } | 162 } |
133 | 163 |
134 if (prefs.install_chrome_app_launcher()) { | 164 if (!is_uninstall && is_multi_install() && |
| 165 !FindProduct(BrowserDistribution::CHROME_BINARIES) && |
| 166 (FindProduct(BrowserDistribution::CHROME_BROWSER) || |
| 167 FindProduct(BrowserDistribution::CHROME_FRAME) || |
| 168 FindProduct(BrowserDistribution::CHROME_APP_HOST))) { |
| 169 // Force binaries to be installed/updated. |
135 Product* p = AddProductFromPreferences( | 170 Product* p = AddProductFromPreferences( |
136 BrowserDistribution::CHROME_APP_HOST, prefs, machine_state); | 171 BrowserDistribution::CHROME_BINARIES, prefs, machine_state); |
137 VLOG(1) << (is_uninstall ? "Uninstall" : "Install") | 172 VLOG(1) << "Install distribution: " |
138 << " distribution: " << p->distribution()->GetAppShortCutName(); | 173 << p->distribution()->GetAppShortCutName(); |
139 } | |
140 | |
141 if (!is_uninstall && is_multi_install()) { | |
142 bool need_binaries = false; | |
143 if (FindProduct(BrowserDistribution::CHROME_APP_HOST)) { | |
144 // App Host will happily use Chrome at system level, or binaries at system | |
145 // level, even if app host is user level. | |
146 const ProductState* chrome_state = machine_state.GetProductState( | |
147 true, // system level | |
148 BrowserDistribution::CHROME_BROWSER); | |
149 // If Chrome is at system-level, multi- or otherwise. We'll use it. | |
150 if (!chrome_state) { | |
151 const ProductState* binaries_state = machine_state.GetProductState( | |
152 true, // system level | |
153 BrowserDistribution::CHROME_BINARIES); | |
154 if (!binaries_state) | |
155 need_binaries = true; | |
156 } | |
157 } | |
158 | |
159 // Chrome/Chrome Frame multi need Binaries at their own level. | |
160 if (FindProduct(BrowserDistribution::CHROME_BROWSER)) | |
161 need_binaries = true; | |
162 | |
163 if (FindProduct(BrowserDistribution::CHROME_FRAME)) | |
164 need_binaries = true; | |
165 | |
166 if (need_binaries && !FindProduct(BrowserDistribution::CHROME_BINARIES)) { | |
167 // Force binaries to be installed/updated. | |
168 Product* p = AddProductFromPreferences( | |
169 BrowserDistribution::CHROME_BINARIES, prefs, machine_state); | |
170 VLOG(1) << "Install distribution: " | |
171 << p->distribution()->GetAppShortCutName(); | |
172 } | |
173 } | 174 } |
174 | 175 |
175 if (is_uninstall && prefs.is_multi_install()) { | 176 if (is_uninstall && prefs.is_multi_install()) { |
176 if (FindProduct(BrowserDistribution::CHROME_BROWSER)) { | 177 if (FindProduct(BrowserDistribution::CHROME_BROWSER)) { |
177 // Uninstall each product of type |type| listed below based on the | 178 // Uninstall each product of type |type| listed below based on the |
178 // presence or absence of |switch_name| in that product's uninstall | 179 // presence or absence of |switch_name| in that product's uninstall |
179 // command. | 180 // command. |
180 const struct { | 181 const struct { |
181 BrowserDistribution::Type type; | 182 BrowserDistribution::Type type; |
182 const char* switch_name; | 183 const char* switch_name; |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 } | 791 } |
791 if (!install_list->Do()) | 792 if (!install_list->Do()) |
792 LOG(ERROR) << "Failed to record installer error information in registry."; | 793 LOG(ERROR) << "Failed to record installer error information in registry."; |
793 } | 794 } |
794 | 795 |
795 bool InstallerState::RequiresActiveSetup() const { | 796 bool InstallerState::RequiresActiveSetup() const { |
796 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); | 797 return system_install() && FindProduct(BrowserDistribution::CHROME_BROWSER); |
797 } | 798 } |
798 | 799 |
799 } // namespace installer | 800 } // namespace installer |
OLD | NEW |