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

Unified Diff: google_apis/gcm/engine/registration_request.h

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 5 years, 7 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
Index: google_apis/gcm/engine/registration_request.h
diff --git a/google_apis/gcm/engine/registration_request.h b/google_apis/gcm/engine/registration_request.h
index 1f707b9dd9ee276fd6ddb34609f8f4ddc9fb9595..4442878aa48c191064dbcc97df12c10ef49eb212 100644
--- a/google_apis/gcm/engine/registration_request.h
+++ b/google_apis/gcm/engine/registration_request.h
@@ -59,31 +59,101 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
const std::string& registration_id)>
RegistrationCallback;
- // Details of the of the Registration Request. Only user's android ID and
- // its serial number are optional and can be set to 0. All other parameters
- // have to be specified to successfully complete the call.
- struct GCM_EXPORT RequestInfo {
- RequestInfo(uint64 android_id,
- uint64 security_token,
- const std::string& app_id,
- const std::vector<std::string>& sender_ids);
- ~RequestInfo();
-
+ // Encapsulates the common info about a registration/token request.
+ class GCM_EXPORT RequestInfo {
+ public:
+ RequestInfo();
+ virtual ~RequestInfo();
+
+ virtual void BuildRequestHeaders(std::string* extra_headers);
Nicolas Zea 2015/05/15 20:37:01 Style guide prefers either doing pure inheritance
jianli 2015/05/21 00:41:15 With more thought, I decided to make RequestInfo s
+ virtual void BuildRequestBody(std::string* body);
+ virtual std::string GetSenders() const = 0;
+
+ std::string app_id() const { return app_id_; }
+
+ void set_chrome_version(const std::string& chrome_version) {
+ chrome_version_ = chrome_version;
+ }
+ void set_android_id(uint64 android_id) {
+ android_id_ = android_id;
+ }
+ void set_security_token(uint64 security_token) {
+ security_token_ = security_token;
+ }
+ void set_app_id(const std::string& app_id) {
+ app_id_ = app_id;
+ }
+
+ protected:
+ // Version to pass.
+ std::string chrome_version_;
// Android ID of the device.
- uint64 android_id;
+ uint64 android_id_;
// Security token of the device.
- uint64 security_token;
+ uint64 security_token_;
// Application ID.
- std::string app_id;
- // Certificate of the application.
- std::string cert;
+ std::string app_id_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RequestInfo);
+ };
+
+ // GCM registration request.
+ class GCM_EXPORT GCMRequestInfo : public RequestInfo {
+ public:
+ GCMRequestInfo();
+ ~GCMRequestInfo() override;
+
+ // RequestInfo overrides:
+ void BuildRequestBody(std::string* body) override;
+ std::string GetSenders() const override;
+
+ void set_sender_ids(const std::vector<std::string>& sender_ids) {
+ sender_ids_ = sender_ids;
+ }
+
+ private:
// List of IDs of senders. Allowed up to 100.
- std::vector<std::string> sender_ids;
+ std::vector<std::string> sender_ids_;
+
+ DISALLOW_COPY_AND_ASSIGN(GCMRequestInfo);
+ };
+
+ // Instance ID token request.
+ class GCM_EXPORT InstanceIDRequestInfo : public RequestInfo {
+ public:
+ InstanceIDRequestInfo();
+ ~InstanceIDRequestInfo() override;
+
+ // RequestInfo overrides:
+ void BuildRequestBody(std::string* body) override;
+ std::string GetSenders() const override;
+
+ void set_instance_id(const std::string& instance_id) {
+ instance_id_ = instance_id;
+ }
+ void set_authorized_entity(const std::string& authorized_entity) {
+ authorized_entity_ = authorized_entity;
+ }
+ void set_scope(const std::string& scope) {
+ scope_ = scope;
+ }
+ void set_options(const std::map<std::string, std::string>& options) {
+ options_ = options;
+ }
+
+ private:
+ std::string instance_id_;
+ std::string authorized_entity_;
+ std::string scope_;
+ std::map<std::string, std::string> options_;
+
+ DISALLOW_COPY_AND_ASSIGN(InstanceIDRequestInfo);
};
RegistrationRequest(
const GURL& registration_url,
- const RequestInfo& request_info,
+ scoped_ptr<RequestInfo> request_info,
const net::BackoffEntry::Policy& backoff_policy,
const RegistrationCallback& callback,
int max_retry_count,
@@ -106,7 +176,7 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate {
Status ParseResponse(const net::URLFetcher* source, std::string* token);
RegistrationCallback callback_;
- RequestInfo request_info_;
+ scoped_ptr<RequestInfo> request_info_;
GURL registration_url_;
net::BackoffEntry backoff_entry_;

Powered by Google App Engine
This is Rietveld 408576698