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

Side by Side Diff: chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.cc

Issue 585213002: [Easy signin] Wire up userClick auth attempt to easy unlock app and back (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@easy_signin_focused_user_changed_observer
Patch Set: . Created 6 years, 3 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 #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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices)) 49 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices))
50 devices.clear(); 50 devices.clear();
51 51
52 // Only one pending request. 52 // Only one pending request.
53 DCHECK(!HasPendingOperations()); 53 DCHECK(!HasPendingOperations());
54 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( 54 create_keys_op_.reset(new EasyUnlockCreateKeysOperation(
55 user_context, 55 user_context,
56 devices, 56 devices,
57 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, 57 base::Bind(&EasyUnlockKeyManager::OnKeysCreated,
58 weak_ptr_factory_.GetWeakPtr(), 58 weak_ptr_factory_.GetWeakPtr(),
59 user_context, 59 devices.size(),
60 devices,
61 callback))); 60 callback)));
62 create_keys_op_->Start(); 61 create_keys_op_->Start();
63 } 62 }
64 63
65 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, 64 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context,
66 size_t start_index, 65 size_t start_index,
67 const RemoveKeysCallback& callback) { 66 const RemoveKeysCallback& callback) {
68 // Must have the secret. 67 // Must have the secret.
69 DCHECK(!user_context.GetKey()->GetSecret().empty()); 68 DCHECK(!user_context.GetKey()->GetSecret().empty());
70 // Only one pending request. 69 // Only one pending request.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 177
179 bool EasyUnlockKeyManager::HasPendingOperations() const { 178 bool EasyUnlockKeyManager::HasPendingOperations() const {
180 return create_keys_op_ || remove_keys_op_ || !get_keys_ops_.empty(); 179 return create_keys_op_ || remove_keys_op_ || !get_keys_ops_.empty();
181 } 180 }
182 181
183 int EasyUnlockKeyManager::GetNextOperationId() { 182 int EasyUnlockKeyManager::GetNextOperationId() {
184 return ++operation_id_; 183 return ++operation_id_;
185 } 184 }
186 185
187 void EasyUnlockKeyManager::OnKeysCreated( 186 void EasyUnlockKeyManager::OnKeysCreated(
188 const UserContext& user_context, 187 size_t remove_start_index,
189 const EasyUnlockDeviceKeyDataList& devices,
190 const RefreshKeysCallback& callback, 188 const RefreshKeysCallback& callback,
191 bool create_success) { 189 bool create_success) {
192 scoped_ptr<EasyUnlockCreateKeysOperation> op = create_keys_op_.Pass(); 190 scoped_ptr<EasyUnlockCreateKeysOperation> op = create_keys_op_.Pass();
193 if (!callback.is_null()) 191 if (!callback.is_null())
194 callback.Run(create_success); 192 callback.Run(create_success);
195 193
196 // Remove extra existing keys. 194 // Remove extra existing keys.
197 RemoveKeys(user_context, devices.size(), RemoveKeysCallback()); 195 RemoveKeys(op->user_context(), remove_start_index, RemoveKeysCallback());
Tim Song 2014/09/23 19:37:59 There might be a race condition here if RemoveKeys
xiyuan 2014/09/23 19:56:58 Currently, we have a poor man's DCHECK(!HasPending
tbarzic 2014/09/23 19:58:34 I had a similar concern when this first got in, bu
198 } 196 }
199 197
200 void EasyUnlockKeyManager::OnKeysRemoved(const RemoveKeysCallback& callback, 198 void EasyUnlockKeyManager::OnKeysRemoved(const RemoveKeysCallback& callback,
201 bool remove_success) { 199 bool remove_success) {
202 scoped_ptr<EasyUnlockRemoveKeysOperation> op = remove_keys_op_.Pass(); 200 scoped_ptr<EasyUnlockRemoveKeysOperation> op = remove_keys_op_.Pass();
203 if (!callback.is_null()) 201 if (!callback.is_null())
204 callback.Run(remove_success); 202 callback.Run(remove_success);
205 } 203 }
206 204
207 void EasyUnlockKeyManager::OnKeysFetched( 205 void EasyUnlockKeyManager::OnKeysFetched(
208 int op_id, 206 int op_id,
209 const GetDeviceDataListCallback& callback, 207 const GetDeviceDataListCallback& callback,
210 bool fetch_success, 208 bool fetch_success,
211 const EasyUnlockDeviceKeyDataList& fetched_data) { 209 const EasyUnlockDeviceKeyDataList& fetched_data) {
212 std::map<int, EasyUnlockGetKeysOperation*>::iterator it = 210 std::map<int, EasyUnlockGetKeysOperation*>::iterator it =
213 get_keys_ops_.find(op_id); 211 get_keys_ops_.find(op_id);
214 scoped_ptr<EasyUnlockGetKeysOperation> op; 212 scoped_ptr<EasyUnlockGetKeysOperation> op;
215 if (it != get_keys_ops_.end()) { 213 if (it != get_keys_ops_.end()) {
216 op.reset(it->second); 214 op.reset(it->second);
217 get_keys_ops_.erase(it); 215 get_keys_ops_.erase(it);
218 } else { 216 } else {
219 NOTREACHED(); 217 NOTREACHED();
220 } 218 }
221 219
222 if (!callback.is_null()) 220 if (!callback.is_null())
223 callback.Run(fetch_success, fetched_data); 221 callback.Run(fetch_success, fetched_data);
224 } 222 }
225 223
226 } // namespace chromeos 224 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698