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

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

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing histograms Created 6 years, 1 month 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const char kRegisterDeviceRpcName[] = "registerdevice"; 53 const char kRegisterDeviceRpcName[] = "registerdevice";
54 const char kDefaultCopresenceServer[] = 54 const char kDefaultCopresenceServer[] =
55 "https://www.googleapis.com/copresence/v2/copresence"; 55 "https://www.googleapis.com/copresence/v2/copresence";
56 56
57 // Logging 57 // Logging
58 58
59 // Checks for a copresence error. If there is one, logs it and returns true. 59 // Checks for a copresence error. If there is one, logs it and returns true.
60 bool CopresenceErrorLogged(const Status& status) { 60 bool CopresenceErrorLogged(const Status& status) {
61 if (status.code() != OK) { 61 if (status.code() != OK) {
62 LOG(ERROR) << "Copresence error code " << status.code() 62 LOG(ERROR) << "Copresence error code " << status.code()
63 << (status.message().empty() ? std::string() : 63 << (status.message().empty() ? "" : ": " + status.message());
64 ": " + status.message());
65 } 64 }
66 return status.code() != OK; 65 return status.code() != OK;
67 } 66 }
68 67
69 void LogIfErrorStatus(const util::error::Code& code, 68 void LogIfErrorStatus(const util::error::Code& code,
70 const std::string& context) { 69 const std::string& context) {
71 LOG_IF(ERROR, code != util::error::OK) 70 LOG_IF(ERROR, code != util::error::OK)
72 << context << " error " << code << ". See " 71 << context << " error " << code << ". See "
73 << "cs/google3/util/task/codes.proto for more info."; 72 << "cs/google3/util/task/codes.proto for more info.";
74 } 73 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); 172 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest);
174 DCHECK(device_id_.empty()); 173 DCHECK(device_id_.empty());
175 174
176 request->mutable_push_service()->set_service(PUSH_SERVICE_NONE); 175 request->mutable_push_service()->set_service(PUSH_SERVICE_NONE);
177 Identity* identity = 176 Identity* identity =
178 request->mutable_device_identifiers()->mutable_registrant(); 177 request->mutable_device_identifiers()->mutable_registrant();
179 identity->set_type(CHROME); 178 identity->set_type(CHROME);
180 identity->set_chrome_id(base::GenerateGUID()); 179 identity->set_chrome_id(base::GenerateGUID());
181 SendServerRequest( 180 SendServerRequest(
182 kRegisterDeviceRpcName, 181 kRegisterDeviceRpcName,
183 std::string(), 182 "",
rkc 2014/10/21 22:48:38 std::string(), here and below.
Charlie 2014/10/21 23:19:44 Done.
184 request.Pass(), 183 request.Pass(),
185 base::Bind(&RpcHandler::RegisterResponseHandler, 184 base::Bind(&RpcHandler::RegisterResponseHandler,
186 // On destruction, this request will be cancelled. 185 // On destruction, this request will be cancelled.
187 base::Unretained(this), 186 base::Unretained(this),
188 init_done_callback)); 187 init_done_callback));
189 } 188 }
190 189
191 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request) { 190 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request) {
192 SendReportRequest(request.Pass(), std::string(), StatusCallback()); 191 SendReportRequest(request.Pass(), "", StatusCallback());
193 } 192 }
194 193
195 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request, 194 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request,
196 const std::string& app_id, 195 const std::string& app_id,
197 const StatusCallback& status_callback) { 196 const StatusCallback& status_callback) {
198 DCHECK(request.get()); 197 DCHECK(request.get());
199 DCHECK(!device_id_.empty()) 198 DCHECK(!device_id_.empty())
200 << "RpcHandler::Initialize() must complete successfully " 199 << "RpcHandler::Initialize() must complete successfully "
201 << "before other RpcHandler methods are called."; 200 << "before other RpcHandler methods are called.";
202 201
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 417 }
419 418
420 RequestHeader* RpcHandler::CreateRequestHeader( 419 RequestHeader* RpcHandler::CreateRequestHeader(
421 const std::string& client_name) const { 420 const std::string& client_name) const {
422 RequestHeader* header = new RequestHeader; 421 RequestHeader* header = new RequestHeader;
423 422
424 header->set_allocated_framework_version(CreateVersion( 423 header->set_allocated_framework_version(CreateVersion(
425 "Chrome", delegate_->GetPlatformVersionString())); 424 "Chrome", delegate_->GetPlatformVersionString()));
426 if (!client_name.empty()) { 425 if (!client_name.empty()) {
427 header->set_allocated_client_version( 426 header->set_allocated_client_version(
428 CreateVersion(client_name, std::string())); 427 CreateVersion(client_name, ""));
429 } 428 }
430 header->set_current_time_millis(base::Time::Now().ToJsTime()); 429 header->set_current_time_millis(base::Time::Now().ToJsTime());
431 header->set_registered_device_id(device_id_); 430 header->set_registered_device_id(device_id_);
432 431
433 DeviceFingerprint* fingerprint = new DeviceFingerprint; 432 DeviceFingerprint* fingerprint = new DeviceFingerprint;
434 fingerprint->set_platform_version(delegate_->GetPlatformVersionString()); 433 fingerprint->set_platform_version(delegate_->GetPlatformVersionString());
435 fingerprint->set_type(CHROME_PLATFORM_TYPE); 434 fingerprint->set_type(CHROME_PLATFORM_TYPE);
436 header->set_allocated_device_fingerprint(fingerprint); 435 header->set_allocated_device_fingerprint(fingerprint);
437 436
438 return header; 437 return header;
439 } 438 }
440 439
441 template <class T> 440 template <class T>
442 void RpcHandler::SendServerRequest( 441 void RpcHandler::SendServerRequest(
443 const std::string& rpc_name, 442 const std::string& rpc_name,
444 const std::string& app_id, 443 const std::string& app_id,
445 scoped_ptr<T> request, 444 scoped_ptr<T> request,
446 const PostCleanupCallback& response_handler) { 445 const PostCleanupCallback& response_handler) {
447 request->set_allocated_header(CreateRequestHeader(app_id)); 446 request->set_allocated_header(CreateRequestHeader(app_id));
448 server_post_callback_.Run(delegate_->GetRequestContext(), 447 server_post_callback_.Run(delegate_->GetRequestContext(),
449 rpc_name, 448 rpc_name,
449 app_id,
450 make_scoped_ptr<MessageLite>(request.release()), 450 make_scoped_ptr<MessageLite>(request.release()),
451 response_handler); 451 response_handler);
452 } 452 }
453 453
454 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter, 454 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter,
455 const std::string& rpc_name, 455 const std::string& rpc_name,
456 const std::string& app_id,
456 scoped_ptr<MessageLite> request_proto, 457 scoped_ptr<MessageLite> request_proto,
457 const PostCleanupCallback& callback) { 458 const PostCleanupCallback& callback) {
458 // Create the base URL to call. 459 // Create the base URL to call.
459 CommandLine* command_line = CommandLine::ForCurrentProcess(); 460 CommandLine* command_line = CommandLine::ForCurrentProcess();
460 const std::string copresence_server_host = 461 const std::string copresence_server_host =
461 command_line->HasSwitch(switches::kCopresenceServer) ? 462 command_line->HasSwitch(switches::kCopresenceServer) ?
462 command_line->GetSwitchValueASCII(switches::kCopresenceServer) : 463 command_line->GetSwitchValueASCII(switches::kCopresenceServer) :
463 kDefaultCopresenceServer; 464 kDefaultCopresenceServer;
464 465
465 // Create the request and keep a pointer until it completes. 466 // Create the request and keep a pointer until it completes.
466 HttpPost* http_post = new HttpPost( 467 HttpPost* http_post = new HttpPost(
467 url_context_getter, 468 url_context_getter,
468 copresence_server_host, 469 copresence_server_host,
469 rpc_name, 470 rpc_name,
471 delegate_->GetAPIKey(app_id),
472 delegate_->GetAuthToken(app_id),
470 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), 473 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken),
471 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 bool audible,
481 const WhispernetClient::SamplesCallback& samples_callback) { 483 const WhispernetClient::SamplesCallback& samples_callback) {
482 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); 484 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient();
483 if (whispernet_client) { 485 if (whispernet_client) {
484 whispernet_client->RegisterSamplesCallback(samples_callback); 486 whispernet_client->RegisterSamplesCallback(samples_callback);
485 whispernet_client->EncodeToken(token, audible); 487 whispernet_client->EncodeToken(token, audible);
486 } 488 }
487 } 489 }
488 490
489 } // namespace copresence 491 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698