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

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

Issue 2809993004: cros: Implement cryptohome backend for pin.
Patch Set: Rebase, remove some extraneous LOG statements Created 3 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
index d38cf288a3f6112aed53a9c59d2bf552573c830c..d443c5bc185399165667496fef5e941cdee68b57 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
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.h"
#include "base/memory/ptr_util.h"
+#include "chrome/browser/chromeos/login/quick_unlock/pin_backend.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
@@ -45,16 +46,22 @@ const int kMinLengthForNonWeakPin = 2;
const char* kMostCommonPins[] = {"1212", "1004", "2000", "6969",
"1122", "1313", "2001", "1010"};
-// Returns the active set of quick unlock modes.
-QuickUnlockModeList ComputeActiveModes(Profile* profile) {
- QuickUnlockModeList modes;
-
- chromeos::quick_unlock::QuickUnlockStorage* quick_unlock_storage =
- chromeos::quick_unlock::QuickUnlockFactory::GetForProfile(profile);
- if (quick_unlock_storage && quick_unlock_storage->pin_storage()->IsPinSet())
- modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
+using ActiveModeCallback = base::Callback<void(const QuickUnlockModeList&)>;
- return modes;
+// Returns the active set of quick unlock modes.
+void ComputeActiveModes(Profile* profile, const ActiveModeCallback& result) {
+ user_manager::User* user =
+ chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
+ chromeos::quick_unlock::PinBackend::IsSet(
+ user->GetAccountId(),
+ base::Bind(
+ [](const ActiveModeCallback& result, bool is_set) {
+ QuickUnlockModeList modes;
+ if (is_set)
+ modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
+ result.Run(modes);
+ },
+ result));
}
// Returns true if |a| and |b| contain the same elements. The elements do not
@@ -197,9 +204,17 @@ QuickUnlockPrivateGetActiveModesFunction::
ExtensionFunction::ResponseAction
QuickUnlockPrivateGetActiveModesFunction::Run() {
- const QuickUnlockModeList modes =
- ComputeActiveModes(chrome_details_.GetProfile());
- return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes)));
+ ComputeActiveModes(
+ chrome_details_.GetProfile(),
+ base::Bind(&QuickUnlockPrivateGetActiveModesFunction::OnGetActiveModes,
+ this));
+
+ return RespondLater();
+}
+
+void QuickUnlockPrivateGetActiveModesFunction::OnGetActiveModes(
+ const std::vector<api::quick_unlock_private::QuickUnlockMode>& modes) {
+ Respond(ArgumentList(GetActiveModes::Results::Create(modes)));
}
// quickUnlockPrivate.checkCredential
@@ -362,12 +377,18 @@ void QuickUnlockPrivateSetModesFunction::OnAuthFailure(
void QuickUnlockPrivateSetModesFunction::OnAuthSuccess(
const chromeos::UserContext& user_context) {
- const QuickUnlockModeList initial_modes =
- ComputeActiveModes(chrome_details_.GetProfile());
- ApplyModeChange();
- const QuickUnlockModeList updated_modes =
- ComputeActiveModes(chrome_details_.GetProfile());
+ ComputeActiveModes(
+ chrome_details_.GetProfile(),
+ base::Bind(
+ &QuickUnlockPrivateSetModesFunction::OnGetActiveModesAfterAuthSuccess,
+ base::Unretained(this), user_context));
+}
+void QuickUnlockPrivateSetModesFunction::OnGetActiveModesAfterAuthSuccess(
+ const chromeos::UserContext& user_context,
+ const std::vector<api::quick_unlock_private::QuickUnlockMode>&
+ initial_modes) {
+ std::vector<QuickUnlockMode> updated_modes = ApplyModeChange(user_context);
if (!AreModesEqual(initial_modes, updated_modes))
FireEvent(updated_modes);
@@ -375,7 +396,9 @@ void QuickUnlockPrivateSetModesFunction::OnAuthSuccess(
Release(); // Balanced in Run().
}
-void QuickUnlockPrivateSetModesFunction::ApplyModeChange() {
+std::vector<QuickUnlockMode>
+QuickUnlockPrivateSetModesFunction::ApplyModeChange(
+ const chromeos::UserContext& user_context) {
// This function is setup so it is easy to add another quick unlock mode while
// following all of the invariants, which are:
//
@@ -383,6 +406,8 @@ void QuickUnlockPrivateSetModesFunction::ApplyModeChange() {
// 2: If a credential for an unlock type is empty, it should not be touched.
// 3: Otherwise, the credential should be set to the new value.
+ std::vector<QuickUnlockMode> newly_active_modes;
+
bool update_pin = true;
std::string pin_credential;
@@ -394,22 +419,25 @@ void QuickUnlockPrivateSetModesFunction::ApplyModeChange() {
if (mode == quick_unlock_private::QUICK_UNLOCK_MODE_PIN) {
update_pin = !credential.empty();
pin_credential = credential;
+ newly_active_modes.push_back(QuickUnlockMode::QUICK_UNLOCK_MODE_PIN);
}
}
// Apply changes.
if (update_pin) {
- Profile* profile = chrome_details_.GetProfile();
- chromeos::quick_unlock::QuickUnlockStorage* quick_unlock_storage =
- chromeos::quick_unlock::QuickUnlockFactory::GetForProfile(profile);
-
if (pin_credential.empty()) {
- quick_unlock_storage->pin_storage()->RemovePin();
+ chromeos::quick_unlock::PinBackend::Remove(user_context);
} else {
- quick_unlock_storage->pin_storage()->SetPin(pin_credential);
+ chromeos::quick_unlock::PinBackend::Set(user_context, pin_credential);
+
+ Profile* profile = chrome_details_.GetProfile();
+ chromeos::quick_unlock::QuickUnlockStorage* quick_unlock_storage =
+ chromeos::quick_unlock::QuickUnlockFactory::GetForProfile(profile);
quick_unlock_storage->MarkStrongAuth();
}
}
+
+ return newly_active_modes;
achuithb 2017/05/13 01:01:57 So that can only be empty or have the QUICK_UNLOCK
jdufault 2017/06/06 18:17:05 Yep.
}
// Triggers a quickUnlockPrivate.onActiveModesChanged change event.

Powered by Google App Engine
This is Rietveld 408576698