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 // Defines the AppBundle COM object exposed by the model. | |
17 | |
18 #ifndef OMAHA_GOOPDATE_APP_BUNDLE_H_ | |
19 #define OMAHA_GOOPDATE_APP_BUNDLE_H_ | |
20 | |
21 #include <windows.h> | |
22 #include <atlbase.h> | |
23 #include <atlcom.h> | |
24 #include <atlstr.h> | |
25 #include <vector> | |
26 #include "base/basictypes.h" | |
27 #include "base/scoped_ptr.h" | |
28 #include "goopdate/omaha3_idl.h" | |
29 #include "omaha/base/constants.h" | |
30 #include "omaha/base/debug.h" | |
31 #include "omaha/base/scoped_any.h" | |
32 #include "omaha/goopdate/com_wrapper_creator.h" | |
33 #include "omaha/goopdate/model_object.h" | |
34 #include "omaha/net/proxy_auth.h" | |
35 #include "third_party/bar/shared_ptr.h" | |
36 | |
37 namespace omaha { | |
38 | |
39 // TODO(omaha): needs to figure out a smaller public interface that | |
40 // Worker expose for the model. AppBundle needs to delegate calls to Worker, | |
41 // such as Pause, Resume, Update, Install, etc... | |
42 | |
43 class App; | |
44 class Model; | |
45 class WebServicesClientInterface; | |
46 class UserWorkItem; | |
47 | |
48 namespace fsm { | |
49 | |
50 class AppBundleState; | |
51 class AppBundleStateInit; | |
52 | |
53 } // namespace fsm | |
54 | |
55 // AppBundle instances are reference-counted using shared pointers. Lifetime | |
56 // of an AppBundle instance is controlled by both external and internal | |
57 // outstanding references. External reference are the COM wrappers that depend | |
58 // on the AppBundle, including its children in the object model. | |
59 // Internal references to the AppBundle are maintained by several objects that | |
60 // depend on the bundle objects. | |
61 class AppBundle | |
62 : public ModelObject, | |
63 public enable_shared_from_this<AppBundle> { | |
64 public: | |
65 AppBundle(bool is_machine, Model* model); | |
66 virtual ~AppBundle(); | |
67 | |
68 // IAppBundle. | |
69 STDMETHOD(get_displayName)(BSTR* display_name); | |
70 STDMETHOD(put_displayName)(BSTR display_name); | |
71 STDMETHOD(get_displayLanguage)(BSTR* language); | |
72 STDMETHOD(put_displayLanguage)(BSTR language); | |
73 STDMETHOD(get_installSource)(BSTR* install_source); | |
74 STDMETHOD(put_installSource)(BSTR install_source); | |
75 STDMETHOD(get_originURL)(BSTR* origin_url); | |
76 STDMETHOD(put_originURL)(BSTR origin_url); | |
77 STDMETHOD(get_offlineDirectory)(BSTR* offline_dir); | |
78 STDMETHOD(put_offlineDirectory)(BSTR offline_dir); | |
79 STDMETHOD(get_sessionId)(BSTR* session_id); | |
80 STDMETHOD(put_sessionId)(BSTR session_id); | |
81 STDMETHOD(get_priority)(long* priority); // NOLINT | |
82 STDMETHOD(put_priority)(long priority); // NOLINT | |
83 STDMETHOD(get_Count)(long* count); // NOLINT | |
84 STDMETHOD(get_Item)(long index, App** app); // NOLINT | |
85 STDMETHOD(put_altTokens)(ULONG_PTR impersonation_token, | |
86 ULONG_PTR primary_token, | |
87 DWORD caller_proc_id); | |
88 STDMETHOD(put_parentHWND)(ULONG_PTR hwnd); | |
89 STDMETHOD(initialize)(); | |
90 STDMETHOD(createApp)(BSTR app_id, App** app); | |
91 STDMETHOD(createInstalledApp)(BSTR app_id, App** app); | |
92 STDMETHOD(createAllInstalledApps)(); | |
93 STDMETHOD(checkForUpdate)(); | |
94 STDMETHOD(download)(); | |
95 STDMETHOD(install)(); | |
96 STDMETHOD(updateAllApps)(); | |
97 STDMETHOD(stop)(); | |
98 STDMETHOD(pause)(); | |
99 STDMETHOD(resume)(); | |
100 STDMETHOD(isBusy)(VARIANT_BOOL* is_busy); | |
101 STDMETHOD(downloadPackage)(BSTR app_id, BSTR package_name); | |
102 STDMETHOD(get_currentState)(VARIANT* current_state); | |
103 | |
104 // Creates an App for each uninstalled app and adds it to | |
105 HRESULT CreateUninstalledApp(const CString& app_id, App** app); | |
106 | |
107 // Marks an asynchronous operation complete. | |
108 void CompleteAsyncCall(); | |
109 | |
110 bool IsBusy() const; | |
111 | |
112 // Returns a shared pointer to this instance of the class under the | |
113 // assumption that the instance is already managed by a shared pointer. | |
114 // This shared pointer controls the lifetime of the app bundle object and | |
115 // all its children. | |
116 ControllingPtr controlling_ptr(); | |
117 | |
118 void set_user_work_item(UserWorkItem* user_work_item); | |
119 | |
120 const CString& install_source() const { return install_source_; } | |
121 | |
122 const CString& origin_url() const { return origin_url_; } | |
123 | |
124 // Gets the impersonation token of the current COM caller. | |
125 HANDLE impersonation_token() const; | |
126 | |
127 // Gets the primary token of the current COM caller. | |
128 HANDLE primary_token() const; | |
129 | |
130 size_t GetNumberOfApps() const; | |
131 | |
132 App* GetApp(size_t index); | |
133 | |
134 WebServicesClientInterface* update_check_client(); | |
135 | |
136 bool is_machine() const; | |
137 | |
138 bool is_auto_update() const; | |
139 void set_is_auto_update(bool is_auto_update); | |
140 | |
141 bool is_offline_install() const; | |
142 | |
143 const CString& offline_dir() const; | |
144 | |
145 const CString& session_id() const; | |
146 | |
147 CString display_language() const; | |
148 | |
149 int priority() const; | |
150 | |
151 ProxyAuthConfig GetProxyAuthConfig() const; | |
152 | |
153 // Gathers accumulated event logs from all child apps and clears the | |
154 // log buffer in each app. | |
155 CString FetchAndResetLogText(); | |
156 | |
157 private: | |
158 // Sets the state for unit testing. | |
159 friend void SetAppBundleStateForUnitTest(AppBundle* app_bundle, | |
160 fsm::AppBundleState* state); | |
161 | |
162 // TODO(omaha): missing unit test. | |
163 // Sends the ping if the applications in the bundle have accumulated | |
164 // any ping events. | |
165 HRESULT SendPingEvents(); | |
166 | |
167 // These methods capture the current COM caller tokens. | |
168 HRESULT CaptureCallerImpersonationToken(); | |
169 HRESULT CaptureCallerPrimaryToken(); | |
170 | |
171 void ChangeState(fsm::AppBundleState* app_bundle_state); | |
172 | |
173 bool is_pending_non_blocking_call() const; | |
174 | |
175 CString display_name_; | |
176 CString install_source_; | |
177 CString origin_url_; | |
178 | |
179 bool is_machine_; | |
180 | |
181 // True if the bundle is an update bundle. | |
182 bool is_auto_update_; | |
183 | |
184 int priority_; | |
185 | |
186 HWND parent_hwnd_; | |
187 | |
188 CString offline_dir_; | |
189 | |
190 // Contains the session ID - a unique marker that we include with each | |
191 // server communication (update checks, pings, etc.) in a single Omaha task. | |
192 // Clients are expected to set this on a bundle before calling initialize(); | |
193 // if they don't, we will randomly generate one. | |
194 CString session_id_; | |
195 | |
196 // The current non-blocking command object if any of them is executing. | |
197 // The class only checks whether the pointer is NULL to determine if a | |
198 // non-blocking call is pending. We use a pointer because it can be useful | |
199 // for debugging. | |
200 UserWorkItem* user_work_item_; | |
201 | |
202 scoped_ptr<WebServicesClientInterface> update_check_client_; | |
203 | |
204 // The apps in the bundle. Do not add to it directly; use AddApp() instead. | |
205 std::vector<App*> apps_; | |
206 | |
207 // Uninstalled apps. Not accessible and only used to store Apps for | |
208 // uninstalled app IDs so that app uninstall pings can be sent along with | |
209 // other pings. | |
210 std::vector<App*> uninstalled_apps_; | |
211 | |
212 scoped_ptr<fsm::AppBundleState> app_bundle_state_; | |
213 | |
214 // Impersonation and primary tokens set by the client. Typically only | |
215 // set by the gupdatem service. The gupdatem service exposes a narrow | |
216 // interface to medium integrity clients. When a medium integrity client calls | |
217 // into the gupdatem service, the gupdatem service captures the token of the | |
218 // caller, and then calls put_altTokens() on the gupdate service, so that the | |
219 // gupdate service can use it for future download() and install() requests. | |
220 CAccessToken alt_impersonation_token_; | |
221 CAccessToken alt_primary_token_; | |
222 | |
223 // The current COM caller's impersonation token. | |
224 CAccessToken impersonation_token_; | |
225 | |
226 // The current COM caller's primary token. Lazy initialized at the install() | |
227 // entry point. | |
228 CAccessToken primary_token_; | |
229 | |
230 // COM caller's display language. | |
231 CString display_language_; | |
232 | |
233 friend class fsm::AppBundleState; | |
234 friend class fsm::AppBundleStateInit; | |
235 | |
236 friend class AppBundleTest; | |
237 friend class WorkerTest; | |
238 | |
239 DISALLOW_COPY_AND_ASSIGN(AppBundle); | |
240 }; | |
241 | |
242 class ATL_NO_VTABLE AppBundleWrapper | |
243 : public ComWrapper<AppBundleWrapper, AppBundle>, | |
244 public IDispatchImpl<IAppBundle, | |
245 &__uuidof(IAppBundle), | |
246 &CAtlModule::m_libid, | |
247 kMajorTypeLibVersion, | |
248 kMinorTypeLibVersion> { | |
249 public: | |
250 AppBundleWrapper(); | |
251 virtual ~AppBundleWrapper(); | |
252 | |
253 // IAppBundle. | |
254 STDMETHOD(get_displayName)(BSTR* display_name); | |
255 STDMETHOD(put_displayName)(BSTR display_name); | |
256 STDMETHOD(get_displayLanguage)(BSTR* language); | |
257 STDMETHOD(put_displayLanguage)(BSTR language); | |
258 STDMETHOD(get_installSource)(BSTR* install_source); | |
259 STDMETHOD(put_installSource)(BSTR install_source); | |
260 STDMETHOD(get_originURL)(BSTR* origin_url); | |
261 STDMETHOD(put_originURL)(BSTR origin_url); | |
262 STDMETHOD(get_offlineDirectory)(BSTR* offline_dir); | |
263 STDMETHOD(put_offlineDirectory)(BSTR offline_dir); | |
264 STDMETHOD(get_sessionId)(BSTR* session_id); | |
265 STDMETHOD(put_sessionId)(BSTR session_id); | |
266 STDMETHOD(get_priority)(long* priority); // NOLINT | |
267 STDMETHOD(put_priority)(long priority); // NOLINT | |
268 STDMETHOD(get_Count)(long* count); // NOLINT | |
269 STDMETHOD(get_Item)(long index, IDispatch** app_disp); // NOLINT | |
270 STDMETHOD(put_altTokens)(ULONG_PTR impersonation_token, | |
271 ULONG_PTR primary_token, | |
272 DWORD caller_proc_id); | |
273 STDMETHOD(put_parentHWND)(ULONG_PTR hwnd); | |
274 STDMETHOD(initialize)(); | |
275 STDMETHOD(createApp)(BSTR app_id, IDispatch** app_disp); | |
276 STDMETHOD(createInstalledApp)(BSTR app_id, IDispatch** app_disp); | |
277 STDMETHOD(createAllInstalledApps)(); | |
278 STDMETHOD(checkForUpdate)(); | |
279 STDMETHOD(download)(); | |
280 STDMETHOD(install)(); | |
281 STDMETHOD(updateAllApps)(); | |
282 STDMETHOD(stop)(); | |
283 STDMETHOD(pause)(); | |
284 STDMETHOD(resume)(); | |
285 STDMETHOD(isBusy)(VARIANT_BOOL* is_busy); | |
286 STDMETHOD(downloadPackage)(BSTR app_id, BSTR package_name); | |
287 STDMETHOD(get_currentState)(VARIANT* current_state); | |
288 | |
289 private: | |
290 BEGIN_COM_MAP(AppBundleWrapper) | |
291 COM_INTERFACE_ENTRY(IAppBundle) | |
292 COM_INTERFACE_ENTRY(IDispatch) | |
293 END_COM_MAP() | |
294 }; | |
295 | |
296 } // namespace omaha | |
297 | |
298 #endif // OMAHA_GOOPDATE_APP_BUNDLE_H_ | |
OLD | NEW |