| 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 10 matching lines...) Expand all Loading... |
| 21 // The max number of fingerprints that can be stored. | 21 // The max number of fingerprints that can be stored. |
| 22 const int kMaxAllowedFingerprints = 5; | 22 const int kMaxAllowedFingerprints = 5; |
| 23 | 23 |
| 24 std::unique_ptr<base::DictionaryValue> GetFingerprintsInfo( | 24 std::unique_ptr<base::DictionaryValue> GetFingerprintsInfo( |
| 25 const std::vector<base::string16>& fingerprints_list) { | 25 const std::vector<base::string16>& fingerprints_list) { |
| 26 auto response = base::MakeUnique<base::DictionaryValue>(); | 26 auto response = base::MakeUnique<base::DictionaryValue>(); |
| 27 auto fingerprints = base::MakeUnique<base::ListValue>(); | 27 auto fingerprints = base::MakeUnique<base::ListValue>(); |
| 28 | 28 |
| 29 DCHECK(int{fingerprints_list.size()} <= kMaxAllowedFingerprints); | 29 DCHECK(int{fingerprints_list.size()} <= kMaxAllowedFingerprints); |
| 30 for (auto& fingerprint_name: fingerprints_list) { | 30 for (auto& fingerprint_name: fingerprints_list) { |
| 31 std::unique_ptr<base::StringValue> str = | 31 std::unique_ptr<base::Value> str = |
| 32 base::MakeUnique<base::StringValue>(fingerprint_name); | 32 base::MakeUnique<base::Value>(fingerprint_name); |
| 33 fingerprints->Append(std::move(str)); | 33 fingerprints->Append(std::move(str)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 response->Set("fingerprintsList", std::move(fingerprints)); | 36 response->Set("fingerprintsList", std::move(fingerprints)); |
| 37 response->SetBoolean( | 37 response->SetBoolean( |
| 38 "isMaxed", int{fingerprints_list.size()} >= kMaxAllowedFingerprints); | 38 "isMaxed", int{fingerprints_list.size()} >= kMaxAllowedFingerprints); |
| 39 return response; | 39 return response; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void FingerprintHandler::HandleGetFingerprintsList( | 95 void FingerprintHandler::HandleGetFingerprintsList( |
| 96 const base::ListValue* args) { | 96 const base::ListValue* args) { |
| 97 AllowJavascript(); | 97 AllowJavascript(); |
| 98 | 98 |
| 99 CHECK_EQ(1U, args->GetSize()); | 99 CHECK_EQ(1U, args->GetSize()); |
| 100 std::string callback_id; | 100 std::string callback_id; |
| 101 CHECK(args->GetString(0, &callback_id)); | 101 CHECK(args->GetString(0, &callback_id)); |
| 102 | 102 |
| 103 std::unique_ptr<base::DictionaryValue> fingerprint_info = | 103 std::unique_ptr<base::DictionaryValue> fingerprint_info = |
| 104 GetFingerprintsInfo(fingerprints_list_); | 104 GetFingerprintsInfo(fingerprints_list_); |
| 105 ResolveJavascriptCallback(base::StringValue(callback_id), *fingerprint_info); | 105 ResolveJavascriptCallback(base::Value(callback_id), *fingerprint_info); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FingerprintHandler::HandleGetNumFingerprints(const base::ListValue* args) { | 108 void FingerprintHandler::HandleGetNumFingerprints(const base::ListValue* args) { |
| 109 AllowJavascript(); | 109 AllowJavascript(); |
| 110 | 110 |
| 111 CHECK_EQ(1U, args->GetSize()); | 111 CHECK_EQ(1U, args->GetSize()); |
| 112 std::string callback_id; | 112 std::string callback_id; |
| 113 CHECK(args->GetString(0, &callback_id)); | 113 CHECK(args->GetString(0, &callback_id)); |
| 114 | 114 |
| 115 ResolveJavascriptCallback(base::StringValue(callback_id), | 115 ResolveJavascriptCallback(base::Value(callback_id), |
| 116 base::Value(int{fingerprints_list_.size()})); | 116 base::Value(int{fingerprints_list_.size()})); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void FingerprintHandler::HandleStartEnroll(const base::ListValue* args) { | 119 void FingerprintHandler::HandleStartEnroll(const base::ListValue* args) { |
| 120 } | 120 } |
| 121 | 121 |
| 122 void FingerprintHandler::HandleCancelCurrentEnroll( | 122 void FingerprintHandler::HandleCancelCurrentEnroll( |
| 123 const base::ListValue* args) { | 123 const base::ListValue* args) { |
| 124 } | 124 } |
| 125 | 125 |
| 126 void FingerprintHandler::HandleGetEnrollmentLabel(const base::ListValue* args) { | 126 void FingerprintHandler::HandleGetEnrollmentLabel(const base::ListValue* args) { |
| 127 AllowJavascript(); | 127 AllowJavascript(); |
| 128 | 128 |
| 129 CHECK_EQ(2U, args->GetSize()); | 129 CHECK_EQ(2U, args->GetSize()); |
| 130 std::string callback_id; | 130 std::string callback_id; |
| 131 int index; | 131 int index; |
| 132 CHECK(args->GetString(0, &callback_id)); | 132 CHECK(args->GetString(0, &callback_id)); |
| 133 CHECK(args->GetInteger(1, &index)); | 133 CHECK(args->GetInteger(1, &index)); |
| 134 | 134 |
| 135 DCHECK(index < int{fingerprints_list_.size()}); | 135 DCHECK(index < int{fingerprints_list_.size()}); |
| 136 ResolveJavascriptCallback(base::StringValue(callback_id), | 136 ResolveJavascriptCallback(base::Value(callback_id), |
| 137 base::StringValue(fingerprints_list_[index])); | 137 base::Value(fingerprints_list_[index])); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void FingerprintHandler::HandleRemoveEnrollment(const base::ListValue* args) { | 140 void FingerprintHandler::HandleRemoveEnrollment(const base::ListValue* args) { |
| 141 AllowJavascript(); | 141 AllowJavascript(); |
| 142 | 142 |
| 143 CHECK_EQ(2U, args->GetSize()); | 143 CHECK_EQ(2U, args->GetSize()); |
| 144 std::string callback_id; | 144 std::string callback_id; |
| 145 int index; | 145 int index; |
| 146 CHECK(args->GetString(0, &callback_id)); | 146 CHECK(args->GetString(0, &callback_id)); |
| 147 CHECK(args->GetInteger(1, &index)); | 147 CHECK(args->GetInteger(1, &index)); |
| 148 | 148 |
| 149 DCHECK(index < int{fingerprints_list_.size()}); | 149 DCHECK(index < int{fingerprints_list_.size()}); |
| 150 bool deleteSucessful = true; | 150 bool deleteSucessful = true; |
| 151 fingerprints_list_.erase(fingerprints_list_.begin() + index); | 151 fingerprints_list_.erase(fingerprints_list_.begin() + index); |
| 152 ResolveJavascriptCallback(base::StringValue(callback_id), | 152 ResolveJavascriptCallback(base::Value(callback_id), |
| 153 base::Value(deleteSucessful)); | 153 base::Value(deleteSucessful)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void FingerprintHandler::HandleChangeEnrollmentLabel( | 156 void FingerprintHandler::HandleChangeEnrollmentLabel( |
| 157 const base::ListValue* args) { | 157 const base::ListValue* args) { |
| 158 CHECK_EQ(2U, args->GetSize()); | 158 CHECK_EQ(2U, args->GetSize()); |
| 159 int index; | 159 int index; |
| 160 std::string new_label; | 160 std::string new_label; |
| 161 CHECK(args->GetInteger(0, &index)); | 161 CHECK(args->GetInteger(0, &index)); |
| 162 CHECK(args->GetString(1, &new_label)); | 162 CHECK(args->GetString(1, &new_label)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 184 if (std::find(fingerprints_list_.begin(), fingerprints_list_.end(), | 184 if (std::find(fingerprints_list_.begin(), fingerprints_list_.end(), |
| 185 fingerprint_name) == fingerprints_list_.end()) { | 185 fingerprint_name) == fingerprints_list_.end()) { |
| 186 fingerprints_list_.push_back(fingerprint_name); | 186 fingerprints_list_.push_back(fingerprint_name); |
| 187 break; | 187 break; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace settings | 192 } // namespace settings |
| 193 } // namespace chromeos | 193 } // namespace chromeos |
| OLD | NEW |