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

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

Issue 514383002: Workaround until the server fully supports BroadcastScanConfiguration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 TokenObservation* token_observation = 199 TokenObservation* token_observation =
200 request->mutable_update_signals_request()->add_token_observation(); 200 request->mutable_update_signals_request()->add_token_observation();
201 token_observation->set_token_id(ToUrlSafe(token.token)); 201 token_observation->set_token_id(ToUrlSafe(token.token));
202 202
203 TokenSignals* signals = token_observation->add_signals(); 203 TokenSignals* signals = token_observation->add_signals();
204 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF 204 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF
205 : AUDIO_ULTRASOUND_PASSBAND); 205 : AUDIO_ULTRASOUND_PASSBAND);
206 signals->set_observed_time_millis(base::Time::Now().ToJsTime()); 206 signals->set_observed_time_millis(base::Time::Now().ToJsTime());
207 } 207 }
208 208
209 OptInStateFilter* CreateOptedInOrOutFilter() {
210 OptInStateFilter* filter = new OptInStateFilter;
211 filter->add_allowed_opt_in_state(copresence::OPTED_IN);
212 filter->add_allowed_opt_in_state(copresence::OPTED_OUT);
213 return filter;
214 }
215
216 void AllowOptedOutMessages(ReportRequest* request) {
217 // TODO(ckehoe): Collapse this pattern into ProcessPublish()
218 // and ProcessSubscribe() methods.
219
220 if (request->has_manage_messages_request()) {
221 RepeatedPtrField<PublishedMessage>* messages = request
222 ->mutable_manage_messages_request()->mutable_message_to_publish();
223 for (int i = 0; i < messages->size(); ++i) {
224 PublishedMessage* message = messages->Mutable(i);
225 if (!message->has_opt_in_state_filter())
226 message->set_allocated_opt_in_state_filter(CreateOptedInOrOutFilter());
227 }
228 }
229
230 if (request->has_manage_subscriptions_request()) {
231 RepeatedPtrField<Subscription>* subscriptions =
232 request->mutable_manage_subscriptions_request()->mutable_subscription();
233 for (int i = 0; i < subscriptions->size(); ++i) {
234 Subscription* subscription = subscriptions->Mutable(i);
235 if (!subscription->has_opt_in_state_filter()) {
236 subscription->set_allocated_opt_in_state_filter(
237 CreateOptedInOrOutFilter());
238 }
239 }
240 }
241 }
242
243 } // namespace 209 } // namespace
244 210
245 // Public methods 211 // Public methods
246 212
247 RpcHandler::RpcHandler(CopresenceClientDelegate* delegate) 213 RpcHandler::RpcHandler(CopresenceClientDelegate* delegate)
248 : delegate_(delegate), 214 : delegate_(delegate),
249 invalid_audio_token_cache_( 215 invalid_audio_token_cache_(
250 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs), 216 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs),
251 kMaxInvalidTokens), 217 kMaxInvalidTokens),
252 server_post_callback_(base::Bind(&RpcHandler::SendHttpPost, 218 server_post_callback_(base::Bind(&RpcHandler::SendHttpPost,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 265
300 // If we are unpublishing or unsubscribing, we need to stop those publish or 266 // If we are unpublishing or unsubscribing, we need to stop those publish or
301 // subscribes right away, we don't need to wait for the server to tell us. 267 // subscribes right away, we don't need to wait for the server to tell us.
302 ProcessRemovedOperations(*request); 268 ProcessRemovedOperations(*request);
303 269
304 request->mutable_update_signals_request()->set_allocated_state( 270 request->mutable_update_signals_request()->set_allocated_state(
305 GetDeviceCapabilities(*request).release()); 271 GetDeviceCapabilities(*request).release());
306 272
307 AddPlayingTokens(request.get()); 273 AddPlayingTokens(request.get());
308 274
309 AllowOptedOutMessages(request.get()); 275 // TODO(ckehoe): Currently the server supports only BROADCAST_AND_SCAN.
276 // Remove this once b/16715253 is fixed.
277 if (request->has_manage_messages_request()) {
278 RepeatedPtrField<PublishedMessage>* messages = request
279 ->mutable_manage_messages_request()->mutable_message_to_publish();
280 for (int i = 0; i < messages->size(); ++i) {
281 messages->Mutable(i)->mutable_token_exchange_strategy()
282 ->set_broadcast_scan_configuration(BROADCAST_AND_SCAN);
283 }
284 }
285 if (request->has_manage_subscriptions_request()) {
286 RepeatedPtrField<Subscription>* subscriptions =
287 request->mutable_manage_subscriptions_request()->mutable_subscription();
288 for (int i = 0; i < subscriptions->size(); ++i) {
289 subscriptions->Mutable(i)->mutable_token_exchange_strategy()
290 ->set_broadcast_scan_configuration(BROADCAST_AND_SCAN);
291 }
292 }
293
310 SendServerRequest(kReportRequestRpcName, 294 SendServerRequest(kReportRequestRpcName,
311 app_id, 295 app_id,
312 request.Pass(), 296 request.Pass(),
313 // On destruction, this request will be cancelled. 297 // On destruction, this request will be cancelled.
314 base::Bind(&RpcHandler::ReportResponseHandler, 298 base::Bind(&RpcHandler::ReportResponseHandler,
315 base::Unretained(this), 299 base::Unretained(this),
316 status_callback)); 300 status_callback));
317 } 301 }
318 302
319 void RpcHandler::ReportTokens(const std::vector<AudioToken>& tokens) { 303 void RpcHandler::ReportTokens(const std::vector<AudioToken>& tokens) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 bool audible, 568 bool audible,
585 const WhispernetClient::SamplesCallback& samples_callback) { 569 const WhispernetClient::SamplesCallback& samples_callback) {
586 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); 570 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient();
587 if (whispernet_client) { 571 if (whispernet_client) {
588 whispernet_client->RegisterSamplesCallback(samples_callback); 572 whispernet_client->RegisterSamplesCallback(samples_callback);
589 whispernet_client->EncodeToken(token, audible); 573 whispernet_client->EncodeToken(token, audible);
590 } 574 }
591 } 575 }
592 576
593 } // namespace copresence 577 } // namespace copresence
OLDNEW
« no previous file with comments | « no previous file | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698