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

Unified Diff: chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc

Issue 1968083004: Implement the private API for quick unlock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..3a84c1ac1571613ad92e8632934c30baddfc8c79
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc
@@ -0,0 +1,180 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.h"
+
+#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/extensions/api/quick_unlock_private.h"
+#include "chromeos/login/auth/extended_authenticator.h"
+#include "chromeos/login/auth/user_context.h"
+
+namespace CheckPassword = extensions::api::quick_unlock_private::CheckPassword;
+namespace SetModes = extensions::api::quick_unlock_private::SetModes;
+namespace GetActiveModes =
+ extensions::api::quick_unlock_private::GetActiveModes;
+namespace GetAvailableModes =
+ extensions::api::quick_unlock_private::GetAvailableModes;
+namespace quick_unlock_private = extensions::api::quick_unlock_private;
+
+namespace extensions {
+
+namespace {
+QuickUnlockPrivateCheckPasswordFunction::CreateAuthenticator
+ create_authenticator_ = nullptr;
+} // namespace
achuithb 2016/05/20 23:50:21 drop comment
jdufault 2016/05/23 18:06:09 Done.
+
+//////////// quickUnlockPrivate.checkPassword
+
+/* static */
+void QuickUnlockPrivateCheckPasswordFunction::SetCreateAuthenticatorForTesting(
+ QuickUnlockPrivateCheckPasswordFunction::CreateAuthenticator allocator) {
+ create_authenticator_ = allocator;
+}
+
+QuickUnlockPrivateCheckPasswordFunction::
+ QuickUnlockPrivateCheckPasswordFunction()
+ : chrome_details_(this) {
+ // Setup a fake authenticator if we are testing.
+ if (create_authenticator_)
+ extended_authenticator_ = create_authenticator_(this);
+ else
+ extended_authenticator_ = chromeos::ExtendedAuthenticator::Create(this);
+}
+
+QuickUnlockPrivateCheckPasswordFunction::
+ ~QuickUnlockPrivateCheckPasswordFunction() {}
+
+ExtensionFunction::ResponseAction
+QuickUnlockPrivateCheckPasswordFunction::Run() {
+ std::unique_ptr<CheckPassword::Params> params(
+ CheckPassword::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(
+ chrome_details_.GetProfile());
+ chromeos::UserContext user_context(user->GetAccountId());
+ user_context.SetKey(chromeos::Key(params->password));
+
+ // The extension function needs to stay alive while the authenticator is
+ // running the password check. Add a ref before the authenticator starts, and
+ // remove the ref after it invokes one of the OnAuth* callbacks.
+ AddRef();
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&chromeos::ExtendedAuthenticator::AuthenticateToCheck,
+ extended_authenticator_.get(), user_context, base::Closure()));
+
+ return RespondLater();
+}
+
+void QuickUnlockPrivateCheckPasswordFunction::OnAuthFailure(
+ const chromeos::AuthFailure& error) {
+ results_ = CheckPassword::Results::Create(false);
+ SendResponse(true);
+ Release();
+}
+
+void QuickUnlockPrivateCheckPasswordFunction::OnAuthSuccess(
+ const chromeos::UserContext& user_context) {
+ results_ = CheckPassword::Results::Create(true);
+ SendResponse(true);
+ Release();
+}
+
+//////////// quickUnlockPrivate.setModes
+
+QuickUnlockPrivateSetModesFunction::QuickUnlockPrivateSetModesFunction()
+ : chrome_details_(this) {}
+
+QuickUnlockPrivateSetModesFunction::~QuickUnlockPrivateSetModesFunction() {}
+
+ExtensionFunction::ResponseAction QuickUnlockPrivateSetModesFunction::Run() {
+ std::unique_ptr<SetModes::Params> params(SetModes::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ if (params->modes.size() != params->passwords.size()) {
+ return RespondNow(
+ Error("|modes| and |passwords| must have the same number of elements"));
achuithb 2016/05/20 23:50:21 Does this need to be translated?
jdufault 2016/05/23 18:06:09 It seems most/all of the existing invocations are
+ }
+
+ // This function is setup so it is easy to add another quick unlock mode while
+ // following all of the invariants, which are:
+ //
+ // 1: If an unlock type is not specified, it should be deactivated.
+ // 2: If a password for an unlock type is empty, it should not be touched.
+ // 3: Otherwise, the password should be set to the new value.
+
+ bool update_pin = true;
+ std::string pin_password;
+
+ // Compute values for update_pin, pin_password, etc.
+ for (size_t i = 0; i < params->modes.size(); ++i) {
+ quick_unlock_private::QuickUnlockMode mode = params->modes[i];
achuithb 2016/05/20 23:50:21 const
jdufault 2016/05/23 18:06:09 Done.
+ std::string password = params->passwords[i];
achuithb 2016/05/20 23:50:21 you don't need this local?
jdufault 2016/05/23 18:06:09 Used twice below, and in any future quick unlock m
achuithb 2016/05/23 19:09:14 I wouldn't worry about future proofing this. Belo
+
+ if (mode == quick_unlock_private::QUICK_UNLOCK_MODE_PIN) {
+ update_pin = !password.empty();
+ pin_password = password;
+ }
+ }
+
+ // Use the computed update_pin, pin_password, etc, values.
+ if (update_pin) {
+ chromeos::PinStorage* pin_storage =
+ chromeos::PinStorageFactory::GetForProfile(
+ chrome_details_.GetProfile());
+ if (pin_password.empty())
+ pin_storage->RemovePin();
+ else
+ pin_storage->SetPin(pin_password);
+ }
+
+ return RespondNow(ArgumentList(SetModes::Results::Create(true)));
+}
+
+//////////// quickUnlockPrivate.getActiveModes
+
+QuickUnlockPrivateGetActiveModesFunction::
+ QuickUnlockPrivateGetActiveModesFunction()
+ : chrome_details_(this) {}
+
+QuickUnlockPrivateGetActiveModesFunction::
+ ~QuickUnlockPrivateGetActiveModesFunction() {}
+
+ExtensionFunction::ResponseAction
+QuickUnlockPrivateGetActiveModesFunction::Run() {
+ std::vector<quick_unlock_private::QuickUnlockMode> modes;
+
+ chromeos::PinStorage* pin_storage =
+ chromeos::PinStorageFactory::GetForProfile(chrome_details_.GetProfile());
+ if (pin_storage->IsPinSet())
+ modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
+
+ return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes)));
+}
+
+//////////// quickUnlockPrivate.getAvailableModes
+
+QuickUnlockPrivateGetAvailableModesFunction::
+ QuickUnlockPrivateGetAvailableModesFunction()
+ : chrome_details_(this) {}
+
+QuickUnlockPrivateGetAvailableModesFunction::
+ ~QuickUnlockPrivateGetAvailableModesFunction() {}
+
+ExtensionFunction::ResponseAction
+QuickUnlockPrivateGetAvailableModesFunction::Run() {
+ std::vector<quick_unlock_private::QuickUnlockMode> modes;
achuithb 2016/05/20 23:50:21 https://www.chromium.org/developers/coding-style/c
jdufault 2016/05/23 18:06:09 Moved to initializer syntax for now, but when poli
+
+ // TODO(jdufault): Check for policy and do not return PIN if policy makes it
+ // unavailable. See crbug.com/612271.
+ modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
+
+ return RespondNow(ArgumentList(GetAvailableModes::Results::Create(modes)));
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698