| 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" | |
| 11 #include "chrome/installer/mini_installer/mini_installer_resource.h" | 10 #include "chrome/installer/mini_installer/mini_installer_resource.h" |
| 12 #include "chrome/installer/mini_installer/regkey.h" | |
| 13 | 11 |
| 14 namespace mini_installer { | 12 namespace mini_installer { |
| 15 | 13 |
| 16 Configuration::Configuration() : args_(NULL) { | 14 Configuration::Configuration() : args_(NULL) { |
| 17 Clear(); | 15 Clear(); |
| 18 } | 16 } |
| 19 | 17 |
| 20 Configuration::~Configuration() { | 18 Configuration::~Configuration() { |
| 21 Clear(); | 19 Clear(); |
| 22 } | 20 } |
| 23 | 21 |
| 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_ ? | |
| 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 (!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 | |
| 75 const wchar_t* Configuration::program() const { | 22 const wchar_t* Configuration::program() const { |
| 76 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; | 23 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; |
| 77 } | 24 } |
| 78 | 25 |
| 79 void Configuration::Clear() { | 26 void Configuration::Clear() { |
| 80 if (args_ != NULL) { | 27 if (args_ != NULL) { |
| 81 ::LocalFree(args_); | 28 ::LocalFree(args_); |
| 82 args_ = NULL; | 29 args_ = NULL; |
| 83 } | 30 } |
| 84 chrome_app_guid_ = google_update::kAppGuid; | 31 chrome_app_guid_ = google_update::kAppGuid; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 114 has_chrome_frame_ = true; | 61 has_chrome_frame_ = true; |
| 115 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) | 62 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) |
| 116 is_multi_install_ = true; | 63 is_multi_install_ = true; |
| 117 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) | 64 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) |
| 118 is_system_level_ = true; | 65 is_system_level_ = true; |
| 119 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) | 66 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) |
| 120 operation_ = CLEANUP; | 67 operation_ = CLEANUP; |
| 121 } | 68 } |
| 122 | 69 |
| 123 // Single-install defaults to Chrome. | 70 // Single-install defaults to Chrome. |
| 124 if (is_multi_install_) { | 71 if (!is_multi_install_) |
| 125 SetChromeAppGuid(); | |
| 126 } else { | |
| 127 has_chrome_ = !has_chrome_frame_; | 72 has_chrome_ = !has_chrome_frame_; |
| 128 } | |
| 129 } | 73 } |
| 130 | 74 |
| 131 return args_ != NULL; | 75 return args_ != NULL; |
| 132 } | 76 } |
| 133 | 77 |
| 134 void Configuration::ReadResources(HMODULE module) { | 78 void Configuration::ReadResources(HMODULE module) { |
| 135 HRSRC resource_info_block = | 79 HRSRC resource_info_block = |
| 136 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA); | 80 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA); |
| 137 if (!resource_info_block) | 81 if (!resource_info_block) |
| 138 return; | 82 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 154 size_t version_len = version_size / sizeof(wchar_t); | 98 size_t version_len = version_size / sizeof(wchar_t); |
| 155 | 99 |
| 156 // The string must be terminated. | 100 // The string must be terminated. |
| 157 if (version_string[version_len - 1]) | 101 if (version_string[version_len - 1]) |
| 158 return; | 102 return; |
| 159 | 103 |
| 160 previous_version_ = version_string; | 104 previous_version_ = version_string; |
| 161 } | 105 } |
| 162 | 106 |
| 163 } // namespace mini_installer | 107 } // namespace mini_installer |
| OLD | NEW |