Chromium Code Reviews| 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 // CEEE module-wide utilities. | 5 // CEEE module-wide utilities. |
| 6 | 6 |
| 7 #include "ceee/ie/common/ceee_module_util.h" | 7 #include "ceee/ie/common/ceee_module_util.h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 14 #include "ceee/common/process_utils_win.h" | 14 #include "ceee/common/process_utils_win.h" |
| 15 #include "chrome/installer/util/google_update_constants.h" | 15 #include "chrome/installer/util/google_update_constants.h" |
| 16 | 16 |
| 17 #include "version.h" // NOLINT | |
| 18 | |
| 19 // TODO(joi@chromium.org): would be nice to move these (and non-L counterparts) | |
| 20 // to e.g. base/string_util.h | |
| 21 #define LSTRINGIZE2(x) L ## #x | |
| 22 #define LSTRINGIZE(x) LSTRINGIZE2(x) | |
|
twiz
2010/11/15 19:02:48
Bummer. Surprising that there wouldn't be common
| |
| 23 | |
| 17 namespace { | 24 namespace { |
| 18 | 25 |
| 19 const wchar_t* kRegistryPath = L"SOFTWARE\\Google\\CEEE"; | 26 const wchar_t* kRegistryPath = L"SOFTWARE\\Google\\CEEE"; |
| 20 const wchar_t* kRegistryValueToolbandIsHidden = L"toolband_is_hidden"; | 27 const wchar_t* kRegistryValueToolbandIsHidden = L"toolband_is_hidden"; |
| 21 const wchar_t* kRegistryValueToolbandPlaced = L"toolband_placed"; | 28 const wchar_t* kRegistryValueToolbandPlaced = L"toolband_placed"; |
| 22 const wchar_t* kRegistryValueCrxInstalledPath = L"crx_installed_path"; | 29 const wchar_t* kRegistryValueCrxInstalledPath = L"crx_installed_path"; |
| 23 const wchar_t* kRegistryValueCrxInstalledTime = L"crx_installed_time"; | 30 const wchar_t* kRegistryValueCrxInstalledTime = L"crx_installed_time"; |
| 31 const wchar_t* kRegistryValueCrxInstalledByVersion = | |
| 32 L"crx_installed_runtime_version"; | |
| 24 | 33 |
| 25 // Global state needed by the BHO and the | 34 // Global state needed by the BHO and the |
| 26 // toolband, to indicate whether ShowDW calls should affect | 35 // toolband, to indicate whether ShowDW calls should affect |
| 27 // registry tracking of the user's visibility preference. A | 36 // registry tracking of the user's visibility preference. A |
| 28 // non-zero value indicates that the calls should be ignored. | 37 // non-zero value indicates that the calls should be ignored. |
| 29 LONG g_ignore_show_dw_changes = 0; | 38 LONG g_ignore_show_dw_changes = 0; |
| 30 | 39 |
| 31 bool GetCeeeRegistryBoolean(const wchar_t* key, bool default_value) { | 40 bool GetCeeeRegistryBoolean(const wchar_t* key, bool default_value) { |
| 32 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 41 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
| 33 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; | 42 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 if (path.empty()) { | 175 if (path.empty()) { |
| 167 // No extension to install, so no need to install the extension. | 176 // No extension to install, so no need to install the extension. |
| 168 return false; | 177 return false; |
| 169 } | 178 } |
| 170 | 179 |
| 171 const FilePath crx_path(path); | 180 const FilePath crx_path(path); |
| 172 if (IsCrxOrEmpty(crx_path.value())) { | 181 if (IsCrxOrEmpty(crx_path.value())) { |
| 173 if (crx_path == GetInstalledExtensionPath()) { | 182 if (crx_path == GetInstalledExtensionPath()) { |
| 174 base::Time installed_time; | 183 base::Time installed_time; |
| 175 base::PlatformFileInfo extension_info; | 184 base::PlatformFileInfo extension_info; |
| 176 const bool success = file_util::GetFileInfo(crx_path, &extension_info); | 185 bool success = file_util::GetFileInfo(crx_path, &extension_info); |
| 177 // If the call above didn't succeed, assume we need to install. | 186 // If the call above didn't succeed, assume we need to install. |
| 178 return !success || | 187 if (!success || |
| 179 extension_info.last_modified > GetInstalledExtensionTime(); | 188 extension_info.last_modified > GetInstalledExtensionTime()) { |
| 189 return true; | |
| 190 } else { | |
| 191 // We also check that the current version of Chrome was the one | |
| 192 // that attempted installation; if not, changes such as a change | |
| 193 // in the location of a profile directory might have occurred, and | |
| 194 // we might need to retry installation. | |
| 195 std::wstring version_string; | |
| 196 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | |
| 197 success = hkcu.ReadValue( | |
| 198 kRegistryValueCrxInstalledByVersion, &version_string); | |
| 199 return !success || version_string != LSTRINGIZE(CHROME_VERSION_STRING); | |
| 200 } | |
| 180 } | 201 } |
| 181 | 202 |
| 182 return true; | 203 return true; |
| 183 } | 204 } |
| 184 | 205 |
| 185 return false; | 206 return false; |
| 186 } | 207 } |
| 187 | 208 |
| 188 void SetInstalledExtensionPath(const FilePath& path) { | 209 void SetInstalledExtensionPath(const FilePath& path) { |
| 189 base::PlatformFileInfo extension_info; | 210 base::PlatformFileInfo extension_info; |
| 190 const bool success = file_util::GetFileInfo(path, &extension_info); | 211 const bool success = file_util::GetFileInfo(path, &extension_info); |
| 191 const int64 crx_time = success ? | 212 const int64 crx_time = success ? |
| 192 extension_info.last_modified.ToInternalValue() : | 213 extension_info.last_modified.ToInternalValue() : |
| 193 base::Time::Now().ToInternalValue(); | 214 base::Time::Now().ToInternalValue(); |
| 194 | 215 |
| 195 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); | 216 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); |
| 196 bool write_result = key.WriteValue(kRegistryValueCrxInstalledTime, | 217 bool write_result = key.WriteValue(kRegistryValueCrxInstalledTime, |
| 197 &crx_time, | 218 &crx_time, |
| 198 sizeof(crx_time), | 219 sizeof(crx_time), |
| 199 REG_QWORD); | 220 REG_QWORD); |
| 200 DCHECK(write_result); | 221 DCHECK(write_result); |
| 201 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, | 222 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, |
| 202 path.value().c_str()); | 223 path.value().c_str()); |
| 203 DCHECK(write_result); | 224 DCHECK(write_result); |
| 225 | |
| 226 write_result = key.WriteValue(kRegistryValueCrxInstalledByVersion, | |
| 227 LSTRINGIZE(CHROME_VERSION_STRING)); | |
|
twiz
2010/11/15 19:02:48
Add a DCHECK here too?
| |
| 204 } | 228 } |
| 205 | 229 |
| 206 bool IsCrxOrEmpty(const std::wstring& path) { | 230 bool IsCrxOrEmpty(const std::wstring& path) { |
| 207 return (path.empty() || | 231 return (path.empty() || |
| 208 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); | 232 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); |
| 209 } | 233 } |
| 210 | 234 |
| 211 void SetOptionToolbandIsHidden(bool is_hidden) { | 235 void SetOptionToolbandIsHidden(bool is_hidden) { |
| 212 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); | 236 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); |
| 213 } | 237 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 DWORD value; | 294 DWORD value; |
| 271 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { | 295 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { |
| 272 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 296 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
| 273 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) | 297 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) |
| 274 return false; | 298 return false; |
| 275 } | 299 } |
| 276 return (1 == value); | 300 return (1 == value); |
| 277 } | 301 } |
| 278 | 302 |
| 279 } // namespace ceee_module_util | 303 } // namespace ceee_module_util |
| OLD | NEW |