Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: components/copresence/rpc/rpc_handler.cc

Issue 600843004: Setting AudioConfiguration and deleting DeviceCapabilities hacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correcting DeviceCapabilities Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/copresence/rpc/rpc_handler.h" 5 #include "components/copresence/rpc/rpc_handler.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 template <typename T> 97 template <typename T>
98 BroadcastScanConfiguration GetBroadcastScanConfig(const T& msg) { 98 BroadcastScanConfiguration GetBroadcastScanConfig(const T& msg) {
99 if (msg.has_token_exchange_strategy() && 99 if (msg.has_token_exchange_strategy() &&
100 msg.token_exchange_strategy().has_broadcast_scan_configuration()) { 100 msg.token_exchange_strategy().has_broadcast_scan_configuration()) {
101 return msg.token_exchange_strategy().broadcast_scan_configuration(); 101 return msg.token_exchange_strategy().broadcast_scan_configuration();
102 } 102 }
103 return BROADCAST_SCAN_CONFIGURATION_UNKNOWN; 103 return BROADCAST_SCAN_CONFIGURATION_UNKNOWN;
104 } 104 }
105 105
106 // This method will extract token exchange strategies
107 // from the publishes and subscribes in a report request.
108 // TODO(ckehoe): Delete this when the server supports
109 // BroadcastScanConfiguration.
110 BroadcastScanConfiguration ExtractTokenExchangeStrategy(
111 const ReportRequest& request) {
112 bool broadcast_only = false;
113 bool scan_only = false;
114
115 // Strategies for publishes.
116 if (request.has_manage_messages_request()) {
117 const RepeatedPtrField<PublishedMessage>& messages =
118 request.manage_messages_request().message_to_publish();
119 for (int i = 0; i < messages.size(); ++i) {
120 BroadcastScanConfiguration config =
121 GetBroadcastScanConfig(messages.Get(i));
122 broadcast_only = broadcast_only || config == BROADCAST_ONLY;
123 scan_only = scan_only || config == SCAN_ONLY;
124 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only))
125 return BROADCAST_AND_SCAN;
126 }
127 }
128
129 // Strategies for subscriptions.
130 if (request.has_manage_subscriptions_request()) {
131 const RepeatedPtrField<Subscription> subscriptions =
132 request.manage_subscriptions_request().subscription();
133 for (int i = 0; i < subscriptions.size(); ++i) {
134 BroadcastScanConfiguration config =
135 GetBroadcastScanConfig(subscriptions.Get(i));
136 broadcast_only = broadcast_only || config == BROADCAST_ONLY;
137 scan_only = scan_only || config == SCAN_ONLY;
138 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only))
139 return BROADCAST_AND_SCAN;
140 }
141 }
142
143 if (broadcast_only)
144 return BROADCAST_ONLY;
145 if (scan_only)
146 return SCAN_ONLY;
147
148 // If nothing else is specified, default to both broadcast and scan.
149 return BROADCAST_AND_SCAN;
150 }
151
152 // TODO(rkc): Fix this hack once the server supports setting strategies per
153 // operation.
154 bool ExtractIsAudibleStrategy(const ReportRequest& request) {
155 if (request.has_manage_messages_request()) {
156 const RepeatedPtrField<PublishedMessage> messages =
157 request.manage_messages_request().message_to_publish();
158 for (int i = 0; i < messages.size(); ++i) {
159 const PublishedMessage& msg = messages.Get(i);
160 if (msg.has_token_exchange_strategy() &&
161 msg.token_exchange_strategy().has_use_audible() &&
162 msg.token_exchange_strategy().use_audible()) {
163 return true;
164 }
165 }
166 }
167 return false;
168 }
169
170 scoped_ptr<DeviceState> GetDeviceCapabilities(const ReportRequest& request) { 106 scoped_ptr<DeviceState> GetDeviceCapabilities(const ReportRequest& request) {
171 scoped_ptr<DeviceState> state(new DeviceState); 107 scoped_ptr<DeviceState> state(new DeviceState);
172 108
173 TokenTechnology* token_technology = 109 TokenTechnology* ultrasound =
174 state->mutable_capabilities()->add_token_technology(); 110 state->mutable_capabilities()->add_token_technology();
175 token_technology->set_medium(AUDIO_ULTRASOUND_PASSBAND); 111 ultrasound->set_medium(AUDIO_ULTRASOUND_PASSBAND);
176 if (ExtractIsAudibleStrategy(request)) 112 ultrasound->add_instruction_type(TRANSMIT);
177 token_technology->set_medium(AUDIO_AUDIBLE_DTMF); 113 ultrasound->add_instruction_type(RECEIVE);
178 114
179 BroadcastScanConfiguration config = 115 TokenTechnology* audible =
180 ExtractTokenExchangeStrategy(request); 116 state->mutable_capabilities()->add_token_technology();
181 if (config == BROADCAST_ONLY || config == BROADCAST_AND_SCAN) 117 audible->set_medium(AUDIO_AUDIBLE_DTMF);
182 token_technology->add_instruction_type(TRANSMIT); 118 audible->add_instruction_type(TRANSMIT);
183 if (config == SCAN_ONLY || config == BROADCAST_AND_SCAN) 119 audible->add_instruction_type(RECEIVE);
184 token_technology->add_instruction_type(RECEIVE);
185 120
186 return state.Pass(); 121 return state.Pass();
187 } 122 }
188 123
189 // TODO(ckehoe): We're keeping this code in a separate function for now 124 // TODO(ckehoe): We're keeping this code in a separate function for now
190 // because we get a version string from Chrome, but the proto expects 125 // because we get a version string from Chrome, but the proto expects
191 // an int64 version. We should probably change the version proto 126 // an int64 version. We should probably change the version proto
192 // to handle a more detailed version. 127 // to handle a more detailed version.
193 ClientVersion* CreateVersion(const std::string& client, 128 ClientVersion* CreateVersion(const std::string& client,
194 const std::string& version_name) { 129 const std::string& version_name) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 205
271 // If we are unpublishing or unsubscribing, we need to stop those publish or 206 // If we are unpublishing or unsubscribing, we need to stop those publish or
272 // subscribes right away, we don't need to wait for the server to tell us. 207 // subscribes right away, we don't need to wait for the server to tell us.
273 ProcessRemovedOperations(*request); 208 ProcessRemovedOperations(*request);
274 209
275 request->mutable_update_signals_request()->set_allocated_state( 210 request->mutable_update_signals_request()->set_allocated_state(
276 GetDeviceCapabilities(*request).release()); 211 GetDeviceCapabilities(*request).release());
277 212
278 AddPlayingTokens(request.get()); 213 AddPlayingTokens(request.get());
279 214
280 // TODO(ckehoe): Currently the server supports only BROADCAST_AND_SCAN.
281 // Remove this once b/16715253 is fixed.
282 if (request->has_manage_messages_request()) {
283 RepeatedPtrField<PublishedMessage>* messages = request
284 ->mutable_manage_messages_request()->mutable_message_to_publish();
285 for (int i = 0; i < messages->size(); ++i) {
286 messages->Mutable(i)->mutable_token_exchange_strategy()
287 ->set_broadcast_scan_configuration(BROADCAST_AND_SCAN);
288 }
289 }
290 if (request->has_manage_subscriptions_request()) {
291 RepeatedPtrField<Subscription>* subscriptions =
292 request->mutable_manage_subscriptions_request()->mutable_subscription();
293 for (int i = 0; i < subscriptions->size(); ++i) {
294 subscriptions->Mutable(i)->mutable_token_exchange_strategy()
295 ->set_broadcast_scan_configuration(BROADCAST_AND_SCAN);
296 }
297 }
298
299 SendServerRequest(kReportRequestRpcName, 215 SendServerRequest(kReportRequestRpcName,
300 app_id, 216 app_id,
301 request.Pass(), 217 request.Pass(),
302 // On destruction, this request will be cancelled. 218 // On destruction, this request will be cancelled.
303 base::Bind(&RpcHandler::ReportResponseHandler, 219 base::Bind(&RpcHandler::ReportResponseHandler,
304 base::Unretained(this), 220 base::Unretained(this),
305 status_callback)); 221 status_callback));
306 } 222 }
307 223
308 void RpcHandler::ReportTokens(const std::vector<AudioToken>& tokens) { 224 void RpcHandler::ReportTokens(const std::vector<AudioToken>& tokens) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 bool audible, 489 bool audible,
574 const WhispernetClient::SamplesCallback& samples_callback) { 490 const WhispernetClient::SamplesCallback& samples_callback) {
575 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); 491 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient();
576 if (whispernet_client) { 492 if (whispernet_client) {
577 whispernet_client->RegisterSamplesCallback(samples_callback); 493 whispernet_client->RegisterSamplesCallback(samples_callback);
578 whispernet_client->EncodeToken(token, audible); 494 whispernet_client->EncodeToken(token, audible);
579 } 495 }
580 } 496 }
581 497
582 } // namespace copresence 498 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/proto/data.proto ('k') | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698