Chromium Code Reviews| 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 Server implementation. | 5 // Broker RPC Server implementation. |
| 6 | 6 |
| 7 #include "ceee/ie/broker/broker_rpc_server.h" | 7 #include "ceee/ie/broker/broker_rpc_server.h" |
| 8 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/logging.h" | |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/logging.h" | 12 #include "base/process_util.h" |
| 12 #include "base/win_util.h" | 13 #include "base/win_util.h" |
| 13 #include "broker_rpc_lib.h" // NOLINT | 14 #include "broker_rpc_lib.h" // NOLINT |
| 14 #include "ceee/common/com_utils.h" | 15 #include "ceee/common/com_utils.h" |
| 15 #include "ceee/ie/broker/broker_module_util.h" | 16 #include "ceee/ie/broker/broker_module_util.h" |
| 16 #include "ceee/ie/broker/broker_rpc_utils.h" | 17 #include "ceee/ie/broker/broker_rpc_utils.h" |
| 17 #include "ceee/ie/broker/chrome_postman.h" | 18 #include "ceee/ie/broker/chrome_postman.h" |
| 18 | 19 |
| 20 | |
| 21 namespace { | |
| 19 // This lock ensures that histograms created by the broker are thread safe. | 22 // This lock ensures that histograms created by the broker are thread safe. |
| 20 // The histograms created here can be initialized on multiple threads. | 23 // The histograms created here can be initialized on multiple threads. |
| 21 Lock g_metrics_lock; | 24 Lock g_metrics_lock; |
| 22 | 25 |
| 26 RPC_STATUS PrepareEndpoint(std::wstring endpoint) { | |
| 27 std::wstring protocol = kRpcProtocol; | |
| 28 DCHECK(!protocol.empty()); | |
|
MAD
2010/12/01 16:35:23
Again, I don't understand why we put the static co
Vitaly Buka corp
2010/12/01 19:06:04
To avoid const in ::RpcServerUseProtseqEp(
On 2010
| |
| 29 DCHECK(!endpoint.empty()); | |
| 30 if (protocol.empty() || endpoint.empty()) | |
| 31 return false; | |
| 32 LOG(INFO) << "RPC server is starting. Endpoint: " << endpoint; | |
| 33 // Tell RPC runtime to use local interprocess communication for given | |
| 34 // end point. | |
| 35 RPC_STATUS status = ::RpcServerUseProtseqEp( | |
| 36 reinterpret_cast<RPC_WSTR>(&protocol[0]), | |
| 37 RPC_C_PROTSEQ_MAX_REQS_DEFAULT, | |
| 38 reinterpret_cast<RPC_WSTR>(&endpoint[0]), | |
| 39 NULL); | |
| 40 LOG_IF(ERROR, RPC_S_OK != status && RPC_S_DUPLICATE_ENDPOINT != status) << | |
| 41 "Failed to set protocol for RPC end point. RPC_STATUS=0x" << | |
| 42 com::LogWe(status); | |
| 43 return status; | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 23 BrokerRpcServer::BrokerRpcServer() | 48 BrokerRpcServer::BrokerRpcServer() |
| 24 : is_started_(false), | 49 : is_started_(false), |
| 25 current_thread_(::GetCurrentThreadId()) { | 50 current_thread_(::GetCurrentThreadId()) { |
| 26 } | 51 } |
| 27 | 52 |
| 28 BrokerRpcServer::~BrokerRpcServer() { | 53 BrokerRpcServer::~BrokerRpcServer() { |
| 29 DCHECK(current_thread_ == ::GetCurrentThreadId()); | 54 DCHECK(current_thread_ == ::GetCurrentThreadId()); |
| 30 Stop(); | 55 Stop(); |
| 31 } | 56 } |
| 32 | 57 |
| 33 bool BrokerRpcServer::Start() { | 58 bool BrokerRpcServer::Start() { |
| 34 DCHECK(current_thread_ == ::GetCurrentThreadId()); | 59 DCHECK(current_thread_ == ::GetCurrentThreadId()); |
| 35 | 60 |
| 36 if (is_started()) | 61 if (is_started()) |
| 37 return true; | 62 return true; |
| 38 | 63 |
| 39 std::wstring end_point = GetRpcEndPointAddress(); | 64 std::wstring endpoint = GetRpcEndpointAddress(); |
| 40 std::wstring protocol = kRpcProtocol; | 65 RPC_STATUS status = PrepareEndpoint(endpoint); |
| 41 DCHECK(!protocol.empty()); | |
| 42 DCHECK(!end_point.empty()); | |
| 43 if (protocol.empty() || end_point.empty()) | |
| 44 return false; | |
| 45 | 66 |
| 46 LOG(INFO) << "RPC server is starting. Endpoint: " << end_point; | |
| 47 // Tell RPC runtime to use local interprocess communication for given | |
| 48 // end point. | |
| 49 RPC_STATUS status = ::RpcServerUseProtseqEp( | |
| 50 reinterpret_cast<RPC_WSTR>(&protocol[0]), | |
| 51 RPC_C_PROTSEQ_MAX_REQS_DEFAULT, | |
| 52 reinterpret_cast<RPC_WSTR>(&end_point[0]), | |
| 53 NULL); | |
| 54 LOG_IF(ERROR, RPC_S_OK != status && RPC_S_DUPLICATE_ENDPOINT != status) << | |
| 55 "Failed to set protocol for RPC end point. RPC_STATUS=0x" << | |
| 56 com::LogWe(status); | |
| 57 if (RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status) { | 67 if (RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status) { |
|
MAD
2010/12/01 16:35:23
Please add a comment stating why RPC_S_DUPLICATE_E
Vitaly Buka corp
2010/12/01 19:06:04
Done. See PrepareEndpoint()
MAD
2010/12/01 19:59:40
Thanks! :-)
| |
| 58 // Register RPC interface with the RPC runtime. | 68 // Register RPC interface with the RPC runtime. |
| 59 status = ::RpcServerRegisterIfEx(BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, | 69 status = ::RpcServerRegisterIfEx(BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, |
| 60 NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); | 70 NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); |
| 61 LOG_IF(ERROR, RPC_S_OK != status) << | 71 LOG_IF(ERROR, RPC_S_OK != status) << |
| 62 "Failed to register RPC interface. RPC_STATUS=0x" << com::LogWe(status); | 72 "Failed to register RPC interface. RPC_STATUS=0x" << com::LogWe(status); |
| 63 if (RPC_S_OK == status) { | 73 if (RPC_S_OK == status) { |
| 64 // Start listen for RPC calls. | 74 // Start listen for RPC calls. |
| 65 status = ::RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); | 75 status = ::RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); |
| 66 LOG_IF(ERROR, RPC_S_OK != status) << | 76 LOG_IF(ERROR, RPC_S_OK != status) << |
| 67 "Failed to start listening. RPC_STATUS=0x" << com::LogWe(status); | 77 "Failed to start listening. RPC_STATUS=0x" << com::LogWe(status); |
| 68 if (RPC_S_OK == status) { | 78 if (RPC_S_OK == status) { |
| 69 LOG(INFO) << "RPC server is started. Endpoint: " << end_point; | 79 LOG(INFO) << "RPC server is started. Endpoints: " << endpoint; |
|
Sigurður Ásgeirsson
2010/12/01 14:23:54
Endpoints->Endpoint
Vitaly Buka corp
2010/12/01 19:06:04
Done.
| |
| 70 is_started_ = true; | 80 is_started_ = true; |
| 71 } | 81 } |
| 72 } | 82 } |
| 73 } | 83 } |
| 74 if (!is_started()) | 84 if (!is_started()) |
| 75 Stop(); | 85 Stop(); |
| 76 | 86 |
| 77 return is_started(); | 87 return is_started(); |
| 78 } | 88 } |
| 79 | 89 |
| 80 bool BrokerRpcServer::Stop() { | 90 bool BrokerRpcServer::Stop() { |
| 81 DCHECK(current_thread_ == ::GetCurrentThreadId()); | 91 DCHECK(current_thread_ == ::GetCurrentThreadId()); |
| 82 is_started_ = false; | 92 is_started_ = false; |
| 83 // Stop server listening for RPC. | 93 // Stop server listening for RPC. |
| 84 RPC_STATUS status = ::RpcMgmtStopServerListening(NULL); | 94 RPC_STATUS status = ::RpcMgmtStopServerListening(NULL); |
| 85 LOG_IF(WARNING, RPC_S_OK != status) << | 95 LOG_IF(WARNING, RPC_S_OK != status) << |
| 86 "Failed to stop listening. RPC_STATUS=0x" << com::LogWe(status); | 96 "Failed to stop listening. RPC_STATUS=0x" << com::LogWe(status); |
| 87 // Wait while server stops listening threads. | 97 // Wait while server stops listening threads. |
| 88 status = ::RpcMgmtWaitServerListen(); | 98 status = ::RpcMgmtWaitServerListen(); |
| 89 LOG_IF(WARNING, RPC_S_OK != status) << | 99 LOG_IF(WARNING, RPC_S_OK != status) << |
| 90 "Failed to wait server listen. RPC_STATUS=0x" << com::LogWe(status); | 100 "Failed to wait server listen. RPC_STATUS=0x" << com::LogWe(status); |
| 91 // Unregister RPC interface. | 101 // Unregister RPC interface. |
| 92 status = ::RpcServerUnregisterIf( | 102 status = ::RpcServerUnregisterIf( |
| 93 BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, NULL, FALSE); | 103 BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, NULL, FALSE); |
| 94 LOG_IF(WARNING, RPC_S_OK != status) << | 104 LOG_IF(WARNING, RPC_S_OK != status) << |
|
Sigurður Ásgeirsson
2010/12/01 14:23:54
Nit: I've seen this warning logged when the broker
Vitaly Buka corp
2010/12/01 19:06:04
Done.
| |
| 95 "Failed to unregister interface. RPC_STATUS=0x" << com::LogWe(status); | 105 "Failed to unregister interface. RPC_STATUS=0x" << com::LogWe(status); |
| 106 | |
| 96 return RPC_S_OK == status; | 107 return RPC_S_OK == status; |
| 97 } | 108 } |
| 98 | 109 |
| 99 bool BrokerRpcServer::is_started() const { | 110 bool BrokerRpcServer::is_started() const { |
| 100 DCHECK(current_thread_ == ::GetCurrentThreadId()); | 111 DCHECK(current_thread_ == ::GetCurrentThreadId()); |
| 101 return is_started_; | 112 return is_started_; |
| 102 } | 113 } |
| 103 | 114 |
| 104 static base::AtomicSequenceNumber current_broker_rpc_context( | 115 static base::AtomicSequenceNumber current_broker_rpc_context( |
| 105 base::LINKER_INITIALIZED); | 116 base::LINKER_INITIALIZED); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 120 } | 131 } |
| 121 | 132 |
| 122 // Called when client process terminated without releasing context handle. | 133 // Called when client process terminated without releasing context handle. |
| 123 void __RPC_USER BrokerContextHandle_rundown(BrokerContextHandle context) { | 134 void __RPC_USER BrokerContextHandle_rundown(BrokerContextHandle context) { |
| 124 DCHECK(context != NULL); | 135 DCHECK(context != NULL); |
| 125 ceee_module_util::UnlockModule(); | 136 ceee_module_util::UnlockModule(); |
| 126 } | 137 } |
| 127 | 138 |
| 128 void BrokerRpcServer_FireEvent( | 139 void BrokerRpcServer_FireEvent( |
| 129 handle_t binding_handle, | 140 handle_t binding_handle, |
| 141 BrokerContextHandle context, | |
| 130 const char* event_name, | 142 const char* event_name, |
| 131 const char* event_args) { | 143 const char* event_args) { |
| 132 DCHECK(ChromePostman::GetInstance()); | 144 DCHECK(ChromePostman::GetInstance()); |
| 133 if (ChromePostman::GetInstance()) | 145 if (ChromePostman::GetInstance()) |
| 134 ChromePostman::GetInstance()->FireEvent(event_name, event_args); | 146 ChromePostman::GetInstance()->FireEvent(event_name, event_args); |
| 135 } | 147 } |
| 136 | 148 |
| 137 void BrokerRpcServer_SendUmaHistogramTimes(handle_t binding_handle, | 149 void BrokerRpcServer_SendUmaHistogramTimes(handle_t binding_handle, |
| 138 const char* name, | 150 const char* name, |
| 139 int sample) { | 151 int sample) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 158 // We can't unfortunately use the HISTOGRAM_*_COUNT here because they use | 170 // We can't unfortunately use the HISTOGRAM_*_COUNT here because they use |
| 159 // static variables to save time. | 171 // static variables to save time. |
| 160 AutoLock lock(g_metrics_lock); | 172 AutoLock lock(g_metrics_lock); |
| 161 scoped_refptr<base::Histogram> counter = | 173 scoped_refptr<base::Histogram> counter = |
| 162 base::Histogram::FactoryGet(name, min, max, bucket_count, | 174 base::Histogram::FactoryGet(name, min, max, bucket_count, |
| 163 base::Histogram::kUmaTargetedHistogramFlag); | 175 base::Histogram::kUmaTargetedHistogramFlag); |
| 164 DCHECK_EQ(name, counter->histogram_name()); | 176 DCHECK_EQ(name, counter->histogram_name()); |
| 165 if (counter.get()) | 177 if (counter.get()) |
| 166 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); | 178 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); |
| 167 } | 179 } |
| OLD | NEW |