| OLD | NEW |
| (Empty) |
| 1 // Copyright 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_bundle_state.h" | |
| 17 #include "omaha/base/debug.h" | |
| 18 #include "omaha/base/error.h" | |
| 19 #include "omaha/base/logging.h" | |
| 20 #include "omaha/common/web_services_client.h" | |
| 21 #include "omaha/goopdate/app_bundle_state_busy.h" | |
| 22 #include "omaha/goopdate/model.h" | |
| 23 | |
| 24 namespace omaha { | |
| 25 | |
| 26 namespace fsm { | |
| 27 | |
| 28 HRESULT AppBundleState::put_altTokens(AppBundle* app_bundle, | |
| 29 ULONG_PTR impersonation_token, | |
| 30 ULONG_PTR primary_token, | |
| 31 DWORD caller_proc_id) { | |
| 32 UNREFERENCED_PARAMETER(impersonation_token); | |
| 33 UNREFERENCED_PARAMETER(primary_token); | |
| 34 UNREFERENCED_PARAMETER(caller_proc_id); | |
| 35 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 36 } | |
| 37 | |
| 38 HRESULT AppBundleState::put_sessionId(AppBundle* app_bundle, BSTR session_id) { | |
| 39 UNREFERENCED_PARAMETER(session_id); | |
| 40 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 41 } | |
| 42 | |
| 43 HRESULT AppBundleState::Initialize(AppBundle* app_bundle) { | |
| 44 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 45 } | |
| 46 | |
| 47 HRESULT AppBundleState::CreateApp(AppBundle* app_bundle, | |
| 48 const CString& app_id, | |
| 49 App** app) { | |
| 50 UNREFERENCED_PARAMETER(app_id); | |
| 51 UNREFERENCED_PARAMETER(app); | |
| 52 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 53 } | |
| 54 | |
| 55 HRESULT AppBundleState::CreateInstalledApp(AppBundle* app_bundle, | |
| 56 const CString& app_id, | |
| 57 App** app) { | |
| 58 UNREFERENCED_PARAMETER(app_id); | |
| 59 UNREFERENCED_PARAMETER(app); | |
| 60 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 61 } | |
| 62 | |
| 63 HRESULT AppBundleState::CreateAllInstalledApps(AppBundle* app_bundle) { | |
| 64 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 65 } | |
| 66 | |
| 67 HRESULT AppBundleState::CheckForUpdate(AppBundle* app_bundle) { | |
| 68 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 69 } | |
| 70 | |
| 71 HRESULT AppBundleState::Download(AppBundle* app_bundle) { | |
| 72 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 73 } | |
| 74 | |
| 75 HRESULT AppBundleState::Install(AppBundle* app_bundle) { | |
| 76 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 77 } | |
| 78 | |
| 79 HRESULT AppBundleState::UpdateAllApps(AppBundle* app_bundle) { | |
| 80 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 81 } | |
| 82 | |
| 83 HRESULT AppBundleState::Stop(AppBundle* app_bundle) { | |
| 84 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 85 } | |
| 86 | |
| 87 HRESULT AppBundleState::Pause(AppBundle* app_bundle) { | |
| 88 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 89 } | |
| 90 | |
| 91 HRESULT AppBundleState::Resume(AppBundle* app_bundle) { | |
| 92 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 93 } | |
| 94 | |
| 95 HRESULT AppBundleState::DownloadPackage(AppBundle* app_bundle, | |
| 96 const CString& app_id, | |
| 97 const CString& package_name) { | |
| 98 UNREFERENCED_PARAMETER(app_id); | |
| 99 UNREFERENCED_PARAMETER(package_name); | |
| 100 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 101 } | |
| 102 | |
| 103 HRESULT AppBundleState::CompleteAsyncCall(AppBundle* app_bundle) { | |
| 104 return HandleInvalidStateTransition(app_bundle, _T(__FUNCTION__)); | |
| 105 } | |
| 106 | |
| 107 bool AppBundleState::IsBusy() const { | |
| 108 return false; | |
| 109 } | |
| 110 | |
| 111 void AppBundleState::AddAppToBundle(AppBundle* app_bundle, App* app) { | |
| 112 ASSERT1(app_bundle); | |
| 113 ASSERT1(app_bundle->model()->IsLockedByCaller()); | |
| 114 app_bundle->apps_.push_back(app); | |
| 115 } | |
| 116 | |
| 117 bool AppBundleState::IsPendingNonBlockingCall(AppBundle* app_bundle) { | |
| 118 ASSERT1(app_bundle); | |
| 119 return app_bundle->is_pending_non_blocking_call(); | |
| 120 } | |
| 121 | |
| 122 HRESULT AppBundleState::DoDownloadPackage(AppBundle* app_bundle, | |
| 123 const CString& app_id, | |
| 124 const CString& package_name) { | |
| 125 CORE_LOG(L3, (_T("[AppBundleState::DoDownloadPackage][0x%p]"), app_bundle)); | |
| 126 ASSERT1(app_bundle); | |
| 127 ASSERT1(app_bundle->model()->IsLockedByCaller()); | |
| 128 ASSERT1(!IsPendingNonBlockingCall(app_bundle)); | |
| 129 | |
| 130 GUID app_guid = {0}; | |
| 131 HRESULT hr = StringToGuidSafe(app_id, &app_guid); | |
| 132 if (FAILED(hr)) { | |
| 133 return hr; | |
| 134 } | |
| 135 | |
| 136 App* app = NULL; | |
| 137 for (size_t i = 0; i != app_bundle->GetNumberOfApps(); ++i) { | |
| 138 App* candidate_app = app_bundle->GetApp(i); | |
| 139 if (::IsEqualGUID(candidate_app->app_guid(), app_guid)) { | |
| 140 app = candidate_app; | |
| 141 break; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 if (!app) { | |
| 146 return E_INVALIDARG; | |
| 147 } | |
| 148 | |
| 149 // Only packages of installed applications can be downloaded. | |
| 150 Package* package = NULL; | |
| 151 AppVersion* version = app->current_version(); | |
| 152 for (size_t i = 0; i != version->GetNumberOfPackages(); ++i) { | |
| 153 if (version->GetPackage(i)->filename() == package_name) { | |
| 154 package = version->GetPackage(i); | |
| 155 break; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 if (!package) { | |
| 160 return E_INVALIDARG; | |
| 161 } | |
| 162 | |
| 163 hr = app_bundle->model()->DownloadPackage(package); | |
| 164 if (FAILED(hr)) { | |
| 165 CORE_LOG(LE, (_T("[DownloadPackage failed][0x%x][0x%p]"), hr, app_bundle)); | |
| 166 return hr; | |
| 167 } | |
| 168 | |
| 169 ChangeState(app_bundle, new AppBundleStateBusy); | |
| 170 return S_OK; | |
| 171 } | |
| 172 | |
| 173 void AppBundleState::ChangeState(AppBundle* app_bundle, AppBundleState* state) { | |
| 174 ASSERT1(app_bundle); | |
| 175 ASSERT1(state); | |
| 176 ASSERT1(app_bundle->model()->IsLockedByCaller()); | |
| 177 CORE_LOG(L3, (_T("[AppBundleState::ChangeState][0x%p][from: %u][to: %u]"), | |
| 178 app_bundle, state_, state->state_)); | |
| 179 | |
| 180 app_bundle->ChangeState(state); | |
| 181 } | |
| 182 | |
| 183 HRESULT AppBundleState::HandleInvalidStateTransition( | |
| 184 AppBundle* app_bundle, | |
| 185 const TCHAR* function_name) { | |
| 186 UNREFERENCED_PARAMETER(app_bundle); | |
| 187 UNREFERENCED_PARAMETER(function_name); | |
| 188 ASSERT1(app_bundle); | |
| 189 ASSERT1(app_bundle->model()->IsLockedByCaller()); | |
| 190 CORE_LOG(LE, (_T("[Invalid state transition][%s called while in %u]"), | |
| 191 function_name, state_)); | |
| 192 return GOOPDATE_E_CALL_UNEXPECTED; | |
| 193 } | |
| 194 | |
| 195 } // namespace fsm | |
| 196 | |
| 197 } // namespace omaha | |
| OLD | NEW |