OLD | NEW |
| (Empty) |
1 // Copyright 2009 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 #include "omaha/goopdate/app_state_error.h" | |
17 #include "omaha/base/debug.h" | |
18 #include "omaha/base/logging.h" | |
19 #include "omaha/goopdate/model.h" | |
20 | |
21 namespace omaha { | |
22 | |
23 namespace fsm { | |
24 | |
25 AppStateError::AppStateError() : AppState(STATE_ERROR) { | |
26 } | |
27 | |
28 const PingEvent* AppStateError::CreatePingEvent( | |
29 App* app, | |
30 CurrentState previous_state) const { | |
31 ASSERT1(app); | |
32 | |
33 ASSERT1(FAILED(app->error_code())); | |
34 | |
35 const PingEvent::Types event_type(app->is_update() ? | |
36 PingEvent::EVENT_UPDATE_COMPLETE : | |
37 PingEvent::EVENT_INSTALL_COMPLETE); | |
38 | |
39 const PingEvent::Results result = GetCompletionResult(*app); | |
40 | |
41 // Installer errors are reported in the ping in the case where the | |
42 // installer ran and failed. Otherwise, Omaha errors are reported. | |
43 // | |
44 // App extra codes are reported if set, otherwise the state of the state | |
45 // machine which caused the transition to the error state is encoded and | |
46 // reported. | |
47 const bool is_installer_error = | |
48 result == PingEvent::EVENT_RESULT_INSTALLER_ERROR_MSI || | |
49 result == PingEvent::EVENT_RESULT_INSTALLER_ERROR_OTHER || | |
50 result == PingEvent::EVENT_RESULT_INSTALLER_ERROR_SYSTEM; | |
51 | |
52 HRESULT error_code = S_OK; | |
53 int extra_code1 = 0; | |
54 | |
55 if (is_installer_error) { | |
56 error_code = static_cast<HRESULT>(app->installer_result_code()); | |
57 extra_code1 = app->installer_result_extra_code1(); | |
58 } else { | |
59 const int app_extra_code1 = app->error_context().extra_code1; | |
60 error_code = app->error_code(); | |
61 extra_code1 = app_extra_code1 ? app_extra_code1 : | |
62 (PingEvent::kAppStateExtraCodeMask | previous_state); | |
63 } | |
64 | |
65 // TODO(omaha): remove special case after the experiment is complete. | |
66 if (error_code == GOOPDATEDOWNLOAD_E_CACHING_FAILED || | |
67 error_code == GOOPDATEINSTALL_E_INSTALLER_FAILED_START) { | |
68 extra_code1 = error_extra_code1(); | |
69 } | |
70 | |
71 // The error completion ping is sent whenever the application ended up in | |
72 // the error state: | |
73 // * in the install case always, since any install error is final. | |
74 // * in the update case only when an update has been available. | |
75 // | |
76 // In the update case, it is possible that the code errors out before it | |
77 // discovers that an update is available. Therefore, there is a window of | |
78 // uncertainty where the client did not get far enough to know if it was | |
79 // told by the server to update or not. | |
80 const bool can_ping = app->is_install() || app->has_update_available(); | |
81 return can_ping ? new PingEvent(event_type, result, error_code, extra_code1) : | |
82 NULL; | |
83 } | |
84 | |
85 void AppStateError::DownloadComplete(App* app) { | |
86 CORE_LOG(L3, (_T("[AppStateError::DownloadComplete][0x%p]"), app)); | |
87 UNREFERENCED_PARAMETER(app); | |
88 } | |
89 | |
90 void AppStateError::MarkReadyToInstall(App* app) { | |
91 CORE_LOG(L3, (_T("[AppStateError::MarkReadyToInstall][0x%p]"), app)); | |
92 UNREFERENCED_PARAMETER(app); | |
93 } | |
94 | |
95 void AppStateError::PreUpdateCheck(App* app, | |
96 xml::UpdateRequest* update_request) { | |
97 CORE_LOG(L3, (_T("[AppStateError::PreUpdateCheck][%p]"), app)); | |
98 ASSERT1(app); | |
99 UNREFERENCED_PARAMETER(app); | |
100 UNREFERENCED_PARAMETER(update_request); | |
101 } | |
102 | |
103 void AppStateError::PostUpdateCheck(App* app, | |
104 HRESULT result, | |
105 xml::UpdateResponse* update_response) { | |
106 CORE_LOG(L3, (_T("[AppStateError::PostUpdateCheck][%p]"), app)); | |
107 ASSERT1(app); | |
108 UNREFERENCED_PARAMETER(app); | |
109 UNREFERENCED_PARAMETER(result); | |
110 UNREFERENCED_PARAMETER(update_response); | |
111 } | |
112 | |
113 void AppStateError::QueueDownload(App* app) { | |
114 CORE_LOG(L3, (_T("[AppStateError::QueueDownload][%p]"), app)); | |
115 ASSERT1(app); | |
116 UNREFERENCED_PARAMETER(app); | |
117 } | |
118 | |
119 void AppStateError::QueueDownloadOrInstall(App* app) { | |
120 CORE_LOG(L3, (_T("[AppStateError::QueueDownloadOrInstall][%p]"), app)); | |
121 ASSERT1(app); | |
122 UNREFERENCED_PARAMETER(app); | |
123 } | |
124 | |
125 void AppStateError::Download( | |
126 App* app, | |
127 DownloadManagerInterface* download_manager) { | |
128 CORE_LOG(L3, (_T("[AppStateError::Download][0x%p]"), app)); | |
129 ASSERT1(app); | |
130 ASSERT1(download_manager); | |
131 UNREFERENCED_PARAMETER(app); | |
132 UNREFERENCED_PARAMETER(download_manager); | |
133 } | |
134 | |
135 void AppStateError::QueueInstall(App* app) { | |
136 CORE_LOG(L3, (_T("[AppStateError::QueueInstall][%p]"), app)); | |
137 ASSERT1(app); | |
138 UNREFERENCED_PARAMETER(app); | |
139 } | |
140 | |
141 void AppStateError::Install( | |
142 App* app, | |
143 InstallManagerInterface* install_manager) { | |
144 CORE_LOG(L3, (_T("[AppStateError::Install][0x%p]"), app)); | |
145 ASSERT1(app); | |
146 ASSERT1(install_manager); | |
147 UNREFERENCED_PARAMETER(app); | |
148 UNREFERENCED_PARAMETER(install_manager); | |
149 } | |
150 | |
151 void AppStateError::Cancel(App* app) { | |
152 CORE_LOG(L3, (_T("[AppStateError::Cancel][0x%p]"), app)); | |
153 ASSERT1(app); | |
154 UNREFERENCED_PARAMETER(app); | |
155 } | |
156 | |
157 void AppStateError::Error(App* app, | |
158 const ErrorContext& error_context, | |
159 const CString& message) { | |
160 ASSERT1(app); | |
161 UNREFERENCED_PARAMETER(app); | |
162 UNREFERENCED_PARAMETER(error_context); | |
163 UNREFERENCED_PARAMETER(message); | |
164 CORE_LOG(L3, (_T("[app is already in the Error state]") | |
165 _T("[0x%p][app error=0x%x][this error=0x%x][%s]"), | |
166 app, app->error_code(), error_context.error_code, message)); | |
167 } | |
168 | |
169 } // namespace fsm | |
170 | |
171 } // namespace omaha | |
OLD | NEW |