| OLD | NEW |
| 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" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 | 14 |
| 15 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities | 15 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities |
| 16 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now, | 16 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now, |
| 17 // we fix this with an #undef. | 17 // we fix this with an #undef. |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 #undef DeviceCapabilities | 20 #undef DeviceCapabilities |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #include "components/copresence/copresence_switches.h" | 23 #include "components/copresence/copresence_switches.h" |
| 24 #include "components/copresence/handlers/directive_handler.h" | 24 #include "components/copresence/handlers/directive_handler.h" |
| 25 #include "components/copresence/proto/codes.pb.h" | 25 #include "components/copresence/proto/codes.pb.h" |
| 26 #include "components/copresence/proto/data.pb.h" | 26 #include "components/copresence/proto/data.pb.h" |
| 27 #include "components/copresence/proto/rpcs.pb.h" | 27 #include "components/copresence/proto/rpcs.pb.h" |
| 28 #include "components/copresence/public/copresence_constants.h" |
| 28 #include "components/copresence/public/copresence_delegate.h" | 29 #include "components/copresence/public/copresence_delegate.h" |
| 29 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
| 30 | 31 |
| 31 // TODO(ckehoe): Return error messages for bad requests. | 32 // TODO(ckehoe): Return error messages for bad requests. |
| 32 | 33 |
| 33 namespace copresence { | 34 namespace copresence { |
| 34 | 35 |
| 35 using google::protobuf::MessageLite; | 36 using google::protobuf::MessageLite; |
| 36 using google::protobuf::RepeatedPtrField; | 37 using google::protobuf::RepeatedPtrField; |
| 37 | 38 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 request.manage_subscriptions_request().id_to_unsubscribe()) { | 376 request.manage_subscriptions_request().id_to_unsubscribe()) { |
| 376 directive_handler_->RemoveDirectives(unsubscribe); | 377 directive_handler_->RemoveDirectives(unsubscribe); |
| 377 } | 378 } |
| 378 } | 379 } |
| 379 } | 380 } |
| 380 | 381 |
| 381 void RpcHandler::AddPlayingTokens(ReportRequest* request) { | 382 void RpcHandler::AddPlayingTokens(ReportRequest* request) { |
| 382 if (!directive_handler_) | 383 if (!directive_handler_) |
| 383 return; | 384 return; |
| 384 | 385 |
| 385 const std::string& audible_token = directive_handler_->CurrentAudibleToken(); | 386 const std::string& audible_token = |
| 387 directive_handler_->GetCurrentAudioToken(AUDIBLE); |
| 386 const std::string& inaudible_token = | 388 const std::string& inaudible_token = |
| 387 directive_handler_->CurrentInaudibleToken(); | 389 directive_handler_->GetCurrentAudioToken(INAUDIBLE); |
| 388 | 390 |
| 389 if (!audible_token.empty()) | 391 if (!audible_token.empty()) |
| 390 AddTokenToRequest(request, AudioToken(audible_token, true)); | 392 AddTokenToRequest(request, AudioToken(audible_token, true)); |
| 391 if (!inaudible_token.empty()) | 393 if (!inaudible_token.empty()) |
| 392 AddTokenToRequest(request, AudioToken(inaudible_token, false)); | 394 AddTokenToRequest(request, AudioToken(inaudible_token, false)); |
| 393 } | 395 } |
| 394 | 396 |
| 395 void RpcHandler::DispatchMessages( | 397 void RpcHandler::DispatchMessages( |
| 396 const RepeatedPtrField<SubscribedMessage>& messages) { | 398 const RepeatedPtrField<SubscribedMessage>& messages) { |
| 397 if (messages.size() == 0) | 399 if (messages.size() == 0) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), | 472 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), |
| 471 delegate_->GetAPIKey(), | 473 delegate_->GetAPIKey(), |
| 472 *request_proto); | 474 *request_proto); |
| 473 | 475 |
| 474 http_post->Start(base::Bind(callback, http_post)); | 476 http_post->Start(base::Bind(callback, http_post)); |
| 475 pending_posts_.insert(http_post); | 477 pending_posts_.insert(http_post); |
| 476 } | 478 } |
| 477 | 479 |
| 478 void RpcHandler::AudioDirectiveListToWhispernetConnector( | 480 void RpcHandler::AudioDirectiveListToWhispernetConnector( |
| 479 const std::string& token, | 481 const std::string& token, |
| 480 bool audible, | 482 AudioType type, |
| 481 const WhispernetClient::SamplesCallback& samples_callback) { | 483 const WhispernetClient::SamplesCallback& samples_callback) { |
| 484 DCHECK_LT(type, BOTH); |
| 482 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); | 485 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); |
| 483 if (whispernet_client) { | 486 if (whispernet_client) { |
| 484 whispernet_client->RegisterSamplesCallback(samples_callback); | 487 whispernet_client->RegisterSamplesCallback(samples_callback); |
| 485 whispernet_client->EncodeToken(token, audible); | 488 whispernet_client->EncodeToken(token, type); |
| 486 } | 489 } |
| 487 } | 490 } |
| 488 | 491 |
| 489 } // namespace copresence | 492 } // namespace copresence |
| OLD | NEW |