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 #include "omaha/goopdate/app_state.h" | |
17 #include "omaha/base/debug.h" | |
18 #include "omaha/base/error.h" | |
19 #include "omaha/base/logging.h" | |
20 #include "omaha/goopdate/app_state_error.h" | |
21 #include "omaha/goopdate/model.h" | |
22 #include "omaha/goopdate/server_resource.h" | |
23 #include "omaha/goopdate/string_formatter.h" | |
24 | |
25 namespace omaha { | |
26 | |
27 namespace fsm { | |
28 | |
29 const PingEvent* AppState::CreatePingEvent(App* app, | |
30 CurrentState previous_state) const { | |
31 UNREFERENCED_PARAMETER(app); | |
32 UNREFERENCED_PARAMETER(previous_state); | |
33 return NULL; | |
34 } | |
35 | |
36 void AppState::QueueUpdateCheck(App* app) { | |
37 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
38 } | |
39 | |
40 void AppState::PreUpdateCheck(App* app, xml::UpdateRequest* update_request) { | |
41 UNREFERENCED_PARAMETER(update_request); | |
42 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
43 } | |
44 | |
45 void AppState::PostUpdateCheck(App* app, | |
46 HRESULT result, | |
47 xml::UpdateResponse* update_response) { | |
48 UNREFERENCED_PARAMETER(result); | |
49 UNREFERENCED_PARAMETER(update_response); | |
50 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
51 } | |
52 | |
53 void AppState::QueueDownload(App* app) { | |
54 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
55 } | |
56 | |
57 void AppState::QueueDownloadOrInstall(App* app) { | |
58 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
59 } | |
60 | |
61 void AppState::Download(App* app, DownloadManagerInterface* download_manager) { | |
62 ASSERT1(download_manager); | |
63 UNREFERENCED_PARAMETER(download_manager); | |
64 // Must acquire the lock here because app does not acquire it before calling | |
65 // this method. | |
66 __mutexScope(app->model()->lock()); | |
67 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
68 } | |
69 | |
70 void AppState::Downloading(App* app) { | |
71 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
72 } | |
73 | |
74 void AppState::DownloadComplete(App* app) { | |
75 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
76 } | |
77 | |
78 void AppState::MarkReadyToInstall(App* app) { | |
79 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
80 } | |
81 | |
82 void AppState::QueueInstall(App* app) { | |
83 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
84 } | |
85 | |
86 void AppState::Install(App* app, InstallManagerInterface* install_manager) { | |
87 ASSERT1(install_manager); | |
88 UNREFERENCED_PARAMETER(install_manager); | |
89 // Must acquire the lock here because app does not acquire it before calling | |
90 // this method. | |
91 __mutexScope(app->model()->lock()); | |
92 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
93 } | |
94 | |
95 void AppState::Installing(App* app) { | |
96 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
97 } | |
98 | |
99 void AppState::ReportInstallerComplete(App* app, | |
100 const InstallerResultInfo& result_info) { | |
101 UNREFERENCED_PARAMETER(result_info); | |
102 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
103 } | |
104 | |
105 void AppState::Pause(App* app) { | |
106 HandleInvalidStateTransition(app, _T(__FUNCTION__)); | |
107 } | |
108 | |
109 // TODO(omaha3): If Cancel is not valid during certain states, override this in | |
110 // those states and decide what should happen. Consider Worker::StopAsync(). | |
111 void AppState::Cancel(App* app) { | |
112 ASSERT1(app); | |
113 ASSERT1(app->model()->IsLockedByCaller()); | |
114 CORE_LOG(L3, (_T("[AppState::Cancel][0x%p]"), app)); | |
115 | |
116 const HRESULT hr = GOOPDATE_E_CANCELLED; | |
117 CString message; | |
118 | |
119 StringFormatter formatter(app->app_bundle()->display_language()); | |
120 VERIFY1(SUCCEEDED(formatter.LoadString(IDS_CANCELED, &message))); | |
121 app->SetError(ErrorContext(hr), message); | |
122 ChangeState(app, new AppStateError); | |
123 } | |
124 | |
125 void AppState::Error(App* app, | |
126 const ErrorContext& error_context, | |
127 const CString& message) { | |
128 ASSERT1(app); | |
129 ASSERT1(app->model()->IsLockedByCaller()); | |
130 CORE_LOG(LE, (_T("[AppState::Error][0x%p][0x%08x][%s]"), | |
131 app, error_context.error_code, message)); | |
132 | |
133 app->SetError(error_context, message); | |
134 ChangeState(app, new AppStateError); | |
135 } | |
136 | |
137 void AppState::ChangeState(App* app, AppState* app_state) { | |
138 ASSERT1(app); | |
139 ASSERT1(app_state); | |
140 ASSERT1(app->model()->IsLockedByCaller()); | |
141 CORE_LOG(L3, (_T("[AppState::ChangeState][0x%p][%d]"), | |
142 app, app_state->state())); | |
143 | |
144 app->ChangeState(app_state); | |
145 } | |
146 | |
147 // Avoid infinite recursion by calling the base class's Error() method. | |
148 void AppState::HandleInvalidStateTransition(App* app, | |
149 const TCHAR* function_name) { | |
150 UNREFERENCED_PARAMETER(function_name); | |
151 ASSERT(false, (_T("Invalid state transition: %s called while in state %u."), | |
152 function_name, state_)); | |
153 const HRESULT hr = GOOPDATE_E_INVALID_STATE_TRANSITION; | |
154 StringFormatter formatter(app->app_bundle()->display_language()); | |
155 CString message; | |
156 VERIFY1(SUCCEEDED(formatter.LoadString(IDS_INSTALL_FAILED, &message))); | |
157 AppState::Error(app, ErrorContext(hr, state_), message); | |
158 } | |
159 | |
160 PingEvent::Results AppState::GetCompletionResult(const App& app) { | |
161 ASSERT1(app.model()->IsLockedByCaller()); | |
162 return app.completion_result_; | |
163 } | |
164 | |
165 } // namespace fsm | |
166 | |
167 } // namespace omaha | |
OLD | NEW |