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

Unified Diff: components/copresence/rpc/rpc_handler.h

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing memory error Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/copresence/rpc/http_post_unittest.cc ('k') | components/copresence/rpc/rpc_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/rpc/rpc_handler.h
diff --git a/components/copresence/rpc/rpc_handler.h b/components/copresence/rpc/rpc_handler.h
index c431bd89ad7e9753b4552237fb527245abc21c94..30215225ba83f70d59061892001ee526e85fa68f 100644
--- a/components/copresence/rpc/rpc_handler.h
+++ b/components/copresence/rpc/rpc_handler.h
@@ -39,17 +39,29 @@ class RpcHandler {
virtual ~RpcHandler();
- // Clients must call this and wait for |init_done_callback|
- // to be called before invoking any other methods.
- void Initialize(const SuccessCallback& init_done_callback);
+ // Before accepting any other calls, the server requires registration,
+ // which is tied to the auth token (or lack thereof) used to call Report.
+ // Clients must call RegisterForToken() for each new token,
+ // *including the empty token*, they need to pass to SendReportRequest(),
+ // and then wait for |init_done_callback| to be invoked.
+ void RegisterForToken(const std::string& auth_token,
+ const SuccessCallback& init_done_callback);
+
+ // Check if a given auth token is already active (registered).
+ bool IsRegisteredForToken(const std::string& auth_token) const;
+
+ // Send a ReportRequest from Chrome itself, i.e. no app id.
+ void SendReportRequest(scoped_ptr<ReportRequest> request,
+ const std::string& auth_token);
- // Send a report request.
- void SendReportRequest(scoped_ptr<ReportRequest> request);
+ // Send a ReportRequest from a specific app, and get notified of completion.
void SendReportRequest(scoped_ptr<ReportRequest> request,
const std::string& app_id,
+ const std::string& auth_token,
const StatusCallback& callback);
// Report a set of tokens to the server for a given medium.
+ // Uses all active auth tokens (if any).
void ReportTokens(const std::vector<AudioToken>& tokens);
// Create the directive handler and connect it to
@@ -57,8 +69,11 @@ class RpcHandler {
void ConnectToWhispernet();
private:
- // An HttpPost::ResponseCallback prepended with an HttpPost object
- // that needs to be deleted.
+ // An HttpPost::ResponseCallback along with an HttpPost object to be deleted.
+ // Arguments:
+ // HttpPost*: The handler should take ownership of (i.e. delete) this object.
+ // int: The HTTP status code of the response.
+ // string: The contents of the response.
typedef base::Callback<void(HttpPost*, int, const std::string&)>
PostCleanupCallback;
@@ -66,17 +81,23 @@ class RpcHandler {
// Arguments:
// URLRequestContextGetter: Context for the HTTP POST request.
// string: Name of the rpc to invoke. URL format: server.google.com/rpc_name
+ // string: The API key to pass in the request.
+ // string: The auth token to pass with the request.
// MessageLite: Contents of POST request to be sent. This needs to be
// a (scoped) pointer to ease handling of the abstract MessageLite class.
// ResponseCallback: Receives the response to the request.
typedef base::Callback<void(net::URLRequestContextGetter*,
const std::string&,
+ const std::string&,
+ const std::string&,
scoped_ptr<google::protobuf::MessageLite>,
const PostCleanupCallback&)> PostCallback;
friend class RpcHandlerTest;
+ // Server call response handlers.
void RegisterResponseHandler(const SuccessCallback& init_done_callback,
+ const std::string& auth_token,
HttpPost* completed_post,
int http_status_code,
const std::string& response_data);
@@ -98,11 +119,15 @@ class RpcHandler {
const google::protobuf::RepeatedPtrField<SubscribedMessage>&
subscribed_messages);
- RequestHeader* CreateRequestHeader(const std::string& client_name) const;
+ RequestHeader* CreateRequestHeader(const std::string& client_name,
+ const std::string& device_id) const;
+ // Post a request to the server. The request should be in proto format.
template <class T>
void SendServerRequest(const std::string& rpc_name,
+ const std::string& device_id,
const std::string& app_id,
+ const std::string& auth_token,
scoped_ptr<T> request,
const PostCleanupCallback& response_handler);
@@ -110,6 +135,8 @@ class RpcHandler {
// to contact the server, but it can be overridden for testing.
void SendHttpPost(net::URLRequestContextGetter* url_context_getter,
const std::string& rpc_name,
+ const std::string& api_key,
+ const std::string& auth_token,
scoped_ptr<google::protobuf::MessageLite> request_proto,
const PostCleanupCallback& callback);
@@ -124,7 +151,7 @@ class RpcHandler {
TimedMap<std::string, bool> invalid_audio_token_cache_;
PostCallback server_post_callback_;
- std::string device_id_;
+ std::map<std::string, std::string> device_id_by_auth_token_;
scoped_ptr<DirectiveHandler> directive_handler_;
std::set<HttpPost*> pending_posts_;
« no previous file with comments | « components/copresence/rpc/http_post_unittest.cc ('k') | components/copresence/rpc/rpc_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698