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 #ifndef OMAHA_CLIENT_INSTALL_PROGRESS_OBSERVER_H_ | |
17 #define OMAHA_CLIENT_INSTALL_PROGRESS_OBSERVER_H_ | |
18 | |
19 #include <windows.h> | |
20 #include <atlstr.h> | |
21 #include <vector> | |
22 | |
23 #include "omaha/base/safe_format.h" | |
24 #include "omaha/base/time.h" | |
25 | |
26 namespace omaha { | |
27 | |
28 // TODO(omaha3): These specify the completion UI to display not the job | |
29 // result as they did in Omaha 2. | |
30 // Some of them may not be necessary depending on how information is | |
31 // communicated to the observer. For example, should the COM API allow reboot/ | |
32 // restart browser AND launchcmd? | |
33 // If we keep this enum, rename to something like CompletionTypes to make it | |
34 // clear that it is describing the desired behavior of the observer. This also | |
35 // differentiates the name from LegacyCompetionCodes. | |
36 // TODO(omaha): If the codes below change, need a conversion method to convert | |
37 // to LegacyCompletionCodes. | |
38 typedef enum { | |
39 COMPLETION_CODE_SUCCESS = 1, | |
40 COMPLETION_CODE_EXIT_SILENTLY, | |
41 COMPLETION_CODE_ERROR = COMPLETION_CODE_SUCCESS + 2, | |
42 COMPLETION_CODE_RESTART_ALL_BROWSERS, | |
43 COMPLETION_CODE_REBOOT, | |
44 COMPLETION_CODE_RESTART_BROWSER, | |
45 COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY, | |
46 COMPLETION_CODE_REBOOT_NOTICE_ONLY, | |
47 COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY, | |
48 COMPLETION_CODE_LAUNCH_COMMAND, | |
49 COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND, | |
50 COMPLETION_CODE_INSTALL_FINISHED_BEFORE_CANCEL, | |
51 } CompletionCodes; | |
52 | |
53 inline bool IsCompletionCodeSuccess(CompletionCodes completion_code) { | |
54 switch (completion_code) { | |
55 case COMPLETION_CODE_SUCCESS: | |
56 case COMPLETION_CODE_EXIT_SILENTLY: | |
57 case COMPLETION_CODE_RESTART_ALL_BROWSERS: | |
58 case COMPLETION_CODE_REBOOT: | |
59 case COMPLETION_CODE_RESTART_BROWSER: | |
60 case COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY: | |
61 case COMPLETION_CODE_REBOOT_NOTICE_ONLY: | |
62 case COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY: | |
63 case COMPLETION_CODE_LAUNCH_COMMAND: | |
64 case COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND: | |
65 case COMPLETION_CODE_INSTALL_FINISHED_BEFORE_CANCEL: | |
66 return true; | |
67 | |
68 case COMPLETION_CODE_ERROR: | |
69 default: | |
70 return false; | |
71 } | |
72 } | |
73 | |
74 struct AppCompletionInfo { | |
75 CString display_name; | |
76 CString app_id; | |
77 CString completion_message; | |
78 CompletionCodes completion_code; | |
79 HRESULT error_code; | |
80 int extra_code1; | |
81 uint32 installer_result_code; | |
82 bool is_canceled; | |
83 bool is_noupdate; // noupdate response from server | |
84 CString post_install_launch_command_line; | |
85 CString post_install_url; | |
86 | |
87 AppCompletionInfo() : completion_code(COMPLETION_CODE_SUCCESS), | |
88 error_code(S_OK), | |
89 extra_code1(0), | |
90 installer_result_code(0), | |
91 is_canceled(false), | |
92 is_noupdate(false) {} | |
93 | |
94 #ifdef DEBUG | |
95 CString ToString() const { | |
96 CString result; | |
97 SafeCStringFormat(&result, | |
98 _T("[AppCompletionInfo][%s][%s][0x%x][%d][%d][%d][%d][cmd_line=%s]"), | |
99 app_id, completion_message, error_code, extra_code1, | |
100 installer_result_code, is_canceled, is_noupdate, | |
101 post_install_launch_command_line); | |
102 return result; | |
103 } | |
104 #endif | |
105 }; | |
106 | |
107 struct ObserverCompletionInfo { | |
108 CompletionCodes completion_code; | |
109 CString completion_text; | |
110 CString help_url; | |
111 std::vector<AppCompletionInfo> apps_info; | |
112 | |
113 explicit ObserverCompletionInfo(CompletionCodes code) | |
114 : completion_code(code) {} | |
115 | |
116 #ifdef DEBUG | |
117 CString ToString() const { | |
118 CString result; | |
119 SafeCStringFormat(&result, _T("[ObserverCompletionInfo][code=%d][text=%s]"), | |
120 completion_code, completion_text); | |
121 for (size_t i = 0; i < apps_info.size(); ++i) { | |
122 result.AppendFormat(_T("[%s]"), apps_info[i].ToString()); | |
123 } | |
124 return result; | |
125 } | |
126 #endif | |
127 }; | |
128 | |
129 // TODO(omaha3): This is bundle-centric. Add support for individual app-updates | |
130 // when we have a better idea of the new bundle-supporting UI. | |
131 class InstallProgressObserver { | |
132 public: | |
133 virtual ~InstallProgressObserver() {} | |
134 virtual void OnCheckingForUpdate() = 0; | |
135 virtual void OnUpdateAvailable(const CString& app_name, | |
136 const CString& version_string) = 0; | |
137 virtual void OnWaitingToDownload(const CString& app_name) = 0; | |
138 virtual void OnDownloading(const CString& app_name, | |
139 int time_remaining_ms, | |
140 int pos) = 0; | |
141 virtual void OnWaitingRetryDownload(const CString& app_name, | |
142 time64 next_retry_time) = 0; | |
143 virtual void OnWaitingToInstall(const CString& app_name, | |
144 bool* can_start_install) = 0; | |
145 virtual void OnInstalling(const CString& app_name) = 0; | |
146 virtual void OnPause() = 0; | |
147 virtual void OnComplete(const ObserverCompletionInfo& observer_info) = 0; | |
148 }; | |
149 | |
150 } // namespace omaha | |
151 | |
152 #endif // OMAHA_CLIENT_INSTALL_PROGRESS_OBSERVER_H_ | |
OLD | NEW |