| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-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/tools/omahacompatibility/console_writer.h" | |
| 17 #include <Windows.h> | |
| 18 #include <tchar.h> | |
| 19 #include "omaha/common/debug.h" | |
| 20 #include "omaha/common/logging.h" | |
| 21 #include "omaha/common/utils.h" | |
| 22 #include "omaha/tools/omahacompatibility/common/ping_observer.h" | |
| 23 | |
| 24 namespace omaha { | |
| 25 | |
| 26 CString ConsoleWriter::PingTypeToString(PingEvent::Types type) { | |
| 27 switch (type) { | |
| 28 case PingEvent::EVENT_UNKNOWN: | |
| 29 return _T("EVENT_UNKNOWN"); | |
| 30 case PingEvent::EVENT_INSTALL_DOWNLOAD_FINISH: | |
| 31 return _T("EVENT_INSTALL_DOWNLOAD_FINISH"); | |
| 32 case PingEvent::EVENT_INSTALL_COMPLETE: | |
| 33 return _T("EVENT_INSTALL_COMPLETE"); | |
| 34 case PingEvent::EVENT_UPDATE_COMPLETE: | |
| 35 return _T("EVENT_UPDATE_COMPLETE"); | |
| 36 case PingEvent::EVENT_UNINSTALL: | |
| 37 return _T("EVENT_UNINSTALL"); | |
| 38 case PingEvent::EVENT_INSTALL_DOWNLOAD_START: | |
| 39 return _T("EVENT_INSTALL_DOWNLOAD_START"); | |
| 40 case PingEvent::EVENT_INSTALL_INSTALLER_START: | |
| 41 return _T("EVENT_INSTALL_INSTALLER_START"); | |
| 42 case PingEvent::EVENT_INSTALL_APPLICATION_BEGIN: | |
| 43 return _T("EVENT_INSTALL_APPLICATION_BEGIN"); | |
| 44 | |
| 45 // Install Setup events. | |
| 46 case PingEvent::EVENT_SETUP_INSTALL_BEGIN: | |
| 47 return _T("EVENT_SETUP_INSTALL_BEGIN"); | |
| 48 case PingEvent::EVENT_SETUP_INSTALL_COMPLETE: | |
| 49 return _T("EVENT_SETUP_INSTALL_COMPLETE"); | |
| 50 | |
| 51 // Register Product Events. | |
| 52 case PingEvent::EVENT_REGISTER_PRODUCT_COMPLETE: | |
| 53 return _T("EVENT_REGISTER_PRODUCT_COMPLETE"); | |
| 54 | |
| 55 // Update Events. | |
| 56 case PingEvent::EVENT_UPDATE_APPLICATION_BEGIN: | |
| 57 return _T("EVENT_UPDATE_APPLICATION_BEGIN"); | |
| 58 case PingEvent::EVENT_UPDATE_DOWNLOAD_START: | |
| 59 return _T("EVENT_UPDATE_DOWNLOAD_START"); | |
| 60 case PingEvent::EVENT_UPDATE_DOWNLOAD_FINISH: | |
| 61 return _T("EVENT_UPDATE_DOWNLOAD_FINISH"); | |
| 62 case PingEvent::EVENT_UPDATE_INSTALLER_START: | |
| 63 return _T("EVENT_UPDATE_INSTALLER_START"); | |
| 64 | |
| 65 // Self-update Setup events. | |
| 66 case PingEvent::EVENT_SETUP_UPDATE_BEGIN: | |
| 67 return _T("EVENT_SETUP_UPDATE_BEGIN"); | |
| 68 case PingEvent::EVENT_SETUP_UPDATE_COMPLETE: | |
| 69 return _T("EVENT_SETUP_UPDATE_COMPLETE"); | |
| 70 | |
| 71 // Other events. | |
| 72 case PingEvent::EVENT_INSTALL_OEM_FIRST_CHECK: | |
| 73 return _T("EVENT_INSTALL_OEM_FIRST_CHECK"); | |
| 74 case PingEvent::EVENT_APP_COMMAND_BEGIN: | |
| 75 return _T("EVENT_APP_COMMAND_BEGIN"); | |
| 76 case PingEvent::EVENT_APP_COMMAND_COMPLETE: | |
| 77 return _T("EVENT_APP_COMMAND_COMPLETE"); | |
| 78 | |
| 79 // Failure report events - not part of the normal flow. | |
| 80 case PingEvent::EVENT_SETUP_INSTALL_FAILURE: | |
| 81 return _T("EVENT_SETUP_INSTALL_FAILURE"); | |
| 82 case PingEvent::EVENT_SETUP_COM_SERVER_FAILURE: | |
| 83 return _T("EVENT_SETUP_COM_SERVER_FAILURE"); | |
| 84 case PingEvent::EVENT_SETUP_UPDATE_FAILURE: | |
| 85 return _T("EVENT_SETUP_UPDATE_FAILURE"); | |
| 86 default: | |
| 87 return _T("Unknown"); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 CString ConsoleWriter::PingResultToString(PingEvent::Results result) { | |
| 92 switch (result) { | |
| 93 case PingEvent::EVENT_RESULT_ERROR: | |
| 94 return _T("EVENT_RESULT_ERROR"); | |
| 95 case PingEvent::EVENT_RESULT_SUCCESS: | |
| 96 return _T("EVENT_RESULT_SUCCESS"); | |
| 97 case PingEvent::EVENT_RESULT_SUCCESS_REBOOT: | |
| 98 return _T("EVENT_RESULT_SUCCESS_REBOOT"); | |
| 99 case PingEvent::EVENT_RESULT_CANCELLED: | |
| 100 return _T("EVENT_RESULT_CANCELLED"); | |
| 101 case PingEvent::EVENT_RESULT_INSTALLER_ERROR_MSI: | |
| 102 return _T("EVENT_RESULT_INSTALLER_ERROR_MSI"); | |
| 103 case PingEvent::EVENT_RESULT_INSTALLER_ERROR_OTHER: | |
| 104 return _T("EVENT_RESULT_INSTALLER_ERROR_OTHER"); | |
| 105 case PingEvent::EVENT_RESULT_NOUPDATE: | |
| 106 return _T("EVENT_RESULT_NOUPDATE"); | |
| 107 case PingEvent::EVENT_RESULT_INSTALLER_ERROR_SYSTEM: | |
| 108 return _T("EVENT_RESULT_INSTALLER_ERROR_SYSTEM"); | |
| 109 case PingEvent::EVENT_RESULT_UPDATE_DEFERRED: | |
| 110 return _T("EVENT_RESULT_UPDATE_DEFERRED"); | |
| 111 default: | |
| 112 return _T("unknown result"); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 bool ConsoleWriter::IsUpdateCompletedEvent(const CString& app_guid, | |
| 117 const PingEvent& ping) { | |
| 118 return app_guid == app_guid_ && | |
| 119 ping.event_type() == PingEvent::EVENT_UPDATE_COMPLETE; | |
| 120 } | |
| 121 | |
| 122 bool ConsoleWriter::IsInstallCompletedEvent(const CString& app_guid, | |
| 123 const PingEvent& ping) { | |
| 124 return app_guid == app_guid_ && | |
| 125 ping.event_type() == PingEvent::EVENT_INSTALL_COMPLETE; | |
| 126 } | |
| 127 | |
| 128 void ConsoleWriter::Observe(const AppRequestData& data) { | |
| 129 PingEventVector::const_iterator iter = data.ping_events_begin(); | |
| 130 for (; iter != data.ping_events_end(); ++iter) { | |
| 131 PingEvent ping = *iter; | |
| 132 CString msg; | |
| 133 msg.Format(_T("\nPing App = %s, Type = %s, Result = %s, Error = %d\n"), | |
| 134 GuidToString(data.app_data().app_guid()), | |
| 135 PingTypeToString(ping.event_type()), | |
| 136 PingResultToString(ping.event_result()), | |
| 137 ping.error_code()); | |
| 138 printf("%S", msg); | |
| 139 CORE_LOG(L1, (msg)); | |
| 140 | |
| 141 if (IsInstallCompletedEvent(GuidToString(data.app_data().app_guid()), | |
| 142 ping)) { | |
| 143 __mutexScope(lock_); | |
| 144 install_result_ = ping.event_result(); | |
| 145 install_completed_ = true; | |
| 146 } else if (IsUpdateCompletedEvent(GuidToString(data.app_data().app_guid()), | |
| 147 ping)) { | |
| 148 __mutexScope(lock_); | |
| 149 update_result_ = ping.event_result(); | |
| 150 update_completed_ = true; | |
| 151 } | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 } // namespace omaha | |
| OLD | NEW |