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

Side by Side 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 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 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ 5 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_
6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ 6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // immediately above this line. Make sure to update the corresponding 52 // immediately above this line. Make sure to update the corresponding
53 // histogram enum accordingly. 53 // histogram enum accordingly.
54 STATUS_COUNT 54 STATUS_COUNT
55 }; 55 };
56 56
57 // Callback completing the registration request. 57 // Callback completing the registration request.
58 typedef base::Callback<void(Status status, 58 typedef base::Callback<void(Status status,
59 const std::string& registration_id)> 59 const std::string& registration_id)>
60 RegistrationCallback; 60 RegistrationCallback;
61 61
62 // Details of the of the Registration Request. Only user's android ID and 62 // Encapsulates the common info about a registration/token request.
63 // its serial number are optional and can be set to 0. All other parameters 63 class GCM_EXPORT RequestInfo {
64 // have to be specified to successfully complete the call. 64 public:
65 struct GCM_EXPORT RequestInfo { 65 RequestInfo();
66 RequestInfo(uint64 android_id, 66 virtual ~RequestInfo();
67 uint64 security_token,
68 const std::string& app_id,
69 const std::vector<std::string>& sender_ids);
70 ~RequestInfo();
71 67
68 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
69 virtual void BuildRequestBody(std::string* body);
70 virtual std::string GetSenders() const = 0;
71
72 std::string app_id() const { return app_id_; }
73
74 void set_chrome_version(const std::string& chrome_version) {
75 chrome_version_ = chrome_version;
76 }
77 void set_android_id(uint64 android_id) {
78 android_id_ = android_id;
79 }
80 void set_security_token(uint64 security_token) {
81 security_token_ = security_token;
82 }
83 void set_app_id(const std::string& app_id) {
84 app_id_ = app_id;
85 }
86
87 protected:
88 // Version to pass.
89 std::string chrome_version_;
72 // Android ID of the device. 90 // Android ID of the device.
73 uint64 android_id; 91 uint64 android_id_;
74 // Security token of the device. 92 // Security token of the device.
75 uint64 security_token; 93 uint64 security_token_;
76 // Application ID. 94 // Application ID.
77 std::string app_id; 95 std::string app_id_;
78 // Certificate of the application. 96
79 std::string cert; 97 private:
98 DISALLOW_COPY_AND_ASSIGN(RequestInfo);
99 };
100
101 // GCM registration request.
102 class GCM_EXPORT GCMRequestInfo : public RequestInfo {
103 public:
104 GCMRequestInfo();
105 ~GCMRequestInfo() override;
106
107 // RequestInfo overrides:
108 void BuildRequestBody(std::string* body) override;
109 std::string GetSenders() const override;
110
111 void set_sender_ids(const std::vector<std::string>& sender_ids) {
112 sender_ids_ = sender_ids;
113 }
114
115 private:
80 // List of IDs of senders. Allowed up to 100. 116 // List of IDs of senders. Allowed up to 100.
81 std::vector<std::string> sender_ids; 117 std::vector<std::string> sender_ids_;
118
119 DISALLOW_COPY_AND_ASSIGN(GCMRequestInfo);
120 };
121
122 // Instance ID token request.
123 class GCM_EXPORT InstanceIDRequestInfo : public RequestInfo {
124 public:
125 InstanceIDRequestInfo();
126 ~InstanceIDRequestInfo() override;
127
128 // RequestInfo overrides:
129 void BuildRequestBody(std::string* body) override;
130 std::string GetSenders() const override;
131
132 void set_instance_id(const std::string& instance_id) {
133 instance_id_ = instance_id;
134 }
135 void set_authorized_entity(const std::string& authorized_entity) {
136 authorized_entity_ = authorized_entity;
137 }
138 void set_scope(const std::string& scope) {
139 scope_ = scope;
140 }
141 void set_options(const std::map<std::string, std::string>& options) {
142 options_ = options;
143 }
144
145 private:
146 std::string instance_id_;
147 std::string authorized_entity_;
148 std::string scope_;
149 std::map<std::string, std::string> options_;
150
151 DISALLOW_COPY_AND_ASSIGN(InstanceIDRequestInfo);
82 }; 152 };
83 153
84 RegistrationRequest( 154 RegistrationRequest(
85 const GURL& registration_url, 155 const GURL& registration_url,
86 const RequestInfo& request_info, 156 scoped_ptr<RequestInfo> request_info,
87 const net::BackoffEntry::Policy& backoff_policy, 157 const net::BackoffEntry::Policy& backoff_policy,
88 const RegistrationCallback& callback, 158 const RegistrationCallback& callback,
89 int max_retry_count, 159 int max_retry_count,
90 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 160 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
91 GCMStatsRecorder* recorder); 161 GCMStatsRecorder* recorder);
92 ~RegistrationRequest() override; 162 ~RegistrationRequest() override;
93 163
94 void Start(); 164 void Start();
95 165
96 // URLFetcherDelegate implementation. 166 // URLFetcherDelegate implementation.
97 void OnURLFetchComplete(const net::URLFetcher* source) override; 167 void OnURLFetchComplete(const net::URLFetcher* source) override;
98 168
99 private: 169 private:
100 // Schedules a retry attempt, informs the backoff of a previous request's 170 // Schedules a retry attempt, informs the backoff of a previous request's
101 // failure, when |update_backoff| is true. 171 // failure, when |update_backoff| is true.
102 void RetryWithBackoff(bool update_backoff); 172 void RetryWithBackoff(bool update_backoff);
103 173
104 // Parse the response returned by the URL fetcher into token, and returns the 174 // Parse the response returned by the URL fetcher into token, and returns the
105 // status. 175 // status.
106 Status ParseResponse(const net::URLFetcher* source, std::string* token); 176 Status ParseResponse(const net::URLFetcher* source, std::string* token);
107 177
108 RegistrationCallback callback_; 178 RegistrationCallback callback_;
109 RequestInfo request_info_; 179 scoped_ptr<RequestInfo> request_info_;
110 GURL registration_url_; 180 GURL registration_url_;
111 181
112 net::BackoffEntry backoff_entry_; 182 net::BackoffEntry backoff_entry_;
113 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 183 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
114 scoped_ptr<net::URLFetcher> url_fetcher_; 184 scoped_ptr<net::URLFetcher> url_fetcher_;
115 int retries_left_; 185 int retries_left_;
116 base::TimeTicks request_start_time_; 186 base::TimeTicks request_start_time_;
117 187
118 // Recorder that records GCM activities for debugging purpose. Not owned. 188 // Recorder that records GCM activities for debugging purpose. Not owned.
119 GCMStatsRecorder* recorder_; 189 GCMStatsRecorder* recorder_;
120 190
121 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; 191 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_;
122 192
123 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); 193 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest);
124 }; 194 };
125 195
126 } // namespace gcm 196 } // namespace gcm
127 197
128 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ 198 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698