Index: chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc |
diff --git a/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc b/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc |
index 50bdfb92b393bb1028d07ee2ed4c58c2058f0e0c..2ef337f539d26eca06e9a31fe0c8252959ff1e56 100644 |
--- a/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc |
+++ b/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc |
@@ -7,8 +7,10 @@ |
#include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h" |
#include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h" |
#include "chrome/browser/chromeos/profiles/profile_helper.h" |
+#include "chrome/common/pref_names.h" |
#include "chromeos/login/auth/extended_authenticator.h" |
#include "chromeos/login/auth/user_context.h" |
+#include "components/prefs/pref_service.h" |
#include "extensions/browser/event_router.h" |
namespace extensions { |
@@ -16,8 +18,10 @@ namespace extensions { |
namespace quick_unlock_private = api::quick_unlock_private; |
namespace SetModes = quick_unlock_private::SetModes; |
namespace GetActiveModes = quick_unlock_private::GetActiveModes; |
+namespace GetUsablePin = quick_unlock_private::GetUsablePin; |
namespace GetAvailableModes = quick_unlock_private::GetAvailableModes; |
namespace OnActiveModesChanged = quick_unlock_private::OnActiveModesChanged; |
+using PinState = quick_unlock_private::PinState; |
using QuickUnlockMode = quick_unlock_private::QuickUnlockMode; |
using QuickUnlockModeList = std::vector<QuickUnlockMode>; |
@@ -93,6 +97,78 @@ QuickUnlockPrivateGetActiveModesFunction::Run() { |
return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes))); |
} |
+// quickUnlockPrivate.getUsablePin |
+ |
+QuickUnlockPrivateGetUsablePinFunction::QuickUnlockPrivateGetUsablePinFunction() |
+ : chrome_details_(this) {} |
+ |
+QuickUnlockPrivateGetUsablePinFunction:: |
+ ~QuickUnlockPrivateGetUsablePinFunction() {} |
+ |
+ExtensionFunction::ResponseAction |
+QuickUnlockPrivateGetUsablePinFunction::Run() { |
+ params_ = GetUsablePin::Params::Create(*args_); |
jdufault
2016/09/29 19:36:52
setModes needs to validate these checks as well.
sammiequon
2016/09/30 00:35:08
Done.
|
+ EXTENSION_FUNCTION_VALIDATE(params_.get()); |
+ |
+ Profile* profile = chrome_details_.GetProfile(); |
+ PrefService* prefservice = profile->GetPrefs(); |
+ |
+ std::string tried_password = params_->attempted_password; |
+ int minimum_length = prefservice->GetInteger(prefs::kPinUnlockMinimumLength); |
+ int maximum_length = prefservice->GetInteger(prefs::kPinUnlockMaximumLength); |
+ |
+ // Check if the pin is shorter than the minimum specified length. |
+ if (int{tried_password.size()} < minimum_length) { |
+ return RespondNow(ArgumentList( |
+ GetUsablePin::Results::Create(PinState::PIN_STATE_SHORTER_THAN_MIN))); |
+ } |
+ |
+ // If the maximum specified length is shorter or equal to the minimum |
+ // specified length, there is no maximum length. Otherwise check if the pin is |
+ // longer than the maximum specified length. |
+ if (maximum_length > minimum_length && |
+ int{tried_password.size()} > maximum_length) { |
+ return RespondNow(ArgumentList( |
+ GetUsablePin::Results::Create(PinState::PIN_STATE_LONGER_THAN_MAX))); |
+ } |
+ |
+ // If the pin length is two or less, there is no need to check for same |
+ // character and increasing pin. |
+ const int pin_check_easy_threshold = 2; |
+ if (int{tried_password.size()} < pin_check_easy_threshold) { |
+ return RespondNow( |
+ ArgumentList(GetUsablePin::Results::Create(PinState::PIN_STATE_GOOD))); |
+ } |
+ |
+ // Check for same digits, increasing pin simutaneously. |
+ bool is_same = true, is_increasing = true; |
+ char last_char; |
+ for (int j = 0; j < int{tried_password.size()}; j++) { |
+ if (j == 0) { |
+ last_char = tried_password[j]; |
+ continue; |
+ } |
+ is_same = is_same && (tried_password[j] == last_char); |
+ is_increasing = is_increasing && (tried_password[j] == last_char + 1); |
+ last_char = tried_password[j]; |
+ } |
+ |
+ // Each digit of the pin is the same. |
+ if (is_same) { |
+ return RespondNow(ArgumentList( |
+ GetUsablePin::Results::Create(PinState::PIN_STATE_ALL_SAME_NUM))); |
+ } |
+ |
+ // Each digit of the pin increases by 1. |
+ if (is_increasing) { |
+ return RespondNow(ArgumentList( |
+ GetUsablePin::Results::Create(PinState::PIN_STATE_INCREASING))); |
+ } |
+ |
+ return RespondNow( |
+ ArgumentList(GetUsablePin::Results::Create(PinState::PIN_STATE_GOOD))); |
+} |
+ |
// quickUnlockPrivate.setModes |
QuickUnlockPrivateSetModesFunction::QuickUnlockPrivateSetModesFunction() |