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

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

Issue 901213003: Removing the project ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 audible->add_instruction_type(RECEIVE); 132 audible->add_instruction_type(RECEIVE);
133 133
134 return state.Pass(); 134 return state.Pass();
135 } 135 }
136 136
137 // TODO(ckehoe): We're keeping this code in a separate function for now 137 // TODO(ckehoe): We're keeping this code in a separate function for now
138 // because we get a version string from Chrome, but the proto expects 138 // because we get a version string from Chrome, but the proto expects
139 // an int64 version. We should probably change the version proto 139 // an int64 version. We should probably change the version proto
140 // to handle a more detailed version. 140 // to handle a more detailed version.
141 ClientVersion* CreateVersion(const std::string& client, 141 ClientVersion* CreateVersion(const std::string& client,
142 const std::string& version_name, 142 const std::string& version_name) {
143 const std::string& project_id) {
144 ClientVersion* version = new ClientVersion; 143 ClientVersion* version = new ClientVersion;
145
146 version->set_client(client); 144 version->set_client(client);
147 version->set_version_name(version_name); 145 version->set_version_name(version_name);
148
149 if (!project_id.empty()) {
150 DVLOG(3) << "Using project ID " << project_id;
151 version->set_project_id(project_id);
152 }
153
154 return version; 146 return version;
155 } 147 }
156 148
157 void AddTokenToRequest(const AudioToken& token, ReportRequest* request) { 149 void AddTokenToRequest(const AudioToken& token, ReportRequest* request) {
158 TokenObservation* token_observation = 150 TokenObservation* token_observation =
159 request->mutable_update_signals_request()->add_token_observation(); 151 request->mutable_update_signals_request()->add_token_observation();
160 token_observation->set_token_id(ToUrlSafe(token.token)); 152 token_observation->set_token_id(ToUrlSafe(token.token));
161 153
162 TokenSignals* signals = token_observation->add_signals(); 154 TokenSignals* signals = token_observation->add_signals();
163 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF 155 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 for (HttpPost* post : pending_posts_) 198 for (HttpPost* post : pending_posts_)
207 delete post; 199 delete post;
208 } 200 }
209 201
210 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request, 202 void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request,
211 const std::string& app_id, 203 const std::string& app_id,
212 const std::string& auth_token, 204 const std::string& auth_token,
213 const StatusCallback& status_callback) { 205 const StatusCallback& status_callback) {
214 DCHECK(request.get()); 206 DCHECK(request.get());
215 207
208 // Check that the app, if any, has some kind of authentication token.
209 // Don't allow it to piggyback on Chrome's credentials.
210 if (!app_id.empty() && delegate_->GetAPIKey(app_id).empty() &&
211 auth_token.empty()) {
212 LOG(ERROR) << "App " << app_id << " has no API key or auth token";
213 status_callback.Run(FAIL);
214 return;
215 }
216
216 // Store just one auth token since we should have only one account 217 // Store just one auth token since we should have only one account
217 // per instance of the copresence component. 218 // per instance of the copresence component.
218 // TODO(ckehoe): We may eventually need to support multiple auth tokens. 219 // TODO(ckehoe): We may eventually need to support multiple auth tokens.
219 const bool authenticated = !auth_token.empty(); 220 const bool authenticated = !auth_token.empty();
220 if (authenticated && auth_token != auth_token_) { 221 if (authenticated && auth_token != auth_token_) {
221 LOG_IF(ERROR, !auth_token_.empty()) 222 LOG_IF(ERROR, !auth_token_.empty())
222 << "Overwriting old auth token: " << LoggingStrForToken(auth_token); 223 << "Overwriting old auth token: " << LoggingStrForToken(auth_token);
223 auth_token_ = auth_token; 224 auth_token_ = auth_token;
224 } 225 }
225 226
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 566 }
566 567
567 // TODO(ckehoe): Pass in the version string and 568 // TODO(ckehoe): Pass in the version string and
568 // group this with the local functions up top. 569 // group this with the local functions up top.
569 RequestHeader* RpcHandler::CreateRequestHeader( 570 RequestHeader* RpcHandler::CreateRequestHeader(
570 const std::string& app_id, 571 const std::string& app_id,
571 const std::string& device_id) const { 572 const std::string& device_id) const {
572 RequestHeader* header = new RequestHeader; 573 RequestHeader* header = new RequestHeader;
573 574
574 header->set_allocated_framework_version(CreateVersion( 575 header->set_allocated_framework_version(CreateVersion(
575 "Chrome", delegate_->GetPlatformVersionString(), std::string())); 576 "Chrome", delegate_->GetPlatformVersionString()));
576 if (!app_id.empty()) { 577 if (!app_id.empty())
577 LOG_IF(WARNING, delegate_->GetProjectId(app_id).empty()) 578 header->set_allocated_client_version(CreateVersion(app_id, std::string()));
578 << "No copresence project ID available";
579 header->set_allocated_client_version(CreateVersion(
580 app_id, std::string(), delegate_->GetProjectId(app_id)));
581 }
582 header->set_current_time_millis(base::Time::Now().ToJsTime()); 579 header->set_current_time_millis(base::Time::Now().ToJsTime());
583 if (!device_id.empty()) 580 if (!device_id.empty())
584 header->set_registered_device_id(device_id); 581 header->set_registered_device_id(device_id);
585 582
586 DeviceFingerprint* fingerprint = new DeviceFingerprint; 583 DeviceFingerprint* fingerprint = new DeviceFingerprint;
587 fingerprint->set_platform_version(delegate_->GetPlatformVersionString()); 584 fingerprint->set_platform_version(delegate_->GetPlatformVersionString());
588 fingerprint->set_type(CHROME_PLATFORM_TYPE); 585 fingerprint->set_type(CHROME_PLATFORM_TYPE);
589 header->set_allocated_device_fingerprint(fingerprint); 586 header->set_allocated_device_fingerprint(fingerprint);
590 587
591 return header; 588 return header;
592 } 589 }
593 590
594 template <class T> 591 template <class T>
595 void RpcHandler::SendServerRequest( 592 void RpcHandler::SendServerRequest(
596 const std::string& rpc_name, 593 const std::string& rpc_name,
597 const std::string& device_id, 594 const std::string& device_id,
598 const std::string& app_id, 595 const std::string& app_id,
599 bool authenticated, 596 bool authenticated,
600 scoped_ptr<T> request, 597 scoped_ptr<T> request,
601 const PostCleanupCallback& response_handler) { 598 const PostCleanupCallback& response_handler) {
602 request->set_allocated_header(CreateRequestHeader(app_id, device_id)); 599 request->set_allocated_header(CreateRequestHeader(app_id, device_id));
603 if (authenticated) 600 if (authenticated)
604 DCHECK(!auth_token_.empty()); 601 DCHECK(!auth_token_.empty());
605 server_post_callback_.Run(delegate_->GetRequestContext(), 602 server_post_callback_.Run(delegate_->GetRequestContext(),
606 rpc_name, 603 rpc_name,
607 delegate_->GetAPIKey(app_id), // Deprecated 604 delegate_->GetAPIKey(app_id),
608 authenticated ? auth_token_ : std::string(), 605 authenticated ? auth_token_ : std::string(),
609 make_scoped_ptr<MessageLite>(request.release()), 606 make_scoped_ptr<MessageLite>(request.release()),
610 response_handler); 607 response_handler);
611 } 608 }
612 609
613 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter, 610 void RpcHandler::SendHttpPost(net::URLRequestContextGetter* url_context_getter,
614 const std::string& rpc_name, 611 const std::string& rpc_name,
615 const std::string& api_key, // Deprecated 612 const std::string& api_key,
616 const std::string& auth_token, 613 const std::string& auth_token,
617 scoped_ptr<MessageLite> request_proto, 614 scoped_ptr<MessageLite> request_proto,
618 const PostCleanupCallback& callback) { 615 const PostCleanupCallback& callback) {
619 // Create the base URL to call. 616 // Create the base URL to call.
620 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 617 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
621 const std::string copresence_server_host = 618 const std::string copresence_server_host =
622 command_line->HasSwitch(switches::kCopresenceServer) ? 619 command_line->HasSwitch(switches::kCopresenceServer) ?
623 command_line->GetSwitchValueASCII(switches::kCopresenceServer) : 620 command_line->GetSwitchValueASCII(switches::kCopresenceServer) :
624 kDefaultCopresenceServer; 621 kDefaultCopresenceServer;
625 622
626 // Create the request and keep a pointer until it completes. 623 // Create the request and keep a pointer until it completes.
627 HttpPost* http_post = new HttpPost( 624 HttpPost* http_post = new HttpPost(
628 url_context_getter, 625 url_context_getter,
629 copresence_server_host, 626 copresence_server_host,
630 rpc_name, 627 rpc_name,
631 api_key, 628 api_key,
632 auth_token, 629 auth_token,
633 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), 630 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken),
634 *request_proto); 631 *request_proto);
635 632
636 http_post->Start(base::Bind(callback, http_post)); 633 http_post->Start(base::Bind(callback, http_post));
637 pending_posts_.insert(http_post); 634 pending_posts_.insert(http_post);
638 } 635 }
639 636
640 } // namespace copresence 637 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/rpc/rpc_handler.h ('k') | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698