| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/product.h" | 5 #include "chrome/installer/util/product.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/win/registry.h" | 11 #include "base/win/registry.h" |
| 12 #include "chrome/installer/util/google_update_constants.h" | 12 #include "chrome/installer/util/google_update_constants.h" |
| 13 #include "chrome/installer/util/helper.h" | 13 #include "chrome/installer/util/helper.h" |
| 14 #include "chrome/installer/util/install_util.h" | 14 #include "chrome/installer/util/install_util.h" |
| 15 #include "chrome/installer/util/l10n_string_util.h" | 15 #include "chrome/installer/util/l10n_string_util.h" |
| 16 #include "chrome/installer/util/master_preferences.h" | 16 #include "chrome/installer/util/master_preferences.h" |
| 17 #include "chrome/installer/util/master_preferences_constants.h" | 17 #include "chrome/installer/util/master_preferences_constants.h" |
| 18 #include "chrome/installer/util/package.h" | 18 #include "chrome/installer/util/package.h" |
| 19 #include "chrome/installer/util/work_item_list.h" | 19 #include "chrome/installer/util/work_item_list.h" |
| 20 | 20 |
| 21 using base::win::RegKey; | 21 using base::win::RegKey; |
| 22 using installer_util::MasterPreferences; | 22 using installer::MasterPreferences; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 class ProductIsOfType { | 25 class ProductIsOfType { |
| 26 public: | 26 public: |
| 27 explicit ProductIsOfType(BrowserDistribution::Type type) | 27 explicit ProductIsOfType(BrowserDistribution::Type type) |
| 28 : type_(type) { } | 28 : type_(type) { } |
| 29 bool operator()( | 29 bool operator()( |
| 30 const scoped_refptr<const installer::Product>& pi) const { | 30 const scoped_refptr<const installer::Product>& pi) const { |
| 31 return pi->distribution()->GetType() == type_; | 31 return pi->distribution()->GetType() == type_; |
| 32 } | 32 } |
| 33 private: | 33 private: |
| 34 BrowserDistribution::Type type_; | 34 BrowserDistribution::Type type_; |
| 35 }; // class ProductIsOfType | 35 }; // class ProductIsOfType |
| 36 } // end namespace | 36 } // end namespace |
| 37 | 37 |
| 38 namespace installer { | 38 namespace installer { |
| 39 | 39 |
| 40 const Product* FindProduct(const Products& products, | 40 const Product* FindProduct(const Products& products, |
| 41 BrowserDistribution::Type type) { | 41 BrowserDistribution::Type type) { |
| 42 Products::const_iterator i = | 42 Products::const_iterator i = |
| 43 std::find_if(products.begin(), products.end(), ProductIsOfType(type)); | 43 std::find_if(products.begin(), products.end(), ProductIsOfType(type)); |
| 44 return i == products.end() ? NULL : *i; | 44 return i == products.end() ? NULL : *i; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void WriteInstallerResult(const Products& products, | 47 void WriteInstallerResult(const Products& products, |
| 48 installer_util::InstallStatus status, | 48 installer::InstallStatus status, |
| 49 int string_resource_id, | 49 int string_resource_id, |
| 50 const std::wstring* const launch_cmd) { | 50 const std::wstring* const launch_cmd) { |
| 51 Products::const_iterator end = products.end(); | 51 Products::const_iterator end = products.end(); |
| 52 for (Products::const_iterator i = products.begin(); i != end; ++i) | 52 for (Products::const_iterator i = products.begin(); i != end; ++i) |
| 53 (*i)->WriteInstallerResult(status, string_resource_id, launch_cmd); | 53 (*i)->WriteInstallerResult(status, string_resource_id, launch_cmd); |
| 54 } | 54 } |
| 55 | 55 |
| 56 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 57 | 57 |
| 58 Product::Product(BrowserDistribution* distribution, bool system_level, | 58 Product::Product(BrowserDistribution* distribution, bool system_level, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 FilePath Product::GetUserDataPath() const { | 71 FilePath Product::GetUserDataPath() const { |
| 72 return GetChromeUserDataPath(distribution_); | 72 return GetChromeUserDataPath(distribution_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool Product::LaunchChrome() const { | 75 bool Product::LaunchChrome() const { |
| 76 const FilePath& install_package = package_->path(); | 76 const FilePath& install_package = package_->path(); |
| 77 bool success = !install_package.empty(); | 77 bool success = !install_package.empty(); |
| 78 if (success) { | 78 if (success) { |
| 79 CommandLine cmd(install_package.Append(installer_util::kChromeExe)); | 79 CommandLine cmd(install_package.Append(installer::kChromeExe)); |
| 80 success = base::LaunchApp(cmd, false, false, NULL); | 80 success = base::LaunchApp(cmd, false, false, NULL); |
| 81 } | 81 } |
| 82 return success; | 82 return success; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool Product::LaunchChromeAndWait(const CommandLine& options, | 85 bool Product::LaunchChromeAndWait(const CommandLine& options, |
| 86 int32* exit_code) const { | 86 int32* exit_code) const { |
| 87 const FilePath& install_package = package_->path(); | 87 const FilePath& install_package = package_->path(); |
| 88 if (install_package.empty()) | 88 if (install_package.empty()) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 CommandLine cmd(install_package.Append(installer_util::kChromeExe)); | 91 CommandLine cmd(install_package.Append(installer::kChromeExe)); |
| 92 cmd.AppendArguments(options, false); | 92 cmd.AppendArguments(options, false); |
| 93 | 93 |
| 94 bool success = false; | 94 bool success = false; |
| 95 STARTUPINFOW si = { sizeof(si) }; | 95 STARTUPINFOW si = { sizeof(si) }; |
| 96 PROCESS_INFORMATION pi = {0}; | 96 PROCESS_INFORMATION pi = {0}; |
| 97 // Cast away constness of the command_line_string() since CreateProcess | 97 // Cast away constness of the command_line_string() since CreateProcess |
| 98 // might modify the string (insert \0 to separate the program from the | 98 // might modify the string (insert \0 to separate the program from the |
| 99 // arguments). Since we're not using the cmd variable beyond this point | 99 // arguments). Since we're not using the cmd variable beyond this point |
| 100 // we don't care. | 100 // we don't care. |
| 101 if (!::CreateProcess(cmd.GetProgram().value().c_str(), | 101 if (!::CreateProcess(cmd.GetProgram().value().c_str(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 return success; | 124 return success; |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool Product::IsMsi() const { | 127 bool Product::IsMsi() const { |
| 128 if (msi_ == MSI_NOT_CHECKED) { | 128 if (msi_ == MSI_NOT_CHECKED) { |
| 129 msi_ = NOT_MSI; // Covers failure cases below. | 129 msi_ = NOT_MSI; // Covers failure cases below. |
| 130 | 130 |
| 131 const MasterPreferences& prefs = | 131 const MasterPreferences& prefs = |
| 132 installer_util::MasterPreferences::ForCurrentProcess(); | 132 installer::MasterPreferences::ForCurrentProcess(); |
| 133 | 133 |
| 134 bool is_msi = false; | 134 bool is_msi = false; |
| 135 prefs.GetBool(installer_util::master_preferences::kMsi, &is_msi); | 135 prefs.GetBool(installer::master_preferences::kMsi, &is_msi); |
| 136 | 136 |
| 137 if (!is_msi) { | 137 if (!is_msi) { |
| 138 // We didn't find it in the preferences, try looking in the registry. | 138 // We didn't find it in the preferences, try looking in the registry. |
| 139 HKEY reg_root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 139 HKEY reg_root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 140 RegKey key; | 140 RegKey key; |
| 141 if (key.Open(reg_root, distribution_->GetStateKey().c_str(), KEY_READ)) { | 141 if (key.Open(reg_root, distribution_->GetStateKey().c_str(), KEY_READ)) { |
| 142 DWORD msi_value; | 142 DWORD msi_value; |
| 143 if (key.ReadValueDW(google_update::kRegMSIField, &msi_value)) { | 143 if (key.ReadValueDW(google_update::kRegMSIField, &msi_value)) { |
| 144 msi_ = (msi_value == 1) ? IS_MSI : NOT_MSI; | 144 msi_ = (msi_value == 1) ? IS_MSI : NOT_MSI; |
| 145 } | 145 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 165 LOG(ERROR) << "Could not write MSI value to client state key."; | 165 LOG(ERROR) << "Could not write MSI value to client state key."; |
| 166 } | 166 } |
| 167 } else { | 167 } else { |
| 168 LOG(ERROR) << "SetMsiMarker: Could not open client state key!"; | 168 LOG(ERROR) << "SetMsiMarker: Could not open client state key!"; |
| 169 } | 169 } |
| 170 | 170 |
| 171 return success; | 171 return success; |
| 172 } | 172 } |
| 173 | 173 |
| 174 void Product::WriteInstallerResult( | 174 void Product::WriteInstallerResult( |
| 175 installer_util::InstallStatus status, int string_resource_id, | 175 installer::InstallStatus status, int string_resource_id, |
| 176 const std::wstring* const launch_cmd) const { | 176 const std::wstring* const launch_cmd) const { |
| 177 HKEY root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 177 HKEY root = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 178 std::wstring key(distribution_->GetStateKey()); | 178 std::wstring key(distribution_->GetStateKey()); |
| 179 int installer_result = distribution_->GetInstallReturnCode(status) == 0 ? | 179 int installer_result = distribution_->GetInstallReturnCode(status) == 0 ? |
| 180 0 : 1; | 180 0 : 1; |
| 181 scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList()); | 181 scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList()); |
| 182 install_list->AddCreateRegKeyWorkItem(root, key); | 182 install_list->AddCreateRegKeyWorkItem(root, key); |
| 183 install_list->AddSetRegValueWorkItem(root, key, | 183 install_list->AddSetRegValueWorkItem(root, key, |
| 184 installer_util::kInstallerResult, | 184 installer::kInstallerResult, |
| 185 installer_result, true); | 185 installer_result, true); |
| 186 install_list->AddSetRegValueWorkItem(root, key, | 186 install_list->AddSetRegValueWorkItem(root, key, |
| 187 installer_util::kInstallerError, | 187 installer::kInstallerError, |
| 188 status, true); | 188 status, true); |
| 189 if (string_resource_id != 0) { | 189 if (string_resource_id != 0) { |
| 190 std::wstring msg = installer_util::GetLocalizedString(string_resource_id); | 190 std::wstring msg = installer::GetLocalizedString(string_resource_id); |
| 191 install_list->AddSetRegValueWorkItem(root, key, | 191 install_list->AddSetRegValueWorkItem(root, key, |
| 192 installer_util::kInstallerResultUIString, msg, true); | 192 installer::kInstallerResultUIString, msg, true); |
| 193 } | 193 } |
| 194 if (launch_cmd != NULL && !launch_cmd->empty()) { | 194 if (launch_cmd != NULL && !launch_cmd->empty()) { |
| 195 install_list->AddSetRegValueWorkItem(root, key, | 195 install_list->AddSetRegValueWorkItem(root, key, |
| 196 installer_util::kInstallerSuccessLaunchCmdLine, *launch_cmd, true); | 196 installer::kInstallerSuccessLaunchCmdLine, *launch_cmd, true); |
| 197 } | 197 } |
| 198 if (!install_list->Do()) | 198 if (!install_list->Do()) |
| 199 LOG(ERROR) << "Failed to record installer error information in registry."; | 199 LOG(ERROR) << "Failed to record installer error information in registry."; |
| 200 } | 200 } |
| 201 | 201 |
| 202 Version* Product::GetInstalledVersion() const { | 202 Version* Product::GetInstalledVersion() const { |
| 203 return InstallUtil::GetChromeVersion(distribution_, system_level_); | 203 return InstallUtil::GetChromeVersion(distribution_, system_level_); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /////////////////////////////////////////////////////////////////////////////// | 206 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 DCHECK_EQ(product->IsMsi(), products_[i]->IsMsi()); | 245 DCHECK_EQ(product->IsMsi(), products_[i]->IsMsi()); |
| 246 } | 246 } |
| 247 #endif | 247 #endif |
| 248 products_.push_back(product); | 248 products_.push_back(product); |
| 249 | 249 |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool ProductPackageMapping::AddDistribution( | 253 bool ProductPackageMapping::AddDistribution( |
| 254 BrowserDistribution::Type type, | 254 BrowserDistribution::Type type, |
| 255 const installer_util::MasterPreferences& prefs) { | 255 const installer::MasterPreferences& prefs) { |
| 256 BrowserDistribution* distribution = | 256 BrowserDistribution* distribution = |
| 257 BrowserDistribution::GetSpecificDistribution(type, prefs); | 257 BrowserDistribution::GetSpecificDistribution(type, prefs); |
| 258 if (!distribution) { | 258 if (!distribution) { |
| 259 NOTREACHED(); | 259 NOTREACHED(); |
| 260 return false; | 260 return false; |
| 261 } | 261 } |
| 262 | 262 |
| 263 return AddDistribution(distribution); | 263 return AddDistribution(distribution); |
| 264 } | 264 } |
| 265 | 265 |
| 266 } // namespace installer | 266 } // namespace installer |
| 267 | 267 |
| OLD | NEW |