OLD | NEW |
| (Empty) |
1 // Copyright 2009-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // Contains the ATL exe server registration. | |
17 | |
18 #include "omaha/goopdate/google_update.h" | |
19 #include "goopdate/omaha3_idl.h" | |
20 #include "omaha/base/debug.h" | |
21 #include "omaha/base/error.h" | |
22 #include "omaha/base/logging.h" | |
23 #include "omaha/common/goopdate_utils.h" | |
24 #include "omaha/core/google_update_core.h" | |
25 #include "omaha/goopdate/broker_class_factory.h" | |
26 #include "omaha/goopdate/cocreate_async.h" | |
27 #include "omaha/goopdate/cred_dialog.h" | |
28 #include "omaha/goopdate/google_update3.h" | |
29 #include "omaha/goopdate/omaha3_idl_datax.h" | |
30 #include "omaha/goopdate/ondemand.h" | |
31 #include "omaha/goopdate/oneclick_process_launcher.h" | |
32 #include "omaha/goopdate/process_launcher.h" | |
33 #include "omaha/goopdate/update3web.h" | |
34 #include "omaha/goopdate/worker.h" | |
35 | |
36 namespace omaha { | |
37 | |
38 // Template arguments need to be non-const TCHAR arrays. | |
39 TCHAR kOnDemandMachineBrokerProgId[] = kProgIDOnDemandMachine; | |
40 TCHAR kUpdate3WebMachineBrokerProgId[] = kProgIDUpdate3WebMachine; | |
41 TCHAR kHKRootUser[] = _T("HKCU"); | |
42 TCHAR kHKRootMachine[] = _T("HKLM"); | |
43 TCHAR kProgIDUpdate3COMClassUserLocal[] = kProgIDUpdate3COMClassUser; | |
44 | |
45 BEGIN_OBJECT_MAP(object_map_update3_user_mode) | |
46 OBJECT_ENTRY(__uuidof(GoogleUpdate3UserClass), Update3COMClassUser) | |
47 END_OBJECT_MAP() | |
48 | |
49 BEGIN_OBJECT_MAP(object_map_broker_machine_mode) | |
50 OBJECT_ENTRY(__uuidof(OnDemandMachineAppsClass), OnDemandMachineBroker) | |
51 OBJECT_ENTRY(__uuidof(GoogleUpdate3WebMachineClass), Update3WebMachineBroker) | |
52 OBJECT_ENTRY(__uuidof(CoCreateAsyncClass), CoCreateAsync) | |
53 OBJECT_ENTRY(__uuidof(OneClickMachineProcessLauncherClass), | |
54 OneClickProcessLauncher) | |
55 END_OBJECT_MAP() | |
56 | |
57 BEGIN_OBJECT_MAP(object_map_ondemand_user_mode) | |
58 OBJECT_ENTRY(__uuidof(GoogleUpdate3WebUserClass), Update3WebUser) | |
59 OBJECT_ENTRY(__uuidof(OnDemandUserAppsClass), OnDemandUser) | |
60 OBJECT_ENTRY(__uuidof(CredentialDialogUserClass), CredentialDialogUser) | |
61 OBJECT_ENTRY(__uuidof(OneClickUserProcessLauncherClass), | |
62 OneClickProcessLauncher) | |
63 END_OBJECT_MAP() | |
64 | |
65 BEGIN_OBJECT_MAP(object_map_ondemand_machine_mode) | |
66 OBJECT_ENTRY(__uuidof(ProcessLauncherClass), ProcessLauncher) | |
67 OBJECT_ENTRY(__uuidof(GoogleUpdateCoreMachineClass), GoogleUpdateCoreMachine) | |
68 OBJECT_ENTRY(__uuidof(OnDemandMachineAppsFallbackClass), | |
69 OnDemandMachineFallback) | |
70 OBJECT_ENTRY(__uuidof(GoogleUpdate3WebMachineFallbackClass), | |
71 Update3WebMachineFallback) | |
72 OBJECT_ENTRY(__uuidof(CredentialDialogMachineClass), CredentialDialogMachine) | |
73 END_OBJECT_MAP() | |
74 | |
75 _ATL_OBJMAP_ENTRY* GoogleUpdate::GetObjectMap() { | |
76 if (mode_ == kUpdate3Mode && !is_machine_) { | |
77 return object_map_update3_user_mode; | |
78 } | |
79 | |
80 if (mode_ == kBrokerMode && is_machine_) { | |
81 return object_map_broker_machine_mode; | |
82 } | |
83 | |
84 if (mode_ == kOnDemandMode && !is_machine_) { | |
85 return object_map_ondemand_user_mode; | |
86 } | |
87 | |
88 if (mode_ == kOnDemandMode && is_machine_) { | |
89 return object_map_ondemand_machine_mode; | |
90 } | |
91 | |
92 return NULL; | |
93 } | |
94 | |
95 GoogleUpdate::GoogleUpdate(bool is_machine, ComServerMode mode) | |
96 : is_machine_(is_machine), mode_(mode) { | |
97 // Disable the delay on shutdown mechanism in CAtlExeModuleT. | |
98 m_bDelayShutdown = false; | |
99 } | |
100 | |
101 GoogleUpdate::~GoogleUpdate() { | |
102 // GoogleUpdate is typically created on the stack. We reset the _pAtlModule | |
103 // here, to allow for cases such as /RegServer, where multiple instances of | |
104 // GoogleUpdate are created and destroyed serially. | |
105 _pAtlModule = NULL; | |
106 } | |
107 | |
108 HRESULT GoogleUpdate::Main() { | |
109 HRESULT hr = E_FAIL; | |
110 if (!ParseCommandLine(::GetCommandLine(), &hr)) { | |
111 // This was either /RegServer or /UnregServer. Return early. | |
112 return hr; | |
113 } | |
114 | |
115 hr = InitializeServerSecurity(is_machine_); | |
116 if (FAILED(hr)) { | |
117 return hr; | |
118 } | |
119 | |
120 DisableCOMExceptionHandling(); | |
121 | |
122 // TODO(omaha3): We do not call worker_->Run() from anywhere. This means that | |
123 // the ThreadPool and the ShutdownHandler within the Worker are not | |
124 // initialized. We need to eventually fix this. | |
125 | |
126 CORE_LOG(L2, (_T("[Calling CAtlExeModuleT<GoogleUpdate>::WinMain]"))); | |
127 return CAtlExeModuleT<GoogleUpdate>::WinMain(0); | |
128 } | |
129 | |
130 HRESULT GoogleUpdate::RegisterClassObjects(DWORD, DWORD) throw() { | |
131 CORE_LOG(L3, (_T("[RegisterClassObjects]"))); | |
132 | |
133 for (_ATL_OBJMAP_ENTRY* entry = GetObjectMap(); | |
134 entry && entry->pclsid != NULL; | |
135 entry++) { | |
136 HRESULT hr = entry->RegisterClassObject(CLSCTX_LOCAL_SERVER, | |
137 REGCLS_MULTIPLEUSE | | |
138 REGCLS_SUSPENDED); | |
139 if (FAILED(hr)) { | |
140 CORE_LOG(LE, (_T("[RegisterClassObject failed][%s][0x%x]"), | |
141 GuidToString(*entry->pclsid), hr)); | |
142 return hr; | |
143 } | |
144 } | |
145 | |
146 return S_OK; | |
147 } | |
148 | |
149 HRESULT GoogleUpdate::RevokeClassObjects() throw() { | |
150 CORE_LOG(L3, (_T("[RevokeClassObjects]"))); | |
151 | |
152 for (_ATL_OBJMAP_ENTRY* entry = GetObjectMap(); | |
153 entry && entry->pclsid != NULL; | |
154 entry++) { | |
155 HRESULT hr = entry->RevokeClassObject(); | |
156 if (FAILED(hr)) { | |
157 CORE_LOG(LE, (_T("[RevokeClassObject failed][%s][0x%x]"), | |
158 GuidToString(*entry->pclsid), hr)); | |
159 return hr; | |
160 } | |
161 } | |
162 | |
163 return S_OK; | |
164 } | |
165 | |
166 HRESULT GoogleUpdate::RegisterOrUnregisterExe(bool is_register) { | |
167 CORE_LOG(L3, (_T("[RegisterOrUnregisterExe][%d]"), is_register)); | |
168 | |
169 for (_ATL_OBJMAP_ENTRY* entry = GetObjectMap(); | |
170 entry && entry->pclsid != NULL; | |
171 entry++) { | |
172 HRESULT hr = entry->pfnUpdateRegistry(is_register); | |
173 if (FAILED(hr)) { | |
174 CORE_LOG(LE, (_T("[pfnUpdateRegistry failed][%d][0x%x][%s]"), | |
175 is_register, hr, GuidToString(*entry->pclsid))); | |
176 return hr; | |
177 } | |
178 } | |
179 | |
180 return S_OK; | |
181 } | |
182 | |
183 HRESULT GoogleUpdate::RegisterOrUnregisterExe(void* data, | |
184 bool is_register) { | |
185 ASSERT1(data); | |
186 return reinterpret_cast<GoogleUpdate*>(data)->RegisterOrUnregisterExe( | |
187 is_register); | |
188 } | |
189 | |
190 HRESULT RegisterOrUnregisterProxies(void* data, bool is_register) { | |
191 ASSERT1(data); | |
192 bool is_machine = *reinterpret_cast<bool*>(data); | |
193 CORE_LOG(L3, (_T("[RegisterOrUnregisterProxies][%d][%d]"), | |
194 is_machine, is_register)); | |
195 | |
196 CPath ps_dll(app_util::GetCurrentModuleDirectory()); | |
197 if (!ps_dll.Append(is_machine ? kPSFileNameMachine : kPSFileNameUser)) { | |
198 return HRESULTFromLastError(); | |
199 } | |
200 | |
201 ASSERT1(!is_register || ps_dll.FileExists()); | |
202 HRESULT hr = is_register ? RegisterDll(ps_dll) : UnregisterDll(ps_dll); | |
203 CORE_LOG(L3, (_T("[ PS][%s][0x%x]"), ps_dll, hr)); | |
204 if (FAILED(hr) && is_register) { | |
205 return hr; | |
206 } | |
207 | |
208 return S_OK; | |
209 } | |
210 | |
211 HRESULT GoogleUpdate::RegisterServer(BOOL, const CLSID*) throw() { | |
212 HRESULT hr = goopdate_utils::RegisterOrUnregisterModule( | |
213 is_machine_, true, &RegisterOrUnregisterProxies, &is_machine_); | |
214 if (FAILED(hr)) { | |
215 return hr; | |
216 } | |
217 | |
218 return goopdate_utils::RegisterOrUnregisterModule( | |
219 is_machine_, | |
220 true, | |
221 &GoogleUpdate::RegisterOrUnregisterExe, | |
222 this); | |
223 } | |
224 | |
225 HRESULT GoogleUpdate::UnregisterServer(BOOL, const CLSID*) throw() { | |
226 HRESULT hr = goopdate_utils::RegisterOrUnregisterModule( | |
227 is_machine_, false, &GoogleUpdate::RegisterOrUnregisterExe, this); | |
228 if (FAILED(hr)) { | |
229 return hr; | |
230 } | |
231 | |
232 return goopdate_utils::RegisterOrUnregisterModule( | |
233 is_machine_, false, &RegisterOrUnregisterProxies, &is_machine_); | |
234 } | |
235 | |
236 HRESULT GoogleUpdate::PreMessageLoop(int show_cmd) throw() { | |
237 return CAtlExeModuleT<GoogleUpdate>::PreMessageLoop(show_cmd); | |
238 } | |
239 | |
240 HRESULT GoogleUpdate::PostMessageLoop() throw() { | |
241 return CAtlExeModuleT<GoogleUpdate>::PostMessageLoop(); | |
242 } | |
243 | |
244 } // namespace omaha | |
OLD | NEW |