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

Side by Side Diff: google_apis/gcm/engine/unregistration_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_UNREGISTRATION_REQUEST_H_ 5 #ifndef GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_
6 #define GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ 6 #define GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 UNKNOWN_ERROR, // Unknown error. 48 UNKNOWN_ERROR, // Unknown error.
49 // NOTE: Always keep this entry at the end. Add new status types only 49 // NOTE: Always keep this entry at the end. Add new status types only
50 // immediately above this line. Make sure to update the corresponding 50 // immediately above this line. Make sure to update the corresponding
51 // histogram enum accordingly. 51 // histogram enum accordingly.
52 UNREGISTRATION_STATUS_COUNT, 52 UNREGISTRATION_STATUS_COUNT,
53 }; 53 };
54 54
55 // Callback completing the unregistration request. 55 // Callback completing the unregistration request.
56 typedef base::Callback<void(Status success)> UnregistrationCallback; 56 typedef base::Callback<void(Status success)> UnregistrationCallback;
57 57
58 // Details of the of the Unregistration Request. All parameters are mandatory. 58 // Encapsulates the common info about an unregistration/token-deletion
59 struct GCM_EXPORT RequestInfo { 59 // request.
60 RequestInfo(uint64 android_id, 60 class GCM_EXPORT RequestInfo {
61 uint64 security_token, 61 public:
62 const std::string& app_id); 62 RequestInfo();
63 ~RequestInfo(); 63 virtual ~RequestInfo();
64 64
65 virtual void BuildRequestHeaders(std::string* extra_headers);
66 virtual void BuildRequestBody(std::string* body);
67
68 std::string app_id() const { return app_id_; }
69
70 void set_chrome_version(const std::string& chrome_version) {
71 chrome_version_ = chrome_version;
72 }
73 void set_android_id(uint64 android_id) {
74 android_id_ = android_id;
75 }
76 void set_security_token(uint64 security_token) {
77 security_token_ = security_token;
78 }
79 void set_app_id(const std::string& app_id) {
80 app_id_ = app_id;
81 }
82
83 protected:
84 // Version to pass.
85 std::string chrome_version_;
65 // Android ID of the device. 86 // Android ID of the device.
66 uint64 android_id; 87 uint64 android_id_;
67 // Security token of the device. 88 // Security token of the device.
68 uint64 security_token; 89 uint64 security_token_;
69 // Application ID. 90 // Application ID.
70 std::string app_id; 91 std::string app_id_;
92
93 private:
94 DISALLOW_COPY_AND_ASSIGN(RequestInfo);
95 };
96
97 // GCM unregistration request.
98 class GCM_EXPORT GCMRequestInfo : public RequestInfo {
99 public:
100 GCMRequestInfo();
101 ~GCMRequestInfo() override;
102
103 // RequestInfo overrides:
104 void BuildRequestBody(std::string* body) override;
105
106 private:
107 DISALLOW_COPY_AND_ASSIGN(GCMRequestInfo);
108 };
109
110 // Instance ID token deletion request.
111 class GCM_EXPORT InstanceIDRequestInfo : public RequestInfo {
112 public:
113 InstanceIDRequestInfo();
114 ~InstanceIDRequestInfo() override;
115
116 // RequestInfo overrides:
117 void BuildRequestBody(std::string* body) override;
118
119 void set_instance_id(const std::string& instance_id) {
120 instance_id_ = instance_id;
121 }
122 void set_authorized_entity(const std::string& authorized_entity) {
123 authorized_entity_ = authorized_entity;
124 }
125 void set_scope(const std::string& scope) {
126 scope_ = scope;
127 }
128
129 private:
130 std::string instance_id_;
131 std::string authorized_entity_;
132 std::string scope_;
133
134 DISALLOW_COPY_AND_ASSIGN(InstanceIDRequestInfo);
71 }; 135 };
72 136
73 // Creates an instance of UnregistrationRequest. |callback| will be called 137 // Creates an instance of UnregistrationRequest. |callback| will be called
74 // once registration has been revoked or there has been an error that makes 138 // once registration has been revoked or there has been an error that makes
75 // further retries pointless. 139 // further retries pointless.
76 UnregistrationRequest( 140 UnregistrationRequest(
77 const GURL& registration_url, 141 const GURL& registration_url,
78 const RequestInfo& request_info, 142 scoped_ptr<RequestInfo> request_info,
79 const net::BackoffEntry::Policy& backoff_policy, 143 const net::BackoffEntry::Policy& backoff_policy,
80 const UnregistrationCallback& callback, 144 const UnregistrationCallback& callback,
81 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 145 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
82 GCMStatsRecorder* recorder); 146 GCMStatsRecorder* recorder);
83 ~UnregistrationRequest() override; 147 ~UnregistrationRequest() override;
84 148
85 // Starts an unregistration request. 149 // Starts an unregistration request.
86 void Start(); 150 void Start();
87 151
88 // URLFetcherDelegate implementation. 152 // URLFetcherDelegate implementation.
89 void OnURLFetchComplete(const net::URLFetcher* source) override; 153 void OnURLFetchComplete(const net::URLFetcher* source) override;
90 154
91 private: 155 private:
92 // Schedules a retry attempt and informs the backoff of previous request's 156 // Schedules a retry attempt and informs the backoff of previous request's
93 // failure, when |update_backoff| is true. 157 // failure, when |update_backoff| is true.
94 void RetryWithBackoff(bool update_backoff); 158 void RetryWithBackoff(bool update_backoff);
95 159
96 UnregistrationCallback callback_; 160 UnregistrationCallback callback_;
97 RequestInfo request_info_; 161 scoped_ptr<RequestInfo> request_info_;
98 GURL registration_url_; 162 GURL registration_url_;
99 163
100 net::BackoffEntry backoff_entry_; 164 net::BackoffEntry backoff_entry_;
101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 165 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
102 scoped_ptr<net::URLFetcher> url_fetcher_; 166 scoped_ptr<net::URLFetcher> url_fetcher_;
103 base::TimeTicks request_start_time_; 167 base::TimeTicks request_start_time_;
104 168
105 // Recorder that records GCM activities for debugging purpose. Not owned. 169 // Recorder that records GCM activities for debugging purpose. Not owned.
106 GCMStatsRecorder* recorder_; 170 GCMStatsRecorder* recorder_;
107 171
108 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_; 172 base::WeakPtrFactory<UnregistrationRequest> weak_ptr_factory_;
109 173
110 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest); 174 DISALLOW_COPY_AND_ASSIGN(UnregistrationRequest);
111 }; 175 };
112 176
113 } // namespace gcm 177 } // namespace gcm
114 178
115 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_ 179 #endif // GOOGLE_APIS_GCM_ENGINE_UNREGISTRATION_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698