Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: goopdate/app.h

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_update/winmain.cc ('k') | goopdate/app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 App COM object exposed by the model. App tracks two versions:
17 // - the version currently installed
18 // - the future version to be updated to, if such a version exists
19
20 #ifndef OMAHA_GOOPDATE_APP_H_
21 #define OMAHA_GOOPDATE_APP_H_
22
23 #include <atlbase.h>
24 #include <atlcom.h>
25 #include "base/basictypes.h"
26 #include "base/scoped_ptr.h"
27 #include "goopdate/omaha3_idl.h"
28 #include "omaha/base/browser_utils.h"
29 #include "omaha/base/constants.h"
30 #include "omaha/common/const_goopdate.h"
31 #include "omaha/common/ping_event.h"
32 #include "omaha/goopdate/com_wrapper_creator.h"
33 #include "omaha/goopdate/installer_result_info.h"
34 #include "omaha/goopdate/model_object.h"
35
36 namespace omaha {
37
38 // Stores the error codes associated with a particular error.
39 struct ErrorContext {
40 ErrorContext() : error_code(S_OK), extra_code1(0) {}
41 explicit ErrorContext(HRESULT hr, int code1 = 0)
42 : error_code(hr),
43 extra_code1(code1) {}
44
45 HRESULT error_code;
46 int extra_code1;
47
48 // Add more extra codes here as needed.
49 };
50
51 class DownloadManagerInterface;
52 class InstallManagerInterface;
53
54 namespace fsm {
55
56 class AppState;
57
58 } // namespace fsm
59
60 namespace xml {
61
62 class UpdateRequest;
63 class UpdateResponse;
64
65 } // namespace xml
66
67 class AppBundle;
68 class AppVersion;
69 class CurrentAppState;
70
71 class App : public ModelObject {
72 public:
73 App(const GUID& app_guid, bool is_update, AppBundle* app_bundle);
74 virtual ~App();
75
76 AppVersion* current_version();
77 const AppVersion* current_version() const;
78
79 AppVersion* next_version();
80 const AppVersion* next_version() const;
81
82 AppBundle* app_bundle();
83 const AppBundle* app_bundle() const;
84
85 CString app_guid_string() const;
86
87 // TODO(omaha): refactor so that the app guid setter is only used by tests.
88 GUID app_guid() const;
89 void set_app_guid(const GUID& app_guid);
90
91 CString language() const;
92
93 bool is_eula_accepted() const;
94
95 CString display_name() const;
96
97 CurrentState state() const;
98
99 bool is_install() const { return !is_update(); }
100 bool is_update() const;
101
102 bool has_update_available() const;
103 void set_has_update_available(bool has_update_available);
104
105 GUID iid() const;
106
107 CString client_id() const;
108
109 CString GetExperimentLabels() const;
110
111 CString referral_id() const;
112
113 BrowserType browser_type() const;
114
115 Tristate usage_stats_enable() const;
116
117 CString client_install_data() const;
118
119 CString server_install_data() const;
120 void set_server_install_data(const CString& server_install_data);
121
122 CString brand_code() const;
123
124 uint32 install_time_diff_sec() const;
125
126 ActiveStates did_run() const;
127
128 int days_since_last_active_ping() const;
129 void set_days_since_last_active_ping(int days);
130
131 int days_since_last_roll_call() const;
132 void set_days_since_last_roll_call(int days);
133
134 CString ap() const;
135
136 CString tt_token() const;
137
138 CString server_install_data_index() const;
139
140 HRESULT error_code() const;
141
142 ErrorContext error_context() const;
143
144 int installer_result_code() const;
145
146 int installer_result_extra_code1() const;
147
148 const PingEventVector& ping_events() const;
149
150 AppVersion* working_version();
151 const AppVersion* working_version() const;
152
153 // IApp.
154 STDMETHOD(get_appId)(BSTR* app_id);
155
156 STDMETHOD(get_pv)(BSTR* pv);
157 STDMETHOD(put_pv)(BSTR pv);
158
159 STDMETHOD(get_language)(BSTR* language);
160 STDMETHOD(put_language)(BSTR language);
161
162 STDMETHOD(get_ap)(BSTR* ap);
163 STDMETHOD(put_ap)(BSTR ap);
164
165 STDMETHOD(get_ttToken)(BSTR* tt_token);
166 STDMETHOD(put_ttToken)(BSTR tt_token);
167
168 STDMETHOD(get_iid)(BSTR* iid);
169 STDMETHOD(put_iid)(BSTR iid);
170
171 STDMETHOD(get_brandCode)(BSTR* brand_code);
172 STDMETHOD(put_brandCode)(BSTR brand_code);
173
174 STDMETHOD(get_clientId)(BSTR* client_id);
175 STDMETHOD(put_clientId)(BSTR client_id);
176
177 STDMETHOD(get_labels)(BSTR* labels);
178 STDMETHOD(put_labels)(BSTR labels);
179
180 STDMETHOD(get_referralId)(BSTR* referral_id);
181 STDMETHOD(put_referralId)(BSTR referral_id);
182
183 STDMETHOD(get_installTimeDiffSec)(UINT* install_time_diff_sec);
184
185 STDMETHOD(get_isEulaAccepted)(VARIANT_BOOL* is_eula_accepted);
186 STDMETHOD(put_isEulaAccepted)(VARIANT_BOOL is_eula_accepted);
187
188 STDMETHOD(get_displayName)(BSTR* display_name);
189 STDMETHOD(put_displayName)(BSTR display_name);
190
191 STDMETHOD(get_browserType)(UINT* browser_type);
192 STDMETHOD(put_browserType)(UINT browser_type);
193
194 STDMETHOD(get_clientInstallData)(BSTR* data);
195 STDMETHOD(put_clientInstallData)(BSTR data);
196
197 STDMETHOD(get_serverInstallDataIndex)(BSTR* index);
198 STDMETHOD(put_serverInstallDataIndex)(BSTR index);
199
200 STDMETHOD(get_usageStatsEnable)(UINT* usage_stats_enable);
201 STDMETHOD(put_usageStatsEnable)(UINT usage_stats_enable);
202
203 STDMETHOD(get_currentState)(IDispatch** current_state);
204
205 // Sets the error context and the completion message.
206 void SetNoUpdate(const ErrorContext& error_context, const CString& message);
207 void SetError(const ErrorContext& error_context, const CString& message);
208
209 // Records the details of the installer success or failure.
210 void SetInstallerResult(const InstallerResultInfo& result_info);
211
212 // Gets the appropriate installer data regardless of the source. Only valid
213 // in STATE_UPDATE_AVAILABLE and later.
214 CString GetInstallData() const;
215
216
217 //
218 // App state machine transition conditions. These functions make
219 // the application change states.
220 //
221
222 // Sets the app to Waiting To Check.
223 void QueueUpdateCheck();
224
225 // Adds the app to the update request.
226 void PreUpdateCheck(xml::UpdateRequest* update_request);
227
228 // Processes the update response for the app.
229 void PostUpdateCheck(HRESULT result, xml::UpdateResponse* update_response);
230
231 // Sets the app to Waiting To Download.
232 void QueueDownload();
233
234 // Sets the app to Waiting To Download or Waiting To Install depending on the
235 // current state.
236 void QueueDownloadOrInstall();
237
238 // Initiates download of the app if necessary.
239 void Download(DownloadManagerInterface* download_manager);
240
241 // Reports that the download is in progress. May be called multiple times.
242 void Downloading();
243
244 // Reports that all packages have been downloaded.
245 void DownloadComplete();
246
247 // Sets the app to Ready To install.
248 void MarkReadyToInstall();
249
250 // Sets the app to Waiting To Install.
251 void QueueInstall();
252
253 // Initiates installation of the app.
254 void Install(InstallManagerInterface* install_manager);
255
256 // Reports that the install is in progress. May be called multiple times.
257 void Installing();
258
259 // Reports that the app installer has completed. Can be success or failure.
260 void ReportInstallerComplete(const InstallerResultInfo& result_info);
261
262 // TODO(omaha3): What does this pause?
263 void Pause();
264
265 // Cancels the app install.
266 void Cancel();
267
268 // Stops installation in the Error state.
269 void Error(const ErrorContext& error_context, const CString& message);
270
271 // For logging support.
272 CString FetchAndResetLogText();
273 void LogTextAppendFormat(const TCHAR* format, ...);
274
275 // Adds an event to the app's ping, which is sent when the bundle is
276 // destroyed. In most cases, pings should be added in
277 // AppState::CreatePingEvent().
278 void AddPingEvent(const PingEventPtr& ping_event);
279
280 // Returns an error if update/install, as determined by is_update_, is
281 // disabled by Group Policy.
282 HRESULT CheckGroupPolicy() const;
283
284 // Sets current time as download start time.
285 void SetDownloadStartTime();
286
287 // Sets current time as download complete time.
288 void SetDownloadCompleteTime();
289
290 // Updates num bytes downloaded by adding newly downloaded bytes.
291 void UpdateNumBytesDownloaded(uint64 num_bytes);
292
293 // Returns how long it takes for the download manager to download this app.
294 int GetDownloadTimeMs() const;
295
296 // Returns how many bytes are actually downloaded.
297 uint64 num_bytes_downloaded() const;
298
299 // Returns the size sum of all packages for this app.
300 uint64 GetPackagesTotalSize() const;
301
302 private:
303 // TODO(omaha): accessing directly the data members bypasses locking. Review
304 // the places where members are accessed by friends and check the caller locks
305 // before going directly for the private members.
306 friend class AppManager;
307 friend class AppManagerTestBase;
308
309 // TODO(omaha3): Maybe use a mock in these tests instead.
310 friend class InstallManagerInstallAppTest;
311
312 friend class fsm::AppState;
313
314 // Sets the app state for unit testing.
315 friend void SetAppStateForUnitTest(App* app, fsm::AppState* state);
316
317 HRESULT GetDownloadProgress(uint64* bytes_downloaded,
318 uint64* bytes_total,
319 LONG* time_remaining_ms,
320 uint64* next_retry_time);
321
322 void ChangeState(fsm::AppState* app_state);
323
324 scoped_ptr<fsm::AppState> app_state_;
325
326 scoped_ptr<AppVersion> current_version_;
327 scoped_ptr<AppVersion> next_version_;
328
329 // Alias to the version of the app that is being modified.
330 AppVersion* working_version_;
331
332 PingEventVector ping_events_;
333
334 CString event_log_text_;
335
336 // Weak reference to the containing bundle.
337 AppBundle* app_bundle_;
338
339 // True if the app is in the update scenario.
340 const bool is_update_;
341
342 // True if the server responded that an update is available for the app.
343 // This can happen in both install and update cases.
344 bool has_update_available_;
345
346 GUID app_guid_;
347 CString pv_;
348
349 // These values are stored in Clients. language can be in ClientState too.
350 CString language_;
351 CString display_name_;
352
353 // These values are stored in ClientState.
354 CString ap_;
355 CString tt_token_;
356 GUID iid_;
357 CString brand_code_;
358 CString client_id_;
359 // TODO(omaha3): Rename member and registry value to match the COM property.
360 CString referral_id_;
361 uint32 install_time_diff_sec_;
362 Tristate is_eula_accepted_;
363 BrowserType browser_type_;
364 int days_since_last_active_ping_;
365 int days_since_last_roll_call_;
366
367 // This value is stored in ClientState but not currently populated from there.
368 Tristate usage_stats_enable_;
369
370 // This value is stored by the clients in one of several registry locations.
371 ActiveStates did_run_;
372
373 // This value is not currently persisted in the registry.
374 CString server_install_data_index_;
375
376 // Contains the installer data string specified by the client (usually
377 // contained in /appdata).
378 CString client_install_data_;
379
380 // Contains the installer data string returned by the server for
381 // server_install_data_index_.
382 CString server_install_data_;
383
384 bool is_canceled_;
385 ErrorContext error_context_;
386 CString completion_message_;
387 PingEvent::Results completion_result_;
388 int installer_result_code_;
389 int installer_result_extra_code1_;
390 CString post_install_launch_command_line_;
391 CString post_install_url_;
392 PostInstallAction post_install_action_;
393
394 uint64 previous_total_download_bytes_;
395
396 // Values for download metrics.
397 uint64 download_start_time_ms_;
398 uint64 download_complete_time_ms_;
399 uint64 num_bytes_downloaded_;
400
401 DISALLOW_COPY_AND_ASSIGN(App);
402 };
403
404 class ATL_NO_VTABLE AppWrapper
405 : public ComWrapper<AppWrapper, App>,
406 public IDispatchImpl<IApp,
407 &__uuidof(IApp),
408 &CAtlModule::m_libid,
409 kMajorTypeLibVersion,
410 kMinorTypeLibVersion> {
411 public:
412 // IApp.
413 STDMETHOD(get_currentVersion)(IDispatch** current);
414 STDMETHOD(get_nextVersion)(IDispatch** next);
415 STDMETHOD(get_currentState)(IDispatch** current_state_disp);
416
417 STDMETHOD(get_appId)(BSTR* app_id);
418
419 STDMETHOD(get_pv)(BSTR* pv);
420 STDMETHOD(put_pv)(BSTR pv);
421
422 STDMETHOD(get_language)(BSTR* language);
423 STDMETHOD(put_language)(BSTR language);
424
425 STDMETHOD(get_ap)(BSTR* ap);
426 STDMETHOD(put_ap)(BSTR ap);
427
428 STDMETHOD(get_ttToken)(BSTR* tt_token);
429 STDMETHOD(put_ttToken)(BSTR tt_token);
430
431 STDMETHOD(get_iid)(BSTR* iid);
432 STDMETHOD(put_iid)(BSTR iid);
433
434 STDMETHOD(get_brandCode)(BSTR* brand_code);
435 STDMETHOD(put_brandCode)(BSTR brand_code);
436
437 STDMETHOD(get_clientId)(BSTR* client_id);
438 STDMETHOD(put_clientId)(BSTR client_id);
439
440 STDMETHOD(get_labels)(BSTR* labels);
441 STDMETHOD(put_labels)(BSTR labels);
442
443 STDMETHOD(get_referralId)(BSTR* referral_id);
444 STDMETHOD(put_referralId)(BSTR referral_id);
445
446 STDMETHOD(get_installTimeDiffSec)(UINT* install_time_diff_sec);
447
448 STDMETHOD(get_isEulaAccepted)(VARIANT_BOOL* is_eula_accepted);
449 STDMETHOD(put_isEulaAccepted)(VARIANT_BOOL is_eula_accepted);
450
451 STDMETHOD(get_displayName)(BSTR* display_name);
452 STDMETHOD(put_displayName)(BSTR display_name);
453
454 STDMETHOD(get_browserType)(UINT* browser_type);
455 STDMETHOD(put_browserType)(UINT browser_type);
456
457 STDMETHOD(get_clientInstallData)(BSTR* data);
458 STDMETHOD(put_clientInstallData)(BSTR data);
459
460 STDMETHOD(get_serverInstallDataIndex)(BSTR* index);
461 STDMETHOD(put_serverInstallDataIndex)(BSTR index);
462
463 STDMETHOD(get_usageStatsEnable)(UINT* usage_stats_enable);
464 STDMETHOD(put_usageStatsEnable)(UINT usage_stats_enable);
465
466 protected:
467 AppWrapper() {}
468 virtual ~AppWrapper() {}
469
470 BEGIN_COM_MAP(AppWrapper)
471 COM_INTERFACE_ENTRY(IApp)
472 COM_INTERFACE_ENTRY(IDispatch)
473 END_COM_MAP()
474
475 private:
476 DISALLOW_COPY_AND_ASSIGN(AppWrapper);
477 };
478
479 } // namespace omaha
480
481 #endif // OMAHA_GOOPDATE_APP_H_
OLDNEW
« no previous file with comments | « google_update/winmain.cc ('k') | goopdate/app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698