Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/self_reg_work_item.h" | 5 #include "chrome/installer/util/self_reg_work_item.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/installer/util/logging_installer.h" | 10 #include "chrome/installer/util/logging_installer.h" |
| 11 | 11 |
| 12 // Default registration export names. | 12 // Default registration export names. |
| 13 const char kDefaultRegistrationEntryPoint[] = "DllRegisterServer"; | 13 const char kDefaultRegistrationEntryPoint[] = "DllRegisterServer"; |
| 14 const char kDefaultUnregistrationEntryPoint[] = "DllUnregisterServer"; | 14 const char kDefaultUnregistrationEntryPoint[] = "DllUnregisterServer"; |
| 15 | 15 |
| 16 // User-level registration export names. | 16 // User-level registration export names. |
| 17 const char kUserRegistrationEntryPoint[] = "DllRegisterUserServer"; | 17 const char kUserRegistrationEntryPoint[] = "DllRegisterUserServer"; |
| 18 const char kUserUnregistrationEntryPoint[] = "DllUnregisterUserServer"; | 18 const char kUserUnregistrationEntryPoint[] = "DllUnregisterUserServer"; |
| 19 | 19 |
| 20 SelfRegWorkItem::SelfRegWorkItem(const std::wstring& dll_path, | 20 SelfRegWorkItem::SelfRegWorkItem(const std::wstring& dll_path, |
| 21 bool do_register, | 21 bool do_register, |
| 22 bool user_level_registration) | 22 bool user_level_registration) |
| 23 : do_register_(do_register), dll_path_(dll_path), | 23 : do_register_(do_register), dll_path_(dll_path), |
| 24 user_level_registration_(user_level_registration) { | 24 user_level_registration_(user_level_registration) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 SelfRegWorkItem::~SelfRegWorkItem() { | 27 SelfRegWorkItem::~SelfRegWorkItem() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 // This is designed to unmux error codes that may be shoe-horned in to HRESULT | |
| 31 // return codes by ORing a number into the top four bits of the facility code. | |
| 32 // Any number thus found will be returned in |error_code|. The "cleaned" | |
| 33 // HRESULT is then returned. Note that this will do the wrong thing for | |
| 34 // high-valued facility codes. | |
| 35 HRESULT UnMuxHRESULTErrorCode(HRESULT hr, int* error_code) { | |
| 36 DCHECK(error_code); | |
| 37 *error_code = (hr & 0x07800000) >> 23; | |
|
grt (UTC plus 2)
2011/09/06 14:56:55
why not do this only if the customer bit is set?
robertshield
2011/09/06 20:23:42
Good idea, done.
| |
| 38 return hr & 0xF87FFFFF; | |
| 39 } | |
| 40 | |
| 30 bool SelfRegWorkItem::RegisterDll(bool do_register) { | 41 bool SelfRegWorkItem::RegisterDll(bool do_register) { |
| 31 VLOG(1) << "COM " << (do_register ? "registration of " : "unregistration of ") | 42 VLOG(1) << "COM " << (do_register ? "registration of " : "unregistration of ") |
| 32 << dll_path_; | 43 << dll_path_; |
| 33 | 44 |
| 34 HMODULE dll_module = ::LoadLibraryEx(dll_path_.c_str(), NULL, | 45 HMODULE dll_module = ::LoadLibraryEx(dll_path_.c_str(), NULL, |
| 35 LOAD_WITH_ALTERED_SEARCH_PATH); | 46 LOAD_WITH_ALTERED_SEARCH_PATH); |
| 36 bool success = false; | 47 bool success = false; |
| 37 if (NULL != dll_module) { | 48 if (NULL != dll_module) { |
| 38 typedef HRESULT (WINAPI* RegisterFunc)(); | 49 typedef HRESULT (WINAPI* RegisterFunc)(); |
| 39 RegisterFunc register_server_func = NULL; | 50 RegisterFunc register_server_func = NULL; |
| 40 if (do_register) { | 51 if (do_register) { |
| 41 register_server_func = reinterpret_cast<RegisterFunc>( | 52 register_server_func = reinterpret_cast<RegisterFunc>( |
| 42 ::GetProcAddress(dll_module, user_level_registration_ ? | 53 ::GetProcAddress(dll_module, user_level_registration_ ? |
| 43 kUserRegistrationEntryPoint : kDefaultRegistrationEntryPoint)); | 54 kUserRegistrationEntryPoint : kDefaultRegistrationEntryPoint)); |
| 44 } else { | 55 } else { |
| 45 register_server_func = reinterpret_cast<RegisterFunc>( | 56 register_server_func = reinterpret_cast<RegisterFunc>( |
| 46 ::GetProcAddress(dll_module, user_level_registration_ ? | 57 ::GetProcAddress(dll_module, user_level_registration_ ? |
| 47 kUserUnregistrationEntryPoint : | 58 kUserUnregistrationEntryPoint : |
| 48 kDefaultUnregistrationEntryPoint)); | 59 kDefaultUnregistrationEntryPoint)); |
| 49 } | 60 } |
| 50 | 61 |
| 51 if (NULL != register_server_func) { | 62 if (NULL != register_server_func) { |
| 52 HRESULT hr = register_server_func(); | 63 HRESULT hr = register_server_func(); |
| 53 success = SUCCEEDED(hr); | 64 success = SUCCEEDED(hr); |
| 54 if (!success) { | 65 if (!success) { |
| 55 PLOG(ERROR) << "Failed to " << (do_register ? "register" : "unregister") | 66 int error_code = 0; |
| 56 << " DLL at " << dll_path_.c_str() << | 67 HRESULT unmuxed_hr = UnMuxHRESULTErrorCode(hr, &error_code); |
| 57 base::StringPrintf(" 0x%08X", hr); | 68 LOG(ERROR) << "Failed to " << (do_register ? "register" : "unregister") |
| 69 << " DLL at " << dll_path_.c_str() << ", hr=" | |
| 70 << base::StringPrintf(" 0x%08X", unmuxed_hr) << ", code=" | |
| 71 << error_code; | |
| 58 } | 72 } |
| 59 } else { | 73 } else { |
| 60 LOG(ERROR) << "COM registration export function not found"; | 74 LOG(ERROR) << "COM registration export function not found"; |
| 61 } | 75 } |
| 62 ::FreeLibrary(dll_module); | 76 ::FreeLibrary(dll_module); |
| 63 } else { | 77 } else { |
| 64 PLOG(WARNING) << "Failed to load: " << dll_path_; | 78 PLOG(WARNING) << "Failed to load: " << dll_path_; |
| 65 } | 79 } |
| 66 return success; | 80 return success; |
| 67 } | 81 } |
| 68 | 82 |
| 69 bool SelfRegWorkItem::Do() { | 83 bool SelfRegWorkItem::Do() { |
| 70 bool success = RegisterDll(do_register_); | 84 bool success = RegisterDll(do_register_); |
| 71 if (ignore_failure_) | 85 if (ignore_failure_) |
| 72 success = true; | 86 success = true; |
| 73 return success; | 87 return success; |
| 74 } | 88 } |
| 75 | 89 |
| 76 void SelfRegWorkItem::Rollback() { | 90 void SelfRegWorkItem::Rollback() { |
| 77 if (!ignore_failure_) { | 91 if (!ignore_failure_) { |
| 78 RegisterDll(!do_register_); | 92 RegisterDll(!do_register_); |
| 79 } | 93 } |
| 80 } | 94 } |
| OLD | NEW |