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

Side by Side Diff: components/gcm_driver/instance_id/instance_id_impl.cc

Issue 2111973002: Add support for GCM subtypes to desktop Instance ID implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid9push
Patch Set: Address review comments Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/gcm_driver/instance_id/instance_id_impl.h" 5 #include "components/gcm_driver/instance_id/instance_id_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 default: 42 default:
43 NOTREACHED() << "Unexpected value of result cannot be converted: " 43 NOTREACHED() << "Unexpected value of result cannot be converted: "
44 << result; 44 << result;
45 } 45 }
46 return InstanceID::UNKNOWN_ERROR; 46 return InstanceID::UNKNOWN_ERROR;
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 // static 51 // static
52 std::unique_ptr<InstanceID> InstanceID::Create(const std::string& app_id, 52 std::unique_ptr<InstanceID> InstanceID::CreateInternal(
53 gcm::GCMDriver* gcm_driver) { 53 const std::string& app_id,
54 return base::WrapUnique(new InstanceIDImpl(app_id, gcm_driver)); 54 bool use_subtype,
55 gcm::GCMDriver* gcm_driver) {
56 return base::WrapUnique(new InstanceIDImpl(app_id, use_subtype, gcm_driver));
55 } 57 }
56 58
57 InstanceIDImpl::InstanceIDImpl(const std::string& app_id, 59 InstanceIDImpl::InstanceIDImpl(const std::string& app_id,
60 bool use_subtype,
58 gcm::GCMDriver* gcm_driver) 61 gcm::GCMDriver* gcm_driver)
59 : InstanceID(app_id, gcm_driver), weak_ptr_factory_(this) { 62 : InstanceID(app_id, gcm_driver),
63 use_subtype_(use_subtype),
64 weak_ptr_factory_(this) {
60 Handler()->GetInstanceIDData( 65 Handler()->GetInstanceIDData(
61 app_id, base::Bind(&InstanceIDImpl::GetInstanceIDDataCompleted, 66 app_id, base::Bind(&InstanceIDImpl::GetInstanceIDDataCompleted,
62 weak_ptr_factory_.GetWeakPtr())); 67 weak_ptr_factory_.GetWeakPtr()));
63 } 68 }
64 69
65 InstanceIDImpl::~InstanceIDImpl() { 70 InstanceIDImpl::~InstanceIDImpl() {
66 } 71 }
67 72
68 void InstanceIDImpl::GetID(const GetIDCallback& callback) { 73 void InstanceIDImpl::GetID(const GetIDCallback& callback) {
69 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { 74 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DoGetToken(authorized_entity, scope, options, callback); 126 DoGetToken(authorized_entity, scope, options, callback);
122 } 127 }
123 128
124 void InstanceIDImpl::DoGetToken( 129 void InstanceIDImpl::DoGetToken(
125 const std::string& authorized_entity, 130 const std::string& authorized_entity,
126 const std::string& scope, 131 const std::string& scope,
127 const std::map<std::string, std::string>& options, 132 const std::map<std::string, std::string>& options,
128 const GetTokenCallback& callback) { 133 const GetTokenCallback& callback) {
129 EnsureIDGenerated(); 134 EnsureIDGenerated();
130 135
131 Handler()->GetToken(app_id(), authorized_entity, scope, options, 136 Handler()->GetToken(app_id(), use_subtype_, authorized_entity, scope, options,
132 base::Bind(&InstanceIDImpl::OnGetTokenCompleted, 137 base::Bind(&InstanceIDImpl::OnGetTokenCompleted,
133 weak_ptr_factory_.GetWeakPtr(), callback)); 138 weak_ptr_factory_.GetWeakPtr(), callback));
134 } 139 }
135 140
136 void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, 141 void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity,
137 const std::string& scope, 142 const std::string& scope,
138 const DeleteTokenCallback& callback) { 143 const DeleteTokenCallback& callback) {
139 DCHECK(!authorized_entity.empty()); 144 DCHECK(!authorized_entity.empty());
140 DCHECK(!scope.empty()); 145 DCHECK(!scope.empty());
141 146
(...skipping 13 matching lines...) Expand all
155 void InstanceIDImpl::DoDeleteToken( 160 void InstanceIDImpl::DoDeleteToken(
156 const std::string& authorized_entity, 161 const std::string& authorized_entity,
157 const std::string& scope, 162 const std::string& scope,
158 const DeleteTokenCallback& callback) { 163 const DeleteTokenCallback& callback) {
159 // Nothing to delete if the ID has not been generated. 164 // Nothing to delete if the ID has not been generated.
160 if (id_.empty()) { 165 if (id_.empty()) {
161 callback.Run(InstanceID::INVALID_PARAMETER); 166 callback.Run(InstanceID::INVALID_PARAMETER);
162 return; 167 return;
163 } 168 }
164 169
165 Handler()->DeleteToken(app_id(), authorized_entity, scope, 170 Handler()->DeleteToken(app_id(), use_subtype_, authorized_entity, scope,
166 base::Bind(&InstanceIDImpl::OnDeleteTokenCompleted, 171 base::Bind(&InstanceIDImpl::OnDeleteTokenCompleted,
167 weak_ptr_factory_.GetWeakPtr(), callback)); 172 weak_ptr_factory_.GetWeakPtr(), callback));
168 } 173 }
169 174
170 void InstanceIDImpl::DeleteIDImpl(const DeleteIDCallback& callback) { 175 void InstanceIDImpl::DeleteIDImpl(const DeleteIDCallback& callback) {
171 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { 176 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) {
172 delayed_task_controller_.AddTask( 177 delayed_task_controller_.AddTask(
173 base::Bind(&InstanceIDImpl::DoDeleteID, 178 base::Bind(&InstanceIDImpl::DoDeleteID,
174 weak_ptr_factory_.GetWeakPtr(), 179 weak_ptr_factory_.GetWeakPtr(),
175 callback)); 180 callback));
176 return; 181 return;
177 } 182 }
178 183
179 DoDeleteID(callback); 184 DoDeleteID(callback);
180 } 185 }
181 186
182 void InstanceIDImpl::DoDeleteID(const DeleteIDCallback& callback) { 187 void InstanceIDImpl::DoDeleteID(const DeleteIDCallback& callback) {
183 // Nothing to do if ID has not been generated. 188 // Nothing to do if ID has not been generated.
184 if (id_.empty()) { 189 if (id_.empty()) {
185 callback.Run(InstanceID::SUCCESS); 190 callback.Run(InstanceID::SUCCESS);
186 return; 191 return;
187 } 192 }
188 193
189 Handler()->DeleteAllTokensForApp( 194 Handler()->DeleteAllTokensForApp(
190 app_id(), base::Bind(&InstanceIDImpl::OnDeleteIDCompleted, 195 app_id(), use_subtype_,
191 weak_ptr_factory_.GetWeakPtr(), callback)); 196 base::Bind(&InstanceIDImpl::OnDeleteIDCompleted,
197 weak_ptr_factory_.GetWeakPtr(), callback));
192 198
193 Handler()->RemoveInstanceIDData(app_id()); 199 Handler()->RemoveInstanceIDData(app_id());
194 200
195 id_.clear(); 201 id_.clear();
196 creation_time_ = base::Time(); 202 creation_time_ = base::Time();
197 } 203 }
198 204
199 void InstanceIDImpl::OnGetTokenCompleted(const GetTokenCallback& callback, 205 void InstanceIDImpl::OnGetTokenCompleted(const GetTokenCallback& callback,
200 const std::string& token, 206 const std::string& token,
201 gcm::GCMClient::Result result) { 207 gcm::GCMClient::Result result) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 274 }
269 275
270 gcm::InstanceIDHandler* InstanceIDImpl::Handler() { 276 gcm::InstanceIDHandler* InstanceIDImpl::Handler() {
271 gcm::InstanceIDHandler* handler = 277 gcm::InstanceIDHandler* handler =
272 gcm_driver()->GetInstanceIDHandlerInternal(); 278 gcm_driver()->GetInstanceIDHandlerInternal();
273 DCHECK(handler); 279 DCHECK(handler);
274 return handler; 280 return handler;
275 } 281 }
276 282
277 } // namespace instance_id 283 } // namespace instance_id
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698