| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 base::Unretained(this))) {} | 160 base::Unretained(this))) {} |
| 160 | 161 |
| 161 RpcHandler::~RpcHandler() { | 162 RpcHandler::~RpcHandler() { |
| 162 for (HttpPost* post : pending_posts_) { | 163 for (HttpPost* post : pending_posts_) { |
| 163 delete post; | 164 delete post; |
| 164 } | 165 } |
| 165 | 166 |
| 166 if (delegate_ && delegate_->GetWhispernetClient()) { | 167 if (delegate_ && delegate_->GetWhispernetClient()) { |
| 167 delegate_->GetWhispernetClient()->RegisterTokensCallback( | 168 delegate_->GetWhispernetClient()->RegisterTokensCallback( |
| 168 WhispernetClient::TokensCallback()); | 169 WhispernetClient::TokensCallback()); |
| 170 delegate_->GetWhispernetClient()->RegisterSamplesCallback( |
| 171 WhispernetClient::SamplesCallback()); |
| 169 } | 172 } |
| 170 } | 173 } |
| 171 | 174 |
| 172 void RpcHandler::Initialize(const SuccessCallback& init_done_callback) { | 175 void RpcHandler::Initialize(const SuccessCallback& init_done_callback) { |
| 173 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); | 176 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); |
| 174 DCHECK(device_id_.empty()); | 177 DCHECK(device_id_.empty()); |
| 175 | 178 |
| 176 request->mutable_push_service()->set_service(PUSH_SERVICE_NONE); | 179 request->mutable_push_service()->set_service(PUSH_SERVICE_NONE); |
| 177 Identity* identity = | 180 Identity* identity = |
| 178 request->mutable_device_identifiers()->mutable_registrant(); | 181 request->mutable_device_identifiers()->mutable_registrant(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 request.manage_subscriptions_request().id_to_unsubscribe()) { | 378 request.manage_subscriptions_request().id_to_unsubscribe()) { |
| 376 directive_handler_->RemoveDirectives(unsubscribe); | 379 directive_handler_->RemoveDirectives(unsubscribe); |
| 377 } | 380 } |
| 378 } | 381 } |
| 379 } | 382 } |
| 380 | 383 |
| 381 void RpcHandler::AddPlayingTokens(ReportRequest* request) { | 384 void RpcHandler::AddPlayingTokens(ReportRequest* request) { |
| 382 if (!directive_handler_) | 385 if (!directive_handler_) |
| 383 return; | 386 return; |
| 384 | 387 |
| 385 const std::string& audible_token = directive_handler_->CurrentAudibleToken(); | 388 const std::string& audible_token = |
| 389 directive_handler_->GetCurrentAudioToken(AUDIBLE); |
| 386 const std::string& inaudible_token = | 390 const std::string& inaudible_token = |
| 387 directive_handler_->CurrentInaudibleToken(); | 391 directive_handler_->GetCurrentAudioToken(INAUDIBLE); |
| 388 | 392 |
| 389 if (!audible_token.empty()) | 393 if (!audible_token.empty()) |
| 390 AddTokenToRequest(request, AudioToken(audible_token, true)); | 394 AddTokenToRequest(request, AudioToken(audible_token, true)); |
| 391 if (!inaudible_token.empty()) | 395 if (!inaudible_token.empty()) |
| 392 AddTokenToRequest(request, AudioToken(inaudible_token, false)); | 396 AddTokenToRequest(request, AudioToken(inaudible_token, false)); |
| 393 } | 397 } |
| 394 | 398 |
| 395 void RpcHandler::DispatchMessages( | 399 void RpcHandler::DispatchMessages( |
| 396 const RepeatedPtrField<SubscribedMessage>& messages) { | 400 const RepeatedPtrField<SubscribedMessage>& messages) { |
| 397 if (messages.size() == 0) | 401 if (messages.size() == 0) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), | 474 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), |
| 471 delegate_->GetAPIKey(), | 475 delegate_->GetAPIKey(), |
| 472 *request_proto); | 476 *request_proto); |
| 473 | 477 |
| 474 http_post->Start(base::Bind(callback, http_post)); | 478 http_post->Start(base::Bind(callback, http_post)); |
| 475 pending_posts_.insert(http_post); | 479 pending_posts_.insert(http_post); |
| 476 } | 480 } |
| 477 | 481 |
| 478 void RpcHandler::AudioDirectiveListToWhispernetConnector( | 482 void RpcHandler::AudioDirectiveListToWhispernetConnector( |
| 479 const std::string& token, | 483 const std::string& token, |
| 480 bool audible, | 484 AudioType type, |
| 481 const WhispernetClient::SamplesCallback& samples_callback) { | 485 const WhispernetClient::SamplesCallback& samples_callback) { |
| 486 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 482 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); | 487 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); |
| 483 if (whispernet_client) { | 488 if (whispernet_client) { |
| 484 whispernet_client->RegisterSamplesCallback(samples_callback); | 489 whispernet_client->RegisterSamplesCallback(samples_callback); |
| 485 whispernet_client->EncodeToken(token, audible); | 490 whispernet_client->EncodeToken(token, type); |
| 486 } | 491 } |
| 487 } | 492 } |
| 488 | 493 |
| 489 } // namespace copresence | 494 } // namespace copresence |
| OLD | NEW |