OLD | NEW |
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 const std::string& scope, | 127 const std::string& scope, |
128 const std::map<std::string, std::string>& options, | 128 const std::map<std::string, std::string>& options, |
129 const GetTokenCallback& callback) { | 129 const GetTokenCallback& callback) { |
130 EnsureIDGenerated(); | 130 EnsureIDGenerated(); |
131 | 131 |
132 Handler()->GetToken(app_id(), authorized_entity, scope, options, | 132 Handler()->GetToken(app_id(), authorized_entity, scope, options, |
133 base::Bind(&InstanceIDImpl::OnGetTokenCompleted, | 133 base::Bind(&InstanceIDImpl::OnGetTokenCompleted, |
134 weak_ptr_factory_.GetWeakPtr(), callback)); | 134 weak_ptr_factory_.GetWeakPtr(), callback)); |
135 } | 135 } |
136 | 136 |
| 137 void InstanceIDImpl::ValidateToken(const std::string& authorized_entity, |
| 138 const std::string& scope, |
| 139 const std::string& token, |
| 140 const ValidateTokenCallback& callback) { |
| 141 DCHECK(!authorized_entity.empty()); |
| 142 DCHECK(!scope.empty()); |
| 143 DCHECK(!token.empty()); |
| 144 |
| 145 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
| 146 delayed_task_controller_.AddTask(base::Bind( |
| 147 &InstanceIDImpl::DoValidateToken, weak_ptr_factory_.GetWeakPtr(), |
| 148 authorized_entity, scope, token, callback)); |
| 149 return; |
| 150 } |
| 151 |
| 152 DoValidateToken(authorized_entity, scope, token, callback); |
| 153 } |
| 154 |
| 155 void InstanceIDImpl::DoValidateToken(const std::string& authorized_entity, |
| 156 const std::string& scope, |
| 157 const std::string& token, |
| 158 const ValidateTokenCallback& callback) { |
| 159 if (id_.empty()) { |
| 160 callback.Run(false /* is_valid */); |
| 161 return; |
| 162 } |
| 163 |
| 164 Handler()->ValidateToken(app_id(), authorized_entity, scope, token, callback); |
| 165 } |
| 166 |
137 void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, | 167 void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, |
138 const std::string& scope, | 168 const std::string& scope, |
139 const DeleteTokenCallback& callback) { | 169 const DeleteTokenCallback& callback) { |
140 DCHECK(!authorized_entity.empty()); | 170 DCHECK(!authorized_entity.empty()); |
141 DCHECK(!scope.empty()); | 171 DCHECK(!scope.empty()); |
142 | 172 |
143 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { | 173 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
144 delayed_task_controller_.AddTask( | 174 delayed_task_controller_.AddTask( |
145 base::Bind(&InstanceIDImpl::DoDeleteToken, | 175 base::Bind(&InstanceIDImpl::DoDeleteToken, |
146 weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 299 } |
270 | 300 |
271 gcm::InstanceIDHandler* InstanceIDImpl::Handler() { | 301 gcm::InstanceIDHandler* InstanceIDImpl::Handler() { |
272 gcm::InstanceIDHandler* handler = | 302 gcm::InstanceIDHandler* handler = |
273 gcm_driver()->GetInstanceIDHandlerInternal(); | 303 gcm_driver()->GetInstanceIDHandlerInternal(); |
274 DCHECK(handler); | 304 DCHECK(handler); |
275 return handler; | 305 return handler; |
276 } | 306 } |
277 | 307 |
278 } // namespace instance_id | 308 } // namespace instance_id |
OLD | NEW |