| 42 | } |
| 43 | |
| 44 | void IESession::Initialize(void* init_params) { |
| 45 | LOG(TRACE) << "Entering IESession::Initialize"; |
| 46 | |
| 47 | HANDLE mutex = ::CreateMutex(NULL, FALSE, MUTEX_NAME); |
| 48 | if (mutex != NULL) { |
| 49 | // Wait for up to the timeout (currently 30 seconds) for other sessions |
| 50 | // to completely initialize. |
| 51 | DWORD mutex_wait_status = ::WaitForSingleObject(mutex, MUTEX_WAIT_TIMEOUT); |
| 52 | if (mutex_wait_status == WAIT_ABANDONED) { |
| 53 | LOG(WARN) << "Acquired mutex, but received wait abandoned status. This " |
| 54 | << "could mean the process previously owning the mutex was " |
| 55 | << "unexpectedly terminated."; |
| 56 | } else if (mutex_wait_status == WAIT_TIMEOUT) { |
| 57 | LOG(WARN) << "Could not acquire mutex within the timeout. Multiple " |
| 58 | << "instances may hang or behave unpredictably"; |
| 59 | } else if (mutex_wait_status == WAIT_OBJECT_0) { |
| 60 | LOG(DEBUG) << "Mutex acquired for session initalization"; |
| 61 | } else if (mutex_wait_status == WAIT_FAILED) { |
| 62 | LOGERR(WARN) << "Mutex acquire waiting is failed"; |
| 63 | } |
| 64 | } else { |
| 65 | LOGERR(WARN) << "Could not create session initialization mutex. Multiple " |
| 66 | << "instances will behave unpredictably. "; |
| 67 | } |
| 68 | |
| 69 | SessionParameters* params = reinterpret_cast<SessionParameters*>(init_params); |
| 70 | int port = params->port; |
| 71 | |
| 72 | IECommandExecutorThreadContext thread_context; |
| 73 | thread_context.port = port; |
| 74 | thread_context.hwnd = NULL; |
| 75 | |
| 76 | unsigned int thread_id = 0; |
| 77 | |
| 78 | HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, WEBDRIVER_START_EVENT_NAME); |
| 79 | if (event_handle == NULL) { |
| 80 | LOGERR(DEBUG) << "Unable to create event " << WEBDRIVER_START_EVENT_NAME; |
| 81 | } |
| 82 | |
| 83 | ThreadProcedure thread_proc = &IECommandExecutor::ThreadProc; |
| 84 | HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, |
| 85 | 0, |
| 86 | thread_proc, |
| 87 | reinterpret_cast<void*>(&thread_context), |
| 88 | 0, |
| 89 | &thread_id)); |
| 90 | if (event_handle != NULL) { |
| 91 | DWORD thread_wait_status = ::WaitForSingleObject(event_handle, THREAD_WAIT_TIMEOUT); |
| 92 | if (thread_wait_status != WAIT_OBJECT_0) { |
| 93 | LOGERR(WARN) << "Unable to wait until created thread notification: '" << thread_wait_status << "'."; |
| 94 | } |
| 95 | ::CloseHandle(event_handle); |
| 96 | } |
| 97 | |
| 98 | if (thread_handle != NULL) { |
| 99 | ::CloseHandle(thread_handle); |
| 100 | } else { |
| 101 | LOG(DEBUG) << "Unable to create thread for command executor"; |
nothing calls this directly
no test coverage detected