OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ui/webui/settings/chromeos/fingerprint_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/fingerprint_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 void FingerprintHandler::OnEnrollScanDone(uint32_t scan_result, | 118 void FingerprintHandler::OnEnrollScanDone(uint32_t scan_result, |
119 bool enroll_session_complete, | 119 bool enroll_session_complete, |
120 int percent_complete) { | 120 int percent_complete) { |
121 AllowJavascript(); | 121 AllowJavascript(); |
122 auto scan_attempt = base::MakeUnique<base::DictionaryValue>(); | 122 auto scan_attempt = base::MakeUnique<base::DictionaryValue>(); |
123 scan_attempt->SetInteger("result", scan_result); | 123 scan_attempt->SetInteger("result", scan_result); |
124 scan_attempt->SetBoolean("isComplete", enroll_session_complete); | 124 scan_attempt->SetBoolean("isComplete", enroll_session_complete); |
125 scan_attempt->SetInteger("percentComplete", percent_complete); | 125 scan_attempt->SetInteger("percentComplete", percent_complete); |
126 | 126 |
127 CallJavascriptFunction("cr.webUIListenerCallback", | 127 FireWebUIListener("on-fingerprint-scan-received", *scan_attempt); |
128 base::Value("on-fingerprint-scan-received"), | |
129 *scan_attempt); | |
130 } | 128 } |
131 | 129 |
132 void FingerprintHandler::OnAuthScanDone( | 130 void FingerprintHandler::OnAuthScanDone( |
133 uint32_t scan_result, | 131 uint32_t scan_result, |
134 const std::unordered_map<std::string, std::vector<std::string>>& matches) { | 132 const std::unordered_map<std::string, std::vector<std::string>>& matches) { |
135 if (SessionManager::Get()->session_state() == SessionState::LOCKED) | 133 if (SessionManager::Get()->session_state() == SessionState::LOCKED) |
136 return; | 134 return; |
137 | 135 |
138 // When the user touches the sensor, highlight the label(s) that finger is | 136 // When the user touches the sensor, highlight the label(s) that finger is |
139 // associated with, if it is registered with this user. | 137 // associated with, if it is registered with this user. |
140 auto it = matches.find(user_id_); | 138 auto it = matches.find(user_id_); |
141 if (it == matches.end() || it->second.size() < 1) | 139 if (it == matches.end() || it->second.size() < 1) |
142 return; | 140 return; |
143 | 141 |
144 AllowJavascript(); | 142 AllowJavascript(); |
145 auto fingerprint_ids = base::MakeUnique<base::ListValue>(); | 143 auto fingerprint_ids = base::MakeUnique<base::ListValue>(); |
146 | 144 |
147 for (const std::string& matched_path : it->second) { | 145 for (const std::string& matched_path : it->second) { |
148 auto path_it = std::find(fingerprints_paths_.begin(), | 146 auto path_it = std::find(fingerprints_paths_.begin(), |
149 fingerprints_paths_.end(), matched_path); | 147 fingerprints_paths_.end(), matched_path); |
150 DCHECK(path_it != fingerprints_paths_.end()); | 148 DCHECK(path_it != fingerprints_paths_.end()); |
151 fingerprint_ids->AppendInteger( | 149 fingerprint_ids->AppendInteger( |
152 static_cast<int>(path_it - fingerprints_paths_.begin())); | 150 static_cast<int>(path_it - fingerprints_paths_.begin())); |
153 } | 151 } |
154 | 152 |
155 auto fingerprint_attempt = base::MakeUnique<base::DictionaryValue>(); | 153 auto fingerprint_attempt = base::MakeUnique<base::DictionaryValue>(); |
156 fingerprint_attempt->SetInteger("result", scan_result); | 154 fingerprint_attempt->SetInteger("result", scan_result); |
157 fingerprint_attempt->Set("indexes", std::move(fingerprint_ids)); | 155 fingerprint_attempt->Set("indexes", std::move(fingerprint_ids)); |
158 | 156 |
159 CallJavascriptFunction("cr.webUIListenerCallback", | 157 FireWebUIListener("on-fingerprint-attempt-received", *fingerprint_attempt); |
160 base::Value("on-fingerprint-attempt-received"), | |
161 *fingerprint_attempt); | |
162 } | 158 } |
163 | 159 |
164 void FingerprintHandler::OnSessionFailed() {} | 160 void FingerprintHandler::OnSessionFailed() {} |
165 | 161 |
166 void FingerprintHandler::OnSessionStateChanged() { | 162 void FingerprintHandler::OnSessionStateChanged() { |
167 SessionState state = SessionManager::Get()->session_state(); | 163 SessionState state = SessionManager::Get()->session_state(); |
168 | 164 |
169 AllowJavascript(); | 165 AllowJavascript(); |
170 CallJavascriptFunction("cr.webUIListenerCallback", | 166 FireWebUIListener("on-screen-locked", |
171 base::Value("on-screen-locked"), | 167 base::Value(state == SessionState::LOCKED)); |
172 base::Value(state == SessionState::LOCKED)); | |
173 } | 168 } |
174 | 169 |
175 void FingerprintHandler::HandleGetFingerprintsList( | 170 void FingerprintHandler::HandleGetFingerprintsList( |
176 const base::ListValue* args) { | 171 const base::ListValue* args) { |
177 CHECK_EQ(1U, args->GetSize()); | 172 CHECK_EQ(1U, args->GetSize()); |
178 std::string callback_id; | 173 std::string callback_id; |
179 CHECK(args->GetString(0, &callback_id)); | 174 CHECK(args->GetString(0, &callback_id)); |
180 | 175 |
181 fp_service_->GetRecordsForUser( | 176 fp_service_->GetRecordsForUser( |
182 user_id_, base::Bind(&FingerprintHandler::OnGetFingerprintsList, | 177 user_id_, base::Bind(&FingerprintHandler::OnGetFingerprintsList, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 weak_ptr_factory_.GetWeakPtr())); | 318 weak_ptr_factory_.GetWeakPtr())); |
324 } | 319 } |
325 | 320 |
326 void FingerprintHandler::OnEndCurrentAuthSession(bool success) { | 321 void FingerprintHandler::OnEndCurrentAuthSession(bool success) { |
327 if (!success) | 322 if (!success) |
328 LOG(ERROR) << "Failed to end current fingerprint authentication session."; | 323 LOG(ERROR) << "Failed to end current fingerprint authentication session."; |
329 } | 324 } |
330 | 325 |
331 } // namespace settings | 326 } // namespace settings |
332 } // namespace chromeos | 327 } // namespace chromeos |
OLD | NEW |