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

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

Issue 469883002: Using API key specified from js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding fingerprint test Created 6 years, 4 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->GetDeviceFingerprint().platform_version()));
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 =
532 new DeviceFingerprint(delegate_->GetDeviceFingerprint());
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 =
560 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken);
561 HttpPost* http_post = new HttpPost(url_context_getter, 564 HttpPost* http_post = new HttpPost(url_context_getter,
562 copresence_server_host, 565 copresence_server_host,
563 rpc_name, 566 rpc_name);
564 tracing_token, 567
565 *request_proto); 568 if (command_line->HasSwitch(switches::kCopresenceTracingToken)) {
566 http_post->Start(base::Bind(callback, http_post)); 569 http_post->set_tracing_token(
570 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken));
571 }
572 if (!delegate_->GetAPIKey().empty())
573 http_post->set_api_key(delegate_->GetAPIKey());
rkc 2014/08/13 21:45:31 Why are we not just passing the API key in the con
Charlie 2014/08/13 22:53:37 See previous comment. For Chrome, the API key is n
574
575 http_post->Start(base::Bind(callback, http_post), *request_proto);
567 pending_posts_.insert(http_post); 576 pending_posts_.insert(http_post);
568 } 577 }
569 578
570 void RpcHandler::AudioDirectiveListToWhispernetConnector( 579 void RpcHandler::AudioDirectiveListToWhispernetConnector(
571 const std::string& token, 580 const std::string& token,
572 bool audible, 581 bool audible,
573 const WhispernetClient::SamplesCallback& samples_callback) { 582 const WhispernetClient::SamplesCallback& samples_callback) {
574 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); 583 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient();
575 if (whispernet_client) { 584 if (whispernet_client) {
576 whispernet_client->RegisterSamplesCallback(samples_callback); 585 whispernet_client->RegisterSamplesCallback(samples_callback);
577 whispernet_client->EncodeToken(token, audible); 586 whispernet_client->EncodeToken(token, audible);
578 } 587 }
579 } 588 }
580 589
581 } // namespace copresence 590 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698