| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/app/google_update_client.h" | 5 #include "chrome/app/google_update_client.h" |
| 6 | 6 |
| 7 #include <shlobj.h> | 7 #include <shlobj.h> |
| 8 #include <strsafe.h> | 8 #include <strsafe.h> |
| 9 | 9 |
| 10 #include "chrome/app/client_util.h" | 10 #include "chrome/app/client_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 delete[] value; | 25 delete[] value; |
| 26 return false; | 26 return false; |
| 27 } | 27 } |
| 28 *out = value; | 28 *out = value; |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 } // anonymous namespace | 31 } // anonymous namespace |
| 32 | 32 |
| 33 namespace google_update { | 33 namespace google_update { |
| 34 | 34 |
| 35 GoogleUpdateClient::GoogleUpdateClient() : version_(NULL) { | 35 GoogleUpdateClient::GoogleUpdateClient() : version_(NULL), dll_handle_(NULL) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 GoogleUpdateClient::~GoogleUpdateClient() { | 38 GoogleUpdateClient::~GoogleUpdateClient() { |
| 39 delete[] version_; | 39 delete[] version_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 std::wstring GoogleUpdateClient::GetDLLPath() { | 42 std::wstring GoogleUpdateClient::GetDLLPath() { |
| 43 return client_util::GetDLLPath(dll_, dll_path_); | 43 return client_util::GetDLLPath(dll_, dll_path_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 const wchar_t* GoogleUpdateClient::GetVersion() const { | 46 const wchar_t* GoogleUpdateClient::GetVersion() const { |
| 47 return version_; | 47 return version_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool GoogleUpdateClient::Launch(HINSTANCE instance, | 50 bool GoogleUpdateClient::Load() { |
| 51 sandbox::SandboxInterfaceInfo* sandbox, | |
| 52 wchar_t* command_line, | |
| 53 int show_command, | |
| 54 const char* entry_name, | |
| 55 int* ret) { | |
| 56 if (client_util::FileExists(dll_path_)) { | 51 if (client_util::FileExists(dll_path_)) { |
| 57 ::SetCurrentDirectory(dll_path_); | 52 ::SetCurrentDirectory(dll_path_); |
| 58 // Setting the version on the environment block is a 'best effort' deal. | 53 // Setting the version on the environment block is a 'best effort' deal. |
| 59 // It enables Google Update running on a child to load the same DLL version. | 54 // It enables Google Update running on a child to load the same DLL version. |
| 60 ::SetEnvironmentVariableW(kEnvProductVersionKey, version_); | 55 ::SetEnvironmentVariableW(kEnvProductVersionKey, version_); |
| 61 } | 56 } |
| 62 | 57 |
| 63 // The dll can be in the exe's directory or in the current directory. | 58 // The dll can be in the exe's directory or in the current directory. |
| 64 // Use the alternate search path to be sure that it's not trying to load it | 59 // Use the alternate search path to be sure that it's not trying to load it |
| 65 // calling application's directory. | 60 // calling application's directory. |
| 66 HINSTANCE dll_handle = ::LoadLibraryEx(dll_.c_str(), NULL, | 61 dll_handle_ = ::LoadLibraryEx(dll_.c_str(), |
| 67 LOAD_WITH_ALTERED_SEARCH_PATH); | 62 NULL, |
| 68 if (NULL == dll_handle) { | 63 LOAD_WITH_ALTERED_SEARCH_PATH); |
| 69 unsigned long err = GetLastError(); | 64 if (dll_handle_) |
| 70 if (err) { | 65 return true; |
| 71 WCHAR message[500] = {0}; | 66 |
| 72 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, | 67 unsigned long err = GetLastError(); |
| 73 reinterpret_cast<LPWSTR>(&message), 500, NULL); | 68 if (err) { |
| 74 ::OutputDebugStringW(message); | 69 WCHAR message[500] = {0}; |
| 75 } | 70 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, |
| 76 return false; | 71 reinterpret_cast<LPWSTR>(&message), 500, NULL); |
| 72 ::OutputDebugStringW(message); |
| 77 } | 73 } |
| 74 return false; |
| 75 } |
| 78 | 76 |
| 77 |
| 78 bool GoogleUpdateClient::Launch(HINSTANCE instance, |
| 79 sandbox::SandboxInterfaceInfo* sandbox, |
| 80 wchar_t* command_line, |
| 81 int show_command, |
| 82 const char* entry_name, |
| 83 int* ret) { |
| 79 bool did_launch = false; | 84 bool did_launch = false; |
| 80 client_util::DLL_MAIN entry = reinterpret_cast<client_util::DLL_MAIN>( | 85 client_util::DLL_MAIN entry = reinterpret_cast<client_util::DLL_MAIN>( |
| 81 ::GetProcAddress(dll_handle, entry_name)); | 86 ::GetProcAddress(dll_handle_, entry_name)); |
| 82 if (NULL != entry) { | 87 if (NULL != entry) { |
| 83 // record did_run "dr" in client state | 88 // record did_run "dr" in client state |
| 84 std::wstring key_path(google_update::kRegPathClientState); | 89 std::wstring key_path(google_update::kRegPathClientState); |
| 85 key_path.append(L"\\" + guid_); | 90 key_path.append(L"\\" + guid_); |
| 86 HKEY reg_key; | 91 HKEY reg_key; |
| 87 if (::RegOpenKeyEx(HKEY_CURRENT_USER, key_path.c_str(), 0, | 92 if (::RegOpenKeyEx(HKEY_CURRENT_USER, key_path.c_str(), 0, |
| 88 KEY_WRITE, ®_key) == ERROR_SUCCESS) { | 93 KEY_WRITE, ®_key) == ERROR_SUCCESS) { |
| 89 const wchar_t kVal[] = L"1"; | 94 const wchar_t kVal[] = L"1"; |
| 90 ::RegSetValueEx(reg_key, google_update::kRegDidRunField, 0, REG_SZ, | 95 ::RegSetValueEx(reg_key, google_update::kRegDidRunField, 0, REG_SZ, |
| 91 reinterpret_cast<const BYTE *>(kVal), sizeof(kVal)); | 96 reinterpret_cast<const BYTE *>(kVal), sizeof(kVal)); |
| 92 ::RegCloseKey(reg_key); | 97 ::RegCloseKey(reg_key); |
| 93 } | 98 } |
| 94 | 99 |
| 95 int rc = (entry)(instance, sandbox, command_line, show_command); | 100 int rc = (entry)(instance, sandbox, command_line, show_command); |
| 96 if (ret) { | 101 if (ret) { |
| 97 *ret = rc; | 102 *ret = rc; |
| 98 } | 103 } |
| 99 did_launch = true; | 104 did_launch = true; |
| 100 } | 105 } |
| 101 #ifdef PURIFY | 106 #ifdef PURIFY |
| 102 // We should never unload the dll. There is only risk and no gain from | 107 // We should never unload the dll. There is only risk and no gain from |
| 103 // doing so. The singleton dtors have been already run by AtExitManager. | 108 // doing so. The singleton dtors have been already run by AtExitManager. |
| 104 ::FreeLibrary(dll_handle); | 109 ::FreeLibrary(dll_handle_); |
| 105 #endif | 110 #endif |
| 106 return did_launch; | 111 return did_launch; |
| 107 } | 112 } |
| 108 | 113 |
| 109 bool GoogleUpdateClient::Init(const wchar_t* client_guid, | 114 bool GoogleUpdateClient::Init(const wchar_t* client_guid, |
| 110 const wchar_t* client_dll) { | 115 const wchar_t* client_dll) { |
| 111 client_util::GetExecutablePath(dll_path_); | 116 client_util::GetExecutablePath(dll_path_); |
| 112 guid_.assign(client_guid); | 117 guid_.assign(client_guid); |
| 113 dll_.assign(client_dll); | 118 dll_.assign(client_dll); |
| 114 bool ret = false; | 119 bool ret = false; |
| 115 if (!guid_.empty()) { | 120 if (!guid_.empty()) { |
| 116 if (GoogleUpdateEnvQueryStr(kEnvProductVersionKey, &version_)) { | 121 if (GoogleUpdateEnvQueryStr(kEnvProductVersionKey, &version_)) { |
| 117 ret = true; | 122 ret = true; |
| 118 } else { | 123 } else { |
| 119 std::wstring key(google_update::kRegPathClients); | 124 std::wstring key(google_update::kRegPathClients); |
| 120 key.append(L"\\" + guid_); | 125 key.append(L"\\" + guid_); |
| 121 if (client_util::GetChromiumVersion(dll_path_, key.c_str(), &version_)) | 126 if (client_util::GetChromiumVersion(dll_path_, key.c_str(), &version_)) |
| 122 ret = true; | 127 ret = true; |
| 123 } | 128 } |
| 124 } | 129 } |
| 125 | 130 |
| 126 if (version_) { | 131 if (version_) { |
| 127 ::StringCchCat(dll_path_, MAX_PATH, version_); | 132 ::StringCchCat(dll_path_, MAX_PATH, version_); |
| 128 } | 133 } |
| 129 return ret; | 134 return ret; |
| 130 } | 135 } |
| 131 } // namespace google_update | 136 } // namespace google_update |
| OLD | NEW |