OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/setup_install_details.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string16.h" |
| 10 #include "base/win/registry.h" |
| 11 #include "chrome/install_static/install_constants.h" |
| 12 #include "chrome/install_static/install_details.h" |
| 13 #include "chrome/install_static/install_modes.h" |
| 14 #include "chrome/install_static/install_util.h" |
| 15 #include "chrome/installer/util/google_update_constants.h" |
| 16 #include "chrome/installer/util/master_preferences.h" |
| 17 #include "chrome/installer/util/master_preferences_constants.h" |
| 18 #include "chrome/installer/util/util_constants.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 const install_static::InstallConstants* FindInstallMode( |
| 23 const base::CommandLine& command_line) { |
| 24 // Search for a mode whose switch is on the command line. |
| 25 for (int i = 1; i < install_static::NUM_INSTALL_MODES; ++i) { |
| 26 const install_static::InstallConstants& mode = |
| 27 install_static::kInstallModes[i]; |
| 28 if (command_line.HasSwitch(mode.install_switch)) |
| 29 return &mode; |
| 30 } |
| 31 // The first mode is always the default if all else fails. |
| 32 return &install_static::kInstallModes[0]; |
| 33 } |
| 34 |
| 35 // Returns true if Chrome is installed (i.e., has a "pv" value) and its |
| 36 // UninstallArguments contains "--multi-install". |
| 37 bool IsUpdatingFromMulti(const install_static::InstallConstants& mode, |
| 38 bool system_level) { |
| 39 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 40 const wchar_t* const app_guid = mode.app_guid; |
| 41 base::win::RegKey key; |
| 42 base::string16 value; |
| 43 |
| 44 return key.Open(root, install_static::GetClientsKeyPath(app_guid).c_str(), |
| 45 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
| 46 key.ReadValue(google_update::kRegVersionField, &value) == |
| 47 ERROR_SUCCESS && |
| 48 !value.empty() && |
| 49 key.Open(root, install_static::GetClientStateKeyPath(app_guid).c_str(), |
| 50 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && |
| 51 key.ReadValue(installer::kUninstallArgumentsField, &value) == |
| 52 ERROR_SUCCESS && |
| 53 value.find(L"--multi-install") != base::string16::npos; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
| 58 void InitializeInstallDetails( |
| 59 const base::CommandLine& command_line, |
| 60 const installer::MasterPreferences& master_preferences) { |
| 61 install_static::InstallDetails::SetForProcess( |
| 62 MakeInstallDetails(command_line, master_preferences)); |
| 63 } |
| 64 |
| 65 std::unique_ptr<install_static::PrimaryInstallDetails> MakeInstallDetails( |
| 66 const base::CommandLine& command_line, |
| 67 const installer::MasterPreferences& master_preferences) { |
| 68 std::unique_ptr<install_static::PrimaryInstallDetails> details( |
| 69 base::MakeUnique<install_static::PrimaryInstallDetails>()); |
| 70 |
| 71 // The mode is determined by brand-specific command line switches. |
| 72 const install_static::InstallConstants* const mode = |
| 73 FindInstallMode(command_line); |
| 74 details->set_mode(mode); |
| 75 |
| 76 // The install level may be set by any of: |
| 77 // - distribution.system_level=true in master_preferences, |
| 78 // - --system-level on the command line, or |
| 79 // - the GoogleUpdateIsMachine=1 environment variable. |
| 80 // In all three cases the value is sussed out in MasterPreferences |
| 81 // initialization. |
| 82 bool system_level = false; |
| 83 master_preferences.GetBool(installer::master_preferences::kSystemLevel, |
| 84 &system_level); |
| 85 details->set_system_level(system_level); |
| 86 |
| 87 // The channel is determined based on the brand and the mode's |
| 88 // ChannelStrategy. For brands that do not support Google Update, the channel |
| 89 // is an empty string. For modes using the FIXED strategy, the channel is the |
| 90 // default_channel_name in the mode. For modes using the ADDITIONAL_PARAMETERS |
| 91 // strategy, the channel is parsed from the "ap" value in either the binaries' |
| 92 // ClientState registry key or the mode's ClientState registry key. Which one |
| 93 // is used depends on whether or not this Chrome is updating from a legacy |
| 94 // multi-install Chrome. |
| 95 details->set_channel(install_static::DetermineChannel( |
| 96 *mode, system_level, IsUpdatingFromMulti(*mode, system_level))); |
| 97 |
| 98 return details; |
| 99 } |
OLD | NEW |