Added GetState, GetManagedProperties, CreateNetwork methods to WiFiService.
[chromium-blink-merge.git] / sandbox / win / src / sync_dispatcher.cc
blob3769fc6c67db422248133c7e5a1855cf89cb2fab
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/src/sync_dispatcher.h"
7 #include "base/win/windows_version.h"
8 #include "sandbox/win/src/crosscall_client.h"
9 #include "sandbox/win/src/interception.h"
10 #include "sandbox/win/src/interceptors.h"
11 #include "sandbox/win/src/ipc_tags.h"
12 #include "sandbox/win/src/policy_broker.h"
13 #include "sandbox/win/src/policy_params.h"
14 #include "sandbox/win/src/sandbox.h"
15 #include "sandbox/win/src/sync_interception.h"
16 #include "sandbox/win/src/sync_policy.h"
18 namespace sandbox {
20 SyncDispatcher::SyncDispatcher(PolicyBase* policy_base)
21 : policy_base_(policy_base) {
22 static const IPCCall create_params = {
23 {IPC_CREATEEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE},
24 reinterpret_cast<CallbackGeneric>(&SyncDispatcher::CreateEvent)
27 static const IPCCall open_params = {
28 {IPC_OPENEVENT_TAG, WCHAR_TYPE, ULONG_TYPE},
29 reinterpret_cast<CallbackGeneric>(&SyncDispatcher::OpenEvent)
32 ipc_calls_.push_back(create_params);
33 ipc_calls_.push_back(open_params);
36 bool SyncDispatcher::SetupService(InterceptionManager* manager,
37 int service) {
38 if (IPC_CREATEEVENT_TAG == service) {
39 return INTERCEPT_NT(manager, NtCreateEvent, CREATE_EVENT_ID, 24);
40 } else if (IPC_OPENEVENT_TAG == service) {
41 return INTERCEPT_NT(manager, NtOpenEvent, OPEN_EVENT_ID, 16);
43 return false;
46 bool SyncDispatcher::CreateEvent(IPCInfo* ipc, std::wstring* name,
47 DWORD event_type, DWORD initial_state) {
48 const wchar_t* event_name = name->c_str();
49 CountedParameterSet<NameBased> params;
50 params[NameBased::NAME] = ParamPickerMake(event_name);
52 EvalResult result = policy_base_->EvalPolicy(IPC_CREATEEVENT_TAG,
53 params.GetBase());
54 HANDLE handle = NULL;
55 DWORD ret = SyncPolicy::CreateEventAction(result, *ipc->client_info, *name,
56 event_type, initial_state,
57 &handle);
58 // Return operation status on the IPC.
59 ipc->return_info.nt_status = ret;
60 ipc->return_info.handle = handle;
61 return true;
64 bool SyncDispatcher::OpenEvent(IPCInfo* ipc, std::wstring* name,
65 DWORD desired_access) {
66 const wchar_t* event_name = name->c_str();
68 CountedParameterSet<OpenEventParams> params;
69 params[OpenEventParams::NAME] = ParamPickerMake(event_name);
70 params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access);
72 EvalResult result = policy_base_->EvalPolicy(IPC_OPENEVENT_TAG,
73 params.GetBase());
74 HANDLE handle = NULL;
75 DWORD ret = SyncPolicy::OpenEventAction(result, *ipc->client_info, *name,
76 desired_access, &handle);
77 // Return operation status on the IPC.
78 ipc->return_info.win32_result = ret;
79 ipc->return_info.handle = handle;
80 return true;
83 } // namespace sandbox