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" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // TODO(ckehoe): Once we have the app ID from the server, we need to pass | 512 // TODO(ckehoe): Once we have the app ID from the server, we need to pass |
513 // it in here and get rid of the app id registry from the main API class. | 513 // it in here and get rid of the app id registry from the main API class. |
514 delegate_->HandleMessages("", subscription->first, subscription->second); | 514 delegate_->HandleMessages("", subscription->first, subscription->second); |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 RequestHeader* RpcHandler::CreateRequestHeader( | 518 RequestHeader* RpcHandler::CreateRequestHeader( |
519 const std::string& client_name) const { | 519 const std::string& client_name) const { |
520 RequestHeader* header = new RequestHeader; | 520 RequestHeader* header = new RequestHeader; |
521 | 521 |
522 header->set_allocated_framework_version( | 522 header->set_allocated_framework_version(CreateVersion( |
523 CreateVersion("Chrome", delegate_->GetPlatformVersionString())); | 523 "Chrome", delegate_->GetPlatformVersionString())); |
524 if (!client_name.empty()) { | 524 if (!client_name.empty()) { |
525 header->set_allocated_client_version( | 525 header->set_allocated_client_version( |
526 CreateVersion(client_name, std::string())); | 526 CreateVersion(client_name, std::string())); |
527 } | 527 } |
528 header->set_current_time_millis(base::Time::Now().ToJsTime()); | 528 header->set_current_time_millis(base::Time::Now().ToJsTime()); |
529 header->set_registered_device_id(device_id_); | 529 header->set_registered_device_id(device_id_); |
530 | 530 |
| 531 DeviceFingerprint* fingerprint = new DeviceFingerprint; |
| 532 fingerprint->set_platform_version(delegate_->GetPlatformVersionString()); |
| 533 fingerprint->set_type(CHROME_PLATFORM_TYPE); |
| 534 header->set_allocated_device_fingerprint(fingerprint); |
| 535 |
531 return header; | 536 return header; |
532 } | 537 } |
533 | 538 |
534 template <class T> | 539 template <class T> |
535 void RpcHandler::SendServerRequest( | 540 void RpcHandler::SendServerRequest( |
536 const std::string& rpc_name, | 541 const std::string& rpc_name, |
537 const std::string& app_id, | 542 const std::string& app_id, |
538 scoped_ptr<T> request, | 543 scoped_ptr<T> request, |
539 const PostCleanupCallback& response_handler) { | 544 const PostCleanupCallback& response_handler) { |
540 request->set_allocated_header(CreateRequestHeader(app_id)); | 545 request->set_allocated_header(CreateRequestHeader(app_id)); |
541 server_post_callback_.Run(delegate_->GetRequestContext(), | 546 server_post_callback_.Run(delegate_->GetRequestContext(), |
542 rpc_name, | 547 rpc_name, |
543 make_scoped_ptr<MessageLite>(request.release()), | 548 make_scoped_ptr<MessageLite>(request.release()), |
544 response_handler); | 549 response_handler); |
545 } | 550 } |
546 | 551 |
547 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter, | 552 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter, |
548 const std::string& rpc_name, | 553 const std::string& rpc_name, |
549 scoped_ptr<MessageLite> request_proto, | 554 scoped_ptr<MessageLite> request_proto, |
550 const PostCleanupCallback& callback) { | 555 const PostCleanupCallback& callback) { |
551 // Create the base URL to call. | 556 // Create the base URL to call. |
552 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 557 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
553 const std::string copresence_server_host = | 558 const std::string copresence_server_host = |
554 command_line->HasSwitch(switches::kCopresenceServer) ? | 559 command_line->HasSwitch(switches::kCopresenceServer) ? |
555 command_line->GetSwitchValueASCII(switches::kCopresenceServer) : | 560 command_line->GetSwitchValueASCII(switches::kCopresenceServer) : |
556 kDefaultCopresenceServer; | 561 kDefaultCopresenceServer; |
557 | 562 |
558 // Create the request and keep a pointer until it completes. | 563 // Create the request and keep a pointer until it completes. |
559 const std::string& tracing_token = | 564 HttpPost* http_post = new HttpPost( |
560 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken); | 565 url_context_getter, |
561 HttpPost* http_post = new HttpPost(url_context_getter, | 566 copresence_server_host, |
562 copresence_server_host, | 567 rpc_name, |
563 rpc_name, | 568 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), |
564 tracing_token, | 569 delegate_->GetAPIKey(), |
565 *request_proto); | 570 *request_proto); |
| 571 |
566 http_post->Start(base::Bind(callback, http_post)); | 572 http_post->Start(base::Bind(callback, http_post)); |
567 pending_posts_.insert(http_post); | 573 pending_posts_.insert(http_post); |
568 } | 574 } |
569 | 575 |
570 void RpcHandler::AudioDirectiveListToWhispernetConnector( | 576 void RpcHandler::AudioDirectiveListToWhispernetConnector( |
571 const std::string& token, | 577 const std::string& token, |
572 bool audible, | 578 bool audible, |
573 const WhispernetClient::SamplesCallback& samples_callback) { | 579 const WhispernetClient::SamplesCallback& samples_callback) { |
574 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); | 580 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); |
575 if (whispernet_client) { | 581 if (whispernet_client) { |
576 whispernet_client->RegisterSamplesCallback(samples_callback); | 582 whispernet_client->RegisterSamplesCallback(samples_callback); |
577 whispernet_client->EncodeToken(token, audible); | 583 whispernet_client->EncodeToken(token, audible); |
578 } | 584 } |
579 } | 585 } |
580 | 586 |
581 } // namespace copresence | 587 } // namespace copresence |
OLD | NEW |