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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 52 std::unique_ptr<InstanceID> InstanceID::Create(const std::string& app_id, |
53 const std::string& app_id, | 53 gcm::GCMDriver* gcm_driver) { |
54 gcm::InstanceIDHandler* handler) { | 54 return base::WrapUnique(new InstanceIDImpl(app_id, gcm_driver)); |
55 return base::WrapUnique(new InstanceIDImpl(app_id, handler)); | |
56 } | 55 } |
57 | 56 |
58 InstanceIDImpl::InstanceIDImpl(const std::string& app_id, | 57 InstanceIDImpl::InstanceIDImpl(const std::string& app_id, |
59 gcm::InstanceIDHandler* handler) | 58 gcm::GCMDriver* gcm_driver) |
60 : InstanceID(app_id), handler_(handler), weak_ptr_factory_(this) { | 59 : InstanceID(app_id, gcm_driver), weak_ptr_factory_(this) { |
| 60 handler_ = gcm_driver->GetInstanceIDHandlerInternal(); |
61 DCHECK(handler_); | 61 DCHECK(handler_); |
62 handler_->GetInstanceIDData( | 62 handler_->GetInstanceIDData( |
63 app_id, base::Bind(&InstanceIDImpl::GetInstanceIDDataCompleted, | 63 app_id, base::Bind(&InstanceIDImpl::GetInstanceIDDataCompleted, |
64 weak_ptr_factory_.GetWeakPtr())); | 64 weak_ptr_factory_.GetWeakPtr())); |
65 } | 65 } |
66 | 66 |
67 InstanceIDImpl::~InstanceIDImpl() { | 67 InstanceIDImpl::~InstanceIDImpl() { |
68 } | 68 } |
69 | 69 |
70 void InstanceIDImpl::GetID(const GetIDCallback& callback) { | 70 void InstanceIDImpl::GetID(const GetIDCallback& callback) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 const std::string& scope, | 128 const std::string& scope, |
129 const std::map<std::string, std::string>& options, | 129 const std::map<std::string, std::string>& options, |
130 const GetTokenCallback& callback) { | 130 const GetTokenCallback& callback) { |
131 EnsureIDGenerated(); | 131 EnsureIDGenerated(); |
132 | 132 |
133 handler_->GetToken(app_id(), authorized_entity, scope, options, | 133 handler_->GetToken(app_id(), authorized_entity, scope, options, |
134 base::Bind(&InstanceIDImpl::OnGetTokenCompleted, | 134 base::Bind(&InstanceIDImpl::OnGetTokenCompleted, |
135 weak_ptr_factory_.GetWeakPtr(), callback)); | 135 weak_ptr_factory_.GetWeakPtr(), callback)); |
136 } | 136 } |
137 | 137 |
138 void InstanceIDImpl::DeleteToken(const std::string& authorized_entity, | 138 void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, |
139 const std::string& scope, | 139 const std::string& scope, |
140 const DeleteTokenCallback& callback) { | 140 const DeleteTokenCallback& callback) { |
141 DCHECK(!authorized_entity.empty()); | 141 DCHECK(!authorized_entity.empty()); |
142 DCHECK(!scope.empty()); | 142 DCHECK(!scope.empty()); |
143 | 143 |
144 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { | 144 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
145 delayed_task_controller_.AddTask( | 145 delayed_task_controller_.AddTask( |
146 base::Bind(&InstanceIDImpl::DoDeleteToken, | 146 base::Bind(&InstanceIDImpl::DoDeleteToken, |
147 weak_ptr_factory_.GetWeakPtr(), | 147 weak_ptr_factory_.GetWeakPtr(), |
148 authorized_entity, | 148 authorized_entity, |
149 scope, | 149 scope, |
150 callback)); | 150 callback)); |
(...skipping 11 matching lines...) Expand all Loading... |
162 if (id_.empty()) { | 162 if (id_.empty()) { |
163 callback.Run(InstanceID::INVALID_PARAMETER); | 163 callback.Run(InstanceID::INVALID_PARAMETER); |
164 return; | 164 return; |
165 } | 165 } |
166 | 166 |
167 handler_->DeleteToken(app_id(), authorized_entity, scope, | 167 handler_->DeleteToken(app_id(), authorized_entity, scope, |
168 base::Bind(&InstanceIDImpl::OnDeleteTokenCompleted, | 168 base::Bind(&InstanceIDImpl::OnDeleteTokenCompleted, |
169 weak_ptr_factory_.GetWeakPtr(), callback)); | 169 weak_ptr_factory_.GetWeakPtr(), callback)); |
170 } | 170 } |
171 | 171 |
172 void InstanceIDImpl::DeleteID(const DeleteIDCallback& callback) { | 172 void InstanceIDImpl::DeleteIDImpl(const DeleteIDCallback& callback) { |
173 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { | 173 if (!delayed_task_controller_.CanRunTaskWithoutDelay()) { |
174 delayed_task_controller_.AddTask( | 174 delayed_task_controller_.AddTask( |
175 base::Bind(&InstanceIDImpl::DoDeleteID, | 175 base::Bind(&InstanceIDImpl::DoDeleteID, |
176 weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), |
177 callback)); | 177 callback)); |
178 return; | 178 return; |
179 } | 179 } |
180 | 180 |
181 DoDeleteID(callback); | 181 DoDeleteID(callback); |
182 } | 182 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 id_.erase(std::remove(id_.begin(), id_.end(), '='), id_.end()); | 263 id_.erase(std::remove(id_.begin(), id_.end(), '='), id_.end()); |
264 | 264 |
265 creation_time_ = base::Time::Now(); | 265 creation_time_ = base::Time::Now(); |
266 | 266 |
267 // Save to the persistent store. | 267 // Save to the persistent store. |
268 handler_->AddInstanceIDData( | 268 handler_->AddInstanceIDData( |
269 app_id(), id_, base::Int64ToString(creation_time_.ToInternalValue())); | 269 app_id(), id_, base::Int64ToString(creation_time_.ToInternalValue())); |
270 } | 270 } |
271 | 271 |
272 } // namespace instance_id | 272 } // namespace instance_id |
OLD | NEW |