OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Broker RPC Client implementation. | 5 // Broker RPC Client implementation. |
6 | 6 |
7 #include "ceee/ie/broker/broker_rpc_client.h" | 7 #include "ceee/ie/broker/broker_rpc_client.h" |
8 | 8 |
9 #include <atlbase.h> | 9 #include <atlbase.h> |
10 | |
10 #include "base/lock.h" | 11 #include "base/lock.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/tuple.h" | 13 #include "base/tuple.h" |
13 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
15 #include "ceee/common/com_utils.h" | |
16 #include "ceee/ie/broker/broker_rpc_utils.h" | |
17 #include "ceee/ie/common/ceee_module_util.h" | |
18 | |
14 #include "broker_lib.h" // NOLINT | 19 #include "broker_lib.h" // NOLINT |
15 #include "broker_rpc_lib.h" // NOLINT | 20 #include "broker_rpc_lib.h" // NOLINT |
16 #include "ceee/common/com_utils.h" | |
17 #include "ceee/ie/broker/broker_rpc_utils.h" | |
18 | |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // Avoid using objects requiring unwind in functions that use __try. | 24 // Avoid using objects requiring unwind in functions that use __try. |
23 void LogRpcException(const char* str, unsigned int exception_code) { | 25 void LogRpcException(const char* str, unsigned int exception_code) { |
24 LOG(ERROR) << str << com::LogWe(exception_code); | 26 LOG(ERROR) << str << com::LogWe(exception_code); |
25 } | 27 } |
26 | 28 |
27 // Avoid using objects requiring unwind in functions that use __try. | 29 // Avoid using objects requiring unwind in functions that use __try. |
28 void RpcDcheck(const char* message) { | 30 void RpcDcheck(const char* message) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 } | 110 } |
109 | 111 |
110 void BrokerRpcClient::ReleaseContext() { | 112 void BrokerRpcClient::ReleaseContext() { |
111 RpcTryExcept { | 113 RpcTryExcept { |
112 BrokerRpcClient_Disconnect(binding_handle_, &context_); | 114 BrokerRpcClient_Disconnect(binding_handle_, &context_); |
113 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | 115 } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
114 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode()); | 116 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode()); |
115 } RpcEndExcept | 117 } RpcEndExcept |
116 } | 118 } |
117 | 119 |
118 HRESULT BrokerRpcClient::StartServer(IUnknown** server) { | 120 HRESULT BrokerRpcClient::StartServer(ICeeeBrokerRegistrar** server) { |
119 base::win::ScopedComPtr<IUnknown> broker; | 121 return StartCeeeBroker(server); |
120 // TODO(vitalybuka@google.com): Start broker without COM after the last | |
121 // COM interface is removed. | |
122 HRESULT hr = broker.CreateInstance(CLSID_CeeeBroker); | |
123 LOG_IF(ERROR, FAILED(hr)) << "Failed to create broker. " << com::LogHr(hr); | |
124 if (FAILED(hr)) | |
125 return hr; | |
126 *server = broker.Detach(); | |
127 return S_OK; | |
128 } | 122 } |
129 | 123 |
130 HRESULT BrokerRpcClient::Connect(bool start_server) { | 124 HRESULT BrokerRpcClient::Connect(bool start_server) { |
131 if (is_connected()) | 125 if (is_connected()) |
132 return S_OK; | 126 return S_OK; |
133 | 127 |
134 // Keep alive until RPC is connected. | 128 // Keep alive until RPC is connected. |
135 base::win::ScopedComPtr<IUnknown> broker; | 129 base::win::ScopedComPtr<ICeeeBrokerRegistrar> broker; |
136 if (start_server) { | 130 if (start_server) { |
137 HRESULT hr = StartServer(broker.Receive()); | 131 HRESULT hr = StartServer(broker.Receive()); |
138 if (FAILED(hr)) | 132 if (FAILED(hr)) |
139 return hr; | 133 return hr; |
140 } | 134 } |
141 | 135 |
142 if (SUCCEEDED(BindRpc(GetRpcEndpointAddress(), &binding_handle_))) | 136 if (SUCCEEDED(BindRpc(GetRpcEndpointAddress(), &binding_handle_))) |
143 LockContext(); | 137 LockContext(); |
144 | 138 |
145 if (!is_connected()) { | 139 if (!is_connected()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 HRESULT BrokerRpcClient::SendUmaHistogramData(const char* name, | 198 HRESULT BrokerRpcClient::SendUmaHistogramData(const char* name, |
205 int sample, | 199 int sample, |
206 int min, | 200 int min, |
207 int max, | 201 int max, |
208 int bucket_count) { | 202 int bucket_count) { |
209 return RunRpc(allow_restarts_, | 203 return RunRpc(allow_restarts_, |
210 &BrokerRpcClient_SendUmaHistogramData, | 204 &BrokerRpcClient_SendUmaHistogramData, |
211 MakeRefTuple(binding_handle_, name, sample, min, max, | 205 MakeRefTuple(binding_handle_, name, sample, min, max, |
212 bucket_count)); | 206 bucket_count)); |
213 } | 207 } |
208 | |
209 HRESULT StartCeeeBroker(ICeeeBrokerRegistrar** broker) { | |
210 ceee_module_util::RefreshElevationPolicyIfNeeded(); | |
211 base::win::ScopedComPtr<ICeeeBrokerRegistrar> broker_tmp; | |
212 // TODO(vitalybuka@google.com): Start broker without COM after the last | |
213 // COM interface is removed. | |
214 HRESULT hr = broker_tmp.CreateInstance(CLSID_CeeeBroker); | |
215 if (FAILED(hr)) { | |
216 LOG(ERROR) << "Failed to create broker. " << com::LogHr(hr); | |
217 return hr; | |
218 } | |
219 *broker = broker_tmp.Detach(); | |
mad-corp
2010/12/13 14:12:45
DCHECK(broker != NULL) before using unknown pointe
| |
220 return S_OK; | |
221 } | |
OLD | NEW |