Chromium Code Reviews| 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/mini_installer/configuration.h" | 5 #include "chrome/installer/mini_installer/configuration.h" |
| 6 | 6 |
| 7 #include <shellapi.h> // NOLINT | 7 #include <shellapi.h> // NOLINT |
| 8 | 8 |
| 9 #include "chrome/installer/mini_installer/appid.h" | 9 #include "chrome/installer/mini_installer/appid.h" |
| 10 #include "chrome/installer/mini_installer/mini_installer_constants.h" | |
| 10 #include "chrome/installer/mini_installer/mini_installer_resource.h" | 11 #include "chrome/installer/mini_installer/mini_installer_resource.h" |
| 12 #include "chrome/installer/mini_installer/regkey.h" | |
| 11 | 13 |
| 12 namespace mini_installer { | 14 namespace mini_installer { |
| 13 | 15 |
| 14 Configuration::Configuration() : args_(NULL) { | 16 Configuration::Configuration() : args_(NULL) { |
| 15 Clear(); | 17 Clear(); |
| 16 } | 18 } |
| 17 | 19 |
| 18 Configuration::~Configuration() { | 20 Configuration::~Configuration() { |
| 19 Clear(); | 21 Clear(); |
| 20 } | 22 } |
| 21 | 23 |
| 24 // When multi_install is true, we are potentially: | |
| 25 // 1. Performing a multi-install of some product(s) on a clean machine. | |
| 26 // Neither the product(s) nor the multi-installer will have a | |
| 27 // ClientState key in the registry, so there is no key to be modified. | |
| 28 // 2. Upgrading an existing multi-install. The multi-installer will have | |
| 29 // a ClientState key in the registry. Only it need be modified. | |
| 30 // 3. Migrating a single-install into a multi-install. The product will | |
| 31 // have a ClientState key in the registry. Only it need be modified. | |
| 32 // To handle all cases, we inspect the product's ClientState to see if it | |
| 33 // exists and its "ap" value does not contain "-multi". This is case 3, | |
| 34 // so we modify the product's ClientState. Otherwise, we check the | |
| 35 // multi-installer's ClientState and modify it if it exists. | |
| 36 // TODO(bcwhite): Write a unit test for this that uses registry virtualization. | |
| 37 void Configuration::SetChromeAppGuid() { | |
| 38 const HKEY root_key = | |
| 39 is_system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
| 40 const wchar_t* app_guid = | |
| 41 has_chrome_frame_ ? | |
|
robertshield
2015/08/04 03:11:36
Maybe out of scope for your change, but why does t
bcwhite
2015/08/04 19:34:30
It was existing code. At one point I had removed
robertshield
2015/08/05 18:39:48
SGTM.
| |
| 42 google_update::kChromeFrameAppGuid : | |
| 43 google_update::kAppGuid; | |
| 44 | |
| 45 // This is the value for single-install and case 3. | |
| 46 chrome_app_guid_ = app_guid; | |
| 47 | |
| 48 if (is_multi_install_) { | |
| 49 ValueString value; | |
| 50 LONG ret = ERROR_SUCCESS; | |
| 51 if (ReadClientStateRegistryValue(root_key, app_guid, &ret, value)) { | |
| 52 // The product has a client state key. See if it's a single-install. | |
| 53 if (ret == ERROR_FILE_NOT_FOUND || | |
| 54 (ret == ERROR_SUCCESS && | |
| 55 !FindTagInStr(value.get(), kMultiInstallTag, NULL))) { | |
| 56 // yes -- case 3: use the existing key. | |
| 57 return; | |
| 58 } | |
| 59 } | |
| 60 // error, case 1, or case 2: modify the multi-installer's key. | |
| 61 chrome_app_guid_ = google_update::kMultiInstallAppGuid; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 bool Configuration::ReadClientStateRegistryValue( | |
| 66 const HKEY root_key, const wchar_t* app_guid, | |
| 67 LONG* retval, ValueString& value) { | |
| 68 RegKey key; | |
| 69 if (!RegKey::OpenClientStateKey(root_key, app_guid, KEY_QUERY_VALUE, &key)) | |
| 70 return false; | |
| 71 *retval = key.ReadSZValue(kApRegistryValue, value.get(), value.capacity()); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 22 const wchar_t* Configuration::program() const { | 75 const wchar_t* Configuration::program() const { |
| 23 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; | 76 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; |
| 24 } | 77 } |
| 25 | 78 |
| 26 void Configuration::Clear() { | 79 void Configuration::Clear() { |
| 27 if (args_ != NULL) { | 80 if (args_ != NULL) { |
| 28 ::LocalFree(args_); | 81 ::LocalFree(args_); |
| 29 args_ = NULL; | 82 args_ = NULL; |
| 30 } | 83 } |
| 31 chrome_app_guid_ = google_update::kAppGuid; | 84 chrome_app_guid_ = google_update::kAppGuid; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 61 has_chrome_frame_ = true; | 114 has_chrome_frame_ = true; |
| 62 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) | 115 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) |
| 63 is_multi_install_ = true; | 116 is_multi_install_ = true; |
| 64 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) | 117 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) |
| 65 is_system_level_ = true; | 118 is_system_level_ = true; |
| 66 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) | 119 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) |
| 67 operation_ = CLEANUP; | 120 operation_ = CLEANUP; |
| 68 } | 121 } |
| 69 | 122 |
| 70 // Single-install defaults to Chrome. | 123 // Single-install defaults to Chrome. |
| 71 if (!is_multi_install_) | 124 if (is_multi_install_) { |
| 125 SetChromeAppGuid(); | |
| 126 } else { | |
| 72 has_chrome_ = !has_chrome_frame_; | 127 has_chrome_ = !has_chrome_frame_; |
| 128 } | |
| 73 } | 129 } |
| 74 | 130 |
| 75 return args_ != NULL; | 131 return args_ != NULL; |
| 76 } | 132 } |
| 77 | 133 |
| 78 void Configuration::ReadResources(HMODULE module) { | 134 void Configuration::ReadResources(HMODULE module) { |
| 79 HRSRC resource_info_block = | 135 HRSRC resource_info_block = |
| 80 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA); | 136 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA); |
| 81 if (!resource_info_block) | 137 if (!resource_info_block) |
| 82 return; | 138 return; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 98 size_t version_len = version_size / sizeof(wchar_t); | 154 size_t version_len = version_size / sizeof(wchar_t); |
| 99 | 155 |
| 100 // The string must be terminated. | 156 // The string must be terminated. |
| 101 if (version_string[version_len - 1]) | 157 if (version_string[version_len - 1]) |
| 102 return; | 158 return; |
| 103 | 159 |
| 104 previous_version_ = version_string; | 160 previous_version_ = version_string; |
| 105 } | 161 } |
| 106 | 162 |
| 107 } // namespace mini_installer | 163 } // namespace mini_installer |
| OLD | NEW |