| 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/base/const_object_names.h" | |
| 17 #include "omaha/base/debug.h" | |
| 18 #include "omaha/base/logging.h" | |
| 19 #include "omaha/common/goopdate_utils.h" | |
| 20 #include "omaha/ui/ui_displayed_event.h" | |
| 21 | |
| 22 namespace omaha { | |
| 23 | |
| 24 HRESULT UIDisplayedEventManager::CreateEvent(bool is_machine) { | |
| 25 ASSERT1(!IsEventHandleInitialized()); | |
| 26 return goopdate_utils::CreateUniqueEventInEnvironment( | |
| 27 kLegacyUiDisplayedEventEnvironmentVariableName, | |
| 28 is_machine, | |
| 29 address(ui_displayed_event_)); | |
| 30 } | |
| 31 | |
| 32 // Caller does not own the event handle and must not close it. | |
| 33 // There is a single event handle for each process. The handle is closed when | |
| 34 // the process exits. | |
| 35 HRESULT UIDisplayedEventManager::GetEvent(bool is_machine, | |
| 36 HANDLE* ui_displayed_event) { | |
| 37 ASSERT1(ui_displayed_event); | |
| 38 *ui_displayed_event = NULL; | |
| 39 if (IsEventHandleInitialized()) { | |
| 40 *ui_displayed_event = get(ui_displayed_event_); | |
| 41 return S_OK; | |
| 42 } | |
| 43 | |
| 44 HRESULT hr = goopdate_utils::OpenUniqueEventFromEnvironment( | |
| 45 kLegacyUiDisplayedEventEnvironmentVariableName, | |
| 46 is_machine, | |
| 47 address(ui_displayed_event_)); | |
| 48 if (FAILED(hr)) { | |
| 49 return hr; | |
| 50 } | |
| 51 | |
| 52 *ui_displayed_event = get(ui_displayed_event_); | |
| 53 return S_OK; | |
| 54 } | |
| 55 | |
| 56 // Creates the event if it does not already exist in the environment. | |
| 57 void UIDisplayedEventManager::SignalEvent(bool is_machine) { | |
| 58 CORE_LOG(L2, (_T("[SignalEvent]"))); | |
| 59 | |
| 60 if (!IsEventHandleInitialized()) { | |
| 61 HRESULT hr = GetEvent(is_machine, address(ui_displayed_event_)); | |
| 62 if (HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) == hr) { | |
| 63 // The event was not created by an earlier process. This can happen when | |
| 64 // developers run the /handoff process directly. | |
| 65 hr = CreateEvent(is_machine); | |
| 66 } | |
| 67 if (FAILED(hr)) { | |
| 68 reset(ui_displayed_event_); | |
| 69 // We may display two UIs. | |
| 70 return; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 ASSERT1(IsEventHandleInitialized()); | |
| 75 VERIFY1(::SetEvent(get(ui_displayed_event_))); | |
| 76 } | |
| 77 | |
| 78 bool UIDisplayedEventManager::IsEventHandleInitialized() { | |
| 79 return valid(ui_displayed_event_); | |
| 80 } | |
| 81 | |
| 82 scoped_handle UIDisplayedEventManager::ui_displayed_event_; | |
| 83 | |
| 84 } // namespace omaha | |
| OLD | NEW |