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/win/scoped_comptr.h" | 13 #include "base/win/scoped_comptr.h" |
| 14 #include "ceee/common/com_utils.h" |
| 15 #include "ceee/ie/broker/broker_rpc_utils.h" |
| 16 #include "ceee/ie/common/ceee_module_util.h" |
| 17 |
13 #include "broker_lib.h" // NOLINT | 18 #include "broker_lib.h" // NOLINT |
14 #include "broker_rpc_lib.h" // NOLINT | 19 #include "broker_rpc_lib.h" // NOLINT |
15 #include "ceee/common/com_utils.h" | |
16 #include "ceee/ie/broker/broker_rpc_utils.h" | |
17 | 20 |
18 BrokerRpcClient::BrokerRpcClient() : context_(0), binding_handle_(NULL) { | 21 namespace { |
| 22 |
| 23 // Avoid using objects requiring unwind in functions that use __try. |
| 24 void LogRpcException(const char* str, unsigned int exception_code) { |
| 25 LOG(ERROR) << str << com::LogWe(exception_code); |
19 } | 26 } |
20 | 27 |
21 BrokerRpcClient::~BrokerRpcClient() { | 28 BrokerRpcClient::~BrokerRpcClient() { |
22 Disconnect(); | 29 Disconnect(); |
23 } | 30 } |
24 | 31 |
25 int HandleRpcException(unsigned int rpc_exception_code) { | 32 int HandleRpcException(unsigned int rpc_exception_code) { |
26 switch (rpc_exception_code) { | 33 switch (rpc_exception_code) { |
27 case STATUS_ACCESS_VIOLATION: | 34 case STATUS_ACCESS_VIOLATION: |
28 case STATUS_DATATYPE_MISALIGNMENT: | 35 case STATUS_DATATYPE_MISALIGNMENT: |
(...skipping 22 matching lines...) Expand all Loading... |
51 } | 58 } |
52 | 59 |
53 void BrokerRpcClient::ReleaseContext() { | 60 void BrokerRpcClient::ReleaseContext() { |
54 RpcTryExcept { | 61 RpcTryExcept { |
55 BrokerRpcClient_Disconnect(binding_handle_, &context_); | 62 BrokerRpcClient_Disconnect(binding_handle_, &context_); |
56 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | 63 } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
57 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode()); | 64 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode()); |
58 } RpcEndExcept | 65 } RpcEndExcept |
59 } | 66 } |
60 | 67 |
| 68 HRESULT BrokerRpcClient::StartServer(ICeeeBrokerRegistrar** server) { |
| 69 return StartCeeeBroker(server); |
| 70 } |
| 71 |
61 HRESULT BrokerRpcClient::Connect(bool start_server) { | 72 HRESULT BrokerRpcClient::Connect(bool start_server) { |
62 if (is_connected()) | 73 if (is_connected()) |
63 return S_OK; | 74 return S_OK; |
64 | 75 |
65 // Keep alive until RPC is connected. | 76 // Keep alive until RPC is connected. |
66 base::win::ScopedComPtr<ICeeeBrokerRegistrar> broker; | 77 base::win::ScopedComPtr<ICeeeBrokerRegistrar> broker; |
67 if (start_server) { | 78 if (start_server) { |
68 // TODO(vitalybuka@google.com): Start broker without COM after the last | 79 // TODO(vitalybuka@google.com): Start broker without COM after the last |
69 // COM interface is removed. | 80 // COM interface is removed. |
70 HRESULT hr = broker.CreateInstance(CLSID_CeeeBroker); | 81 HRESULT hr = broker.CreateInstance(CLSID_CeeeBroker); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 int bucket_count) { | 165 int bucket_count) { |
155 RpcTryExcept { | 166 RpcTryExcept { |
156 BrokerRpcClient_SendUmaHistogramData( | 167 BrokerRpcClient_SendUmaHistogramData( |
157 binding_handle_, name, sample, min, max, bucket_count); | 168 binding_handle_, name, sample, min, max, bucket_count); |
158 return S_OK; | 169 return S_OK; |
159 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | 170 } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
160 LogRpcException("RPC error in SendUmaHistogramData", RpcExceptionCode()); | 171 LogRpcException("RPC error in SendUmaHistogramData", RpcExceptionCode()); |
161 return RPC_E_FAULT; | 172 return RPC_E_FAULT; |
162 } RpcEndExcept | 173 } RpcEndExcept |
163 } | 174 } |
| 175 |
| 176 HRESULT StartCeeeBroker(ICeeeBrokerRegistrar** broker) { |
| 177 ceee_module_util::RefreshElevationPolicyIfNeeded(); |
| 178 base::win::ScopedComPtr<ICeeeBrokerRegistrar> broker_tmp; |
| 179 // TODO(vitalybuka@google.com): Start broker without COM after the last |
| 180 // COM interface is removed. |
| 181 HRESULT hr = broker_tmp.CreateInstance(CLSID_CeeeBroker); |
| 182 if (FAILED(hr)) { |
| 183 LOG(ERROR) << "Failed to create broker. " << com::LogHr(hr); |
| 184 return hr; |
| 185 } |
| 186 *broker = broker_tmp.Detach(); |
| 187 return S_OK; |
| 188 } |
OLD | NEW |