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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_p rivate_api.h"
6
7 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h"
8 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/common/extensions/api/quick_unlock_private.h"
11 #include "chromeos/login/auth/extended_authenticator.h"
12 #include "chromeos/login/auth/user_context.h"
13
14 namespace CheckPassword = extensions::api::quick_unlock_private::CheckPassword;
15 namespace SetModes = extensions::api::quick_unlock_private::SetModes;
16 namespace GetActiveModes =
17 extensions::api::quick_unlock_private::GetActiveModes;
18 namespace GetAvailableModes =
19 extensions::api::quick_unlock_private::GetAvailableModes;
20 namespace quick_unlock_private = extensions::api::quick_unlock_private;
21
22 namespace extensions {
23
24 namespace {
25 QuickUnlockPrivateCheckPasswordFunction::CreateAuthenticator
26 create_authenticator_ = nullptr;
27 } // namespace
achuithb 2016/05/20 23:50:21 drop comment
jdufault 2016/05/23 18:06:09 Done.
28
29 //////////// quickUnlockPrivate.checkPassword
30
31 /* static */
32 void QuickUnlockPrivateCheckPasswordFunction::SetCreateAuthenticatorForTesting(
33 QuickUnlockPrivateCheckPasswordFunction::CreateAuthenticator allocator) {
34 create_authenticator_ = allocator;
35 }
36
37 QuickUnlockPrivateCheckPasswordFunction::
38 QuickUnlockPrivateCheckPasswordFunction()
39 : chrome_details_(this) {
40 // Setup a fake authenticator if we are testing.
41 if (create_authenticator_)
42 extended_authenticator_ = create_authenticator_(this);
43 else
44 extended_authenticator_ = chromeos::ExtendedAuthenticator::Create(this);
45 }
46
47 QuickUnlockPrivateCheckPasswordFunction::
48 ~QuickUnlockPrivateCheckPasswordFunction() {}
49
50 ExtensionFunction::ResponseAction
51 QuickUnlockPrivateCheckPasswordFunction::Run() {
52 std::unique_ptr<CheckPassword::Params> params(
53 CheckPassword::Params::Create(*args_));
54 EXTENSION_FUNCTION_VALIDATE(params.get());
55
56 user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(
57 chrome_details_.GetProfile());
58 chromeos::UserContext user_context(user->GetAccountId());
59 user_context.SetKey(chromeos::Key(params->password));
60
61 // The extension function needs to stay alive while the authenticator is
62 // running the password check. Add a ref before the authenticator starts, and
63 // remove the ref after it invokes one of the OnAuth* callbacks.
64 AddRef();
65
66 content::BrowserThread::PostTask(
67 content::BrowserThread::UI, FROM_HERE,
68 base::Bind(&chromeos::ExtendedAuthenticator::AuthenticateToCheck,
69 extended_authenticator_.get(), user_context, base::Closure()));
70
71 return RespondLater();
72 }
73
74 void QuickUnlockPrivateCheckPasswordFunction::OnAuthFailure(
75 const chromeos::AuthFailure& error) {
76 results_ = CheckPassword::Results::Create(false);
77 SendResponse(true);
78 Release();
79 }
80
81 void QuickUnlockPrivateCheckPasswordFunction::OnAuthSuccess(
82 const chromeos::UserContext& user_context) {
83 results_ = CheckPassword::Results::Create(true);
84 SendResponse(true);
85 Release();
86 }
87
88 //////////// quickUnlockPrivate.setModes
89
90 QuickUnlockPrivateSetModesFunction::QuickUnlockPrivateSetModesFunction()
91 : chrome_details_(this) {}
92
93 QuickUnlockPrivateSetModesFunction::~QuickUnlockPrivateSetModesFunction() {}
94
95 ExtensionFunction::ResponseAction QuickUnlockPrivateSetModesFunction::Run() {
96 std::unique_ptr<SetModes::Params> params(SetModes::Params::Create(*args_));
97 EXTENSION_FUNCTION_VALIDATE(params.get());
98
99 if (params->modes.size() != params->passwords.size()) {
100 return RespondNow(
101 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
102 }
103
104 // This function is setup so it is easy to add another quick unlock mode while
105 // following all of the invariants, which are:
106 //
107 // 1: If an unlock type is not specified, it should be deactivated.
108 // 2: If a password for an unlock type is empty, it should not be touched.
109 // 3: Otherwise, the password should be set to the new value.
110
111 bool update_pin = true;
112 std::string pin_password;
113
114 // Compute values for update_pin, pin_password, etc.
115 for (size_t i = 0; i < params->modes.size(); ++i) {
116 quick_unlock_private::QuickUnlockMode mode = params->modes[i];
achuithb 2016/05/20 23:50:21 const
jdufault 2016/05/23 18:06:09 Done.
117 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
118
119 if (mode == quick_unlock_private::QUICK_UNLOCK_MODE_PIN) {
120 update_pin = !password.empty();
121 pin_password = password;
122 }
123 }
124
125 // Use the computed update_pin, pin_password, etc, values.
126 if (update_pin) {
127 chromeos::PinStorage* pin_storage =
128 chromeos::PinStorageFactory::GetForProfile(
129 chrome_details_.GetProfile());
130 if (pin_password.empty())
131 pin_storage->RemovePin();
132 else
133 pin_storage->SetPin(pin_password);
134 }
135
136 return RespondNow(ArgumentList(SetModes::Results::Create(true)));
137 }
138
139 //////////// quickUnlockPrivate.getActiveModes
140
141 QuickUnlockPrivateGetActiveModesFunction::
142 QuickUnlockPrivateGetActiveModesFunction()
143 : chrome_details_(this) {}
144
145 QuickUnlockPrivateGetActiveModesFunction::
146 ~QuickUnlockPrivateGetActiveModesFunction() {}
147
148 ExtensionFunction::ResponseAction
149 QuickUnlockPrivateGetActiveModesFunction::Run() {
150 std::vector<quick_unlock_private::QuickUnlockMode> modes;
151
152 chromeos::PinStorage* pin_storage =
153 chromeos::PinStorageFactory::GetForProfile(chrome_details_.GetProfile());
154 if (pin_storage->IsPinSet())
155 modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
156
157 return RespondNow(ArgumentList(GetActiveModes::Results::Create(modes)));
158 }
159
160 //////////// quickUnlockPrivate.getAvailableModes
161
162 QuickUnlockPrivateGetAvailableModesFunction::
163 QuickUnlockPrivateGetAvailableModesFunction()
164 : chrome_details_(this) {}
165
166 QuickUnlockPrivateGetAvailableModesFunction::
167 ~QuickUnlockPrivateGetAvailableModesFunction() {}
168
169 ExtensionFunction::ResponseAction
170 QuickUnlockPrivateGetAvailableModesFunction::Run() {
171 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
172
173 // TODO(jdufault): Check for policy and do not return PIN if policy makes it
174 // unavailable. See crbug.com/612271.
175 modes.push_back(quick_unlock_private::QUICK_UNLOCK_MODE_PIN);
176
177 return RespondNow(ArgumentList(GetAvailableModes::Results::Create(modes)));
178 }
179
180 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698