OLD | NEW |
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 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices)) | 44 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices)) |
45 devices.clear(); | 45 devices.clear(); |
46 | 46 |
47 // Only one pending request. | 47 // Only one pending request. |
48 DCHECK(!HasPendingOperations()); | 48 DCHECK(!HasPendingOperations()); |
49 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( | 49 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( |
50 user_context, | 50 user_context, |
51 devices, | 51 devices, |
52 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, | 52 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, |
53 weak_ptr_factory_.GetWeakPtr(), | 53 weak_ptr_factory_.GetWeakPtr(), |
54 user_context, | 54 devices.size(), |
55 devices, | |
56 callback))); | 55 callback))); |
57 create_keys_op_->Start(); | 56 create_keys_op_->Start(); |
58 } | 57 } |
59 | 58 |
60 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, | 59 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, |
61 size_t start_index, | 60 size_t start_index, |
62 const RemoveKeysCallback& callback) { | 61 const RemoveKeysCallback& callback) { |
63 // Must have the secret. | 62 // Must have the secret. |
64 DCHECK(!user_context.GetKey()->GetSecret().empty()); | 63 DCHECK(!user_context.GetKey()->GetSecret().empty()); |
65 // Only one pending request. | 64 // Only one pending request. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 164 |
166 bool EasyUnlockKeyManager::HasPendingOperations() const { | 165 bool EasyUnlockKeyManager::HasPendingOperations() const { |
167 return create_keys_op_ || remove_keys_op_ || !get_keys_ops_.empty(); | 166 return create_keys_op_ || remove_keys_op_ || !get_keys_ops_.empty(); |
168 } | 167 } |
169 | 168 |
170 int EasyUnlockKeyManager::GetNextOperationId() { | 169 int EasyUnlockKeyManager::GetNextOperationId() { |
171 return ++operation_id_; | 170 return ++operation_id_; |
172 } | 171 } |
173 | 172 |
174 void EasyUnlockKeyManager::OnKeysCreated( | 173 void EasyUnlockKeyManager::OnKeysCreated( |
175 const UserContext& user_context, | 174 size_t remove_start_index, |
176 const EasyUnlockDeviceKeyDataList& devices, | |
177 const RefreshKeysCallback& callback, | 175 const RefreshKeysCallback& callback, |
178 bool create_success) { | 176 bool create_success) { |
179 scoped_ptr<EasyUnlockCreateKeysOperation> op = create_keys_op_.Pass(); | 177 scoped_ptr<EasyUnlockCreateKeysOperation> op = create_keys_op_.Pass(); |
180 if (!callback.is_null()) | 178 if (!callback.is_null()) |
181 callback.Run(create_success); | 179 callback.Run(create_success); |
182 | 180 |
183 // Remove extra existing keys. | 181 // Remove extra existing keys. |
184 RemoveKeys(user_context, devices.size(), RemoveKeysCallback()); | 182 RemoveKeys(op->user_context(), remove_start_index, RemoveKeysCallback()); |
185 } | 183 } |
186 | 184 |
187 void EasyUnlockKeyManager::OnKeysRemoved(const RemoveKeysCallback& callback, | 185 void EasyUnlockKeyManager::OnKeysRemoved(const RemoveKeysCallback& callback, |
188 bool remove_success) { | 186 bool remove_success) { |
189 scoped_ptr<EasyUnlockRemoveKeysOperation> op = remove_keys_op_.Pass(); | 187 scoped_ptr<EasyUnlockRemoveKeysOperation> op = remove_keys_op_.Pass(); |
190 if (!callback.is_null()) | 188 if (!callback.is_null()) |
191 callback.Run(remove_success); | 189 callback.Run(remove_success); |
192 } | 190 } |
193 | 191 |
194 void EasyUnlockKeyManager::OnKeysFetched( | 192 void EasyUnlockKeyManager::OnKeysFetched( |
195 int op_id, | 193 int op_id, |
196 const GetDeviceDataListCallback& callback, | 194 const GetDeviceDataListCallback& callback, |
197 bool fetch_success, | 195 bool fetch_success, |
198 const EasyUnlockDeviceKeyDataList& fetched_data) { | 196 const EasyUnlockDeviceKeyDataList& fetched_data) { |
199 std::map<int, EasyUnlockGetKeysOperation*>::iterator it = | 197 std::map<int, EasyUnlockGetKeysOperation*>::iterator it = |
200 get_keys_ops_.find(op_id); | 198 get_keys_ops_.find(op_id); |
201 scoped_ptr<EasyUnlockGetKeysOperation> op; | 199 scoped_ptr<EasyUnlockGetKeysOperation> op; |
202 if (it != get_keys_ops_.end()) { | 200 if (it != get_keys_ops_.end()) { |
203 op.reset(it->second); | 201 op.reset(it->second); |
204 get_keys_ops_.erase(it); | 202 get_keys_ops_.erase(it); |
205 } else { | 203 } else { |
206 NOTREACHED(); | 204 NOTREACHED(); |
207 } | 205 } |
208 | 206 |
209 if (!callback.is_null()) | 207 if (!callback.is_null()) |
210 callback.Run(fetch_success, fetched_data); | 208 callback.Run(fetch_success, fetched_data); |
211 } | 209 } |
212 | 210 |
213 } // namespace chromeos | 211 } // namespace chromeos |
OLD | NEW |