| 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/current_state.h" | |
| 17 #include <atlsafe.h> | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/logging.h" | |
| 20 | |
| 21 namespace omaha { | |
| 22 | |
| 23 HRESULT CurrentAppState::Create( | |
| 24 LONG state_value, | |
| 25 const CString& available_version, | |
| 26 ULONGLONG bytes_downloaded, | |
| 27 ULONGLONG total_bytes_to_download, | |
| 28 LONG download_time_remaining_ms, | |
| 29 ULONGLONG next_retry_time, | |
| 30 LONG install_progress_percentage, | |
| 31 LONG install_time_remaining_ms, | |
| 32 bool is_canceled, | |
| 33 LONG error_code, | |
| 34 LONG extra_code1, | |
| 35 const CString& completion_message, | |
| 36 LONG installer_result_code, | |
| 37 LONG installer_result_extra_code1, | |
| 38 const CString& post_install_launch_command_line, | |
| 39 const CString& post_install_url, | |
| 40 PostInstallAction post_install_action, | |
| 41 CComObject<CurrentAppState>** state) { | |
| 42 ASSERT1(state); | |
| 43 ASSERT1(state_value); | |
| 44 | |
| 45 HRESULT hr = CComObject<CurrentAppState>::CreateInstance(state); | |
| 46 if (FAILED(hr)) { | |
| 47 return hr; | |
| 48 } | |
| 49 | |
| 50 (*state)->state_value_ = state_value; | |
| 51 (*state)->available_version_ = available_version.AllocSysString(); | |
| 52 (*state)->bytes_downloaded_ = bytes_downloaded; | |
| 53 (*state)->total_bytes_to_download_ = total_bytes_to_download; | |
| 54 (*state)->download_time_remaining_ms_ = download_time_remaining_ms; | |
| 55 (*state)->next_retry_time_ = next_retry_time; | |
| 56 (*state)->install_progress_percentage_ = install_progress_percentage; | |
| 57 (*state)->install_time_remaining_ms_ = install_time_remaining_ms; | |
| 58 (*state)->is_canceled_ = is_canceled ? VARIANT_TRUE : VARIANT_FALSE; | |
| 59 (*state)->error_code_ = error_code; | |
| 60 (*state)->extra_code1_ = extra_code1; | |
| 61 (*state)->completion_message_ = completion_message.AllocSysString(); | |
| 62 (*state)->installer_result_code_ = installer_result_code; | |
| 63 (*state)->installer_result_extra_code1_ = installer_result_extra_code1; | |
| 64 (*state)->post_install_launch_command_line_ = | |
| 65 post_install_launch_command_line.AllocSysString(); | |
| 66 (*state)->post_install_url_ = post_install_url.AllocSysString(); | |
| 67 (*state)->post_install_action_ = post_install_action; | |
| 68 | |
| 69 return S_OK; | |
| 70 } | |
| 71 | |
| 72 CurrentAppState::CurrentAppState() | |
| 73 : m_bRequiresSave(TRUE), | |
| 74 state_value_(0), | |
| 75 bytes_downloaded_(0), | |
| 76 total_bytes_to_download_(0), | |
| 77 download_time_remaining_ms_(0), | |
| 78 next_retry_time_(0), | |
| 79 install_progress_percentage_(0), | |
| 80 install_time_remaining_ms_(0), | |
| 81 is_canceled_(VARIANT_FALSE), | |
| 82 error_code_(0), | |
| 83 extra_code1_(0), | |
| 84 installer_result_code_(0), | |
| 85 installer_result_extra_code1_(0), | |
| 86 post_install_action_(0) { | |
| 87 CORE_LOG(L6, (_T("[CurrentAppState::CurrentAppState()"))); | |
| 88 } | |
| 89 | |
| 90 CurrentAppState::~CurrentAppState() { | |
| 91 CORE_LOG(L6, (_T("[CurrentAppState::~CurrentAppState()"))); | |
| 92 } | |
| 93 | |
| 94 // ICurrentState. | |
| 95 // No locks are necessary because a copy of this object is returned to the | |
| 96 // client. | |
| 97 // TODO(omaha3): Perhaps we should set all the properties to valid values | |
| 98 // regardless of the stateValue. | |
| 99 // Or perhaps there are some good asserts we can and probably should do. Maybe | |
| 100 // we need a helper method such as IsStateOrLater() that would handle the | |
| 101 // non-contiguous issues, such as STATE_NO_UPDATE and STATE_PAUSED. Then, we | |
| 102 // could ASSERT1(IsStateOrLater(STATE_UPDATE_AVAILABLE)); | |
| 103 | |
| 104 STDMETHODIMP CurrentAppState::get_stateValue(LONG* state_value) { | |
| 105 ASSERT1(state_value); | |
| 106 | |
| 107 *state_value = state_value_; | |
| 108 CORE_LOG(L6, (_T("[CurrentAppState::get_stateValue][%d]"), state_value_)); | |
| 109 return S_OK; | |
| 110 } | |
| 111 | |
| 112 STDMETHODIMP CurrentAppState::get_availableVersion(BSTR* available_version) { | |
| 113 ASSERT1(available_version); | |
| 114 | |
| 115 *available_version = available_version_.Copy(); | |
| 116 return S_OK; | |
| 117 } | |
| 118 | |
| 119 STDMETHODIMP CurrentAppState::get_bytesDownloaded(ULONG* bytes_downloaded) { | |
| 120 ASSERT1(bytes_downloaded); | |
| 121 | |
| 122 // Firefox does not support uint32... | |
| 123 if (bytes_downloaded_ > kint32max) { | |
| 124 return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); | |
| 125 } | |
| 126 *bytes_downloaded = static_cast<ULONG>(bytes_downloaded_); | |
| 127 return S_OK; | |
| 128 } | |
| 129 | |
| 130 STDMETHODIMP CurrentAppState::get_totalBytesToDownload( | |
| 131 ULONG* total_bytes_to_download) { | |
| 132 ASSERT1(total_bytes_to_download); | |
| 133 | |
| 134 // Firefox does not support uint32... | |
| 135 if (total_bytes_to_download_ > kint32max) { | |
| 136 return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); | |
| 137 } | |
| 138 *total_bytes_to_download = static_cast<ULONG>(total_bytes_to_download_); | |
| 139 return S_OK; | |
| 140 } | |
| 141 | |
| 142 STDMETHODIMP CurrentAppState::get_downloadTimeRemainingMs( | |
| 143 LONG* download_time_remaining_ms) { | |
| 144 ASSERT1(download_time_remaining_ms); | |
| 145 | |
| 146 *download_time_remaining_ms = download_time_remaining_ms_; | |
| 147 return S_OK; | |
| 148 } | |
| 149 | |
| 150 STDMETHODIMP CurrentAppState::get_nextRetryTime(ULONGLONG* next_retry_time) { | |
| 151 ASSERT1(next_retry_time); | |
| 152 | |
| 153 *next_retry_time = next_retry_time_; | |
| 154 return S_OK; | |
| 155 } | |
| 156 | |
| 157 STDMETHODIMP CurrentAppState::get_installProgress( | |
| 158 LONG* install_progress_percentage) { | |
| 159 | |
| 160 ASSERT1(install_progress_percentage); | |
| 161 *install_progress_percentage = install_progress_percentage_; | |
| 162 return S_OK; | |
| 163 } | |
| 164 | |
| 165 STDMETHODIMP CurrentAppState::get_installTimeRemainingMs( | |
| 166 LONG* install_time_remaining_ms) { | |
| 167 | |
| 168 ASSERT1(install_time_remaining_ms); | |
| 169 *install_time_remaining_ms = install_time_remaining_ms_; | |
| 170 return S_OK; | |
| 171 } | |
| 172 | |
| 173 STDMETHODIMP CurrentAppState::get_isCanceled(VARIANT_BOOL* is_canceled) { | |
| 174 ASSERT1(is_canceled); | |
| 175 | |
| 176 *is_canceled = is_canceled_; | |
| 177 return S_OK; | |
| 178 } | |
| 179 | |
| 180 STDMETHODIMP CurrentAppState::get_errorCode(LONG* error_code) { | |
| 181 ASSERT1(error_code); | |
| 182 | |
| 183 *error_code = error_code_; | |
| 184 return S_OK; | |
| 185 } | |
| 186 | |
| 187 STDMETHODIMP CurrentAppState::get_extraCode1(LONG* extra_code1) { | |
| 188 ASSERT1(extra_code1); | |
| 189 | |
| 190 *extra_code1 = extra_code1_; | |
| 191 return S_OK; | |
| 192 } | |
| 193 | |
| 194 STDMETHODIMP CurrentAppState::get_completionMessage( | |
| 195 BSTR* completion_message) { | |
| 196 ASSERT1(completion_message); | |
| 197 | |
| 198 *completion_message = completion_message_.Copy(); | |
| 199 return S_OK; | |
| 200 } | |
| 201 | |
| 202 STDMETHODIMP CurrentAppState::get_installerResultCode( | |
| 203 LONG* installer_result_code) { | |
| 204 ASSERT1(installer_result_code); | |
| 205 | |
| 206 *installer_result_code = installer_result_code_; | |
| 207 return S_OK; | |
| 208 } | |
| 209 | |
| 210 STDMETHODIMP CurrentAppState::get_installerResultExtraCode1( | |
| 211 LONG* installer_result_extra_code1) { | |
| 212 ASSERT1(installer_result_extra_code1); | |
| 213 | |
| 214 *installer_result_extra_code1 = installer_result_extra_code1_; | |
| 215 return S_OK; | |
| 216 } | |
| 217 | |
| 218 STDMETHODIMP CurrentAppState::get_postInstallLaunchCommandLine( | |
| 219 BSTR* post_install_launch_command_line) { | |
| 220 ASSERT1(post_install_launch_command_line); | |
| 221 | |
| 222 *post_install_launch_command_line = | |
| 223 post_install_launch_command_line_.Copy(); | |
| 224 return S_OK; | |
| 225 } | |
| 226 | |
| 227 STDMETHODIMP CurrentAppState::get_postInstallUrl(BSTR* post_install_url) { | |
| 228 ASSERT1(post_install_url); | |
| 229 | |
| 230 *post_install_url = post_install_url_.Copy(); | |
| 231 return S_OK; | |
| 232 } | |
| 233 | |
| 234 STDMETHODIMP CurrentAppState::get_postInstallAction( | |
| 235 LONG* post_install_action) { | |
| 236 ASSERT1(post_install_action); | |
| 237 *post_install_action = static_cast<LONG>(post_install_action_); | |
| 238 return S_OK; | |
| 239 } | |
| 240 | |
| 241 } // namespace omaha | |
| OLD | NEW |