OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/extensions/users_private/users_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/users_private/users_private_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 121 } |
122 | 122 |
123 ExtensionFunction::ResponseAction | 123 ExtensionFunction::ResponseAction |
124 UsersPrivateAddWhitelistedUserFunction::Run() { | 124 UsersPrivateAddWhitelistedUserFunction::Run() { |
125 std::unique_ptr<api::users_private::AddWhitelistedUser::Params> parameters = | 125 std::unique_ptr<api::users_private::AddWhitelistedUser::Params> parameters = |
126 api::users_private::AddWhitelistedUser::Params::Create(*args_); | 126 api::users_private::AddWhitelistedUser::Params::Create(*args_); |
127 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 127 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
128 | 128 |
129 // Non-owners should not be able to add users. | 129 // Non-owners should not be able to add users. |
130 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { | 130 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { |
131 return RespondNow( | 131 return RespondNow(OneArgument(base::MakeUnique<base::Value>(false))); |
132 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
133 } | 132 } |
134 | 133 |
135 std::string username = gaia::CanonicalizeEmail(parameters->email); | 134 std::string username = gaia::CanonicalizeEmail(parameters->email); |
136 if (chromeos::CrosSettings::Get()->FindEmailInList( | 135 if (chromeos::CrosSettings::Get()->FindEmailInList( |
137 chromeos::kAccountsPrefUsers, username, NULL)) { | 136 chromeos::kAccountsPrefUsers, username, NULL)) { |
138 return RespondNow( | 137 return RespondNow(OneArgument(base::MakeUnique<base::Value>(false))); |
139 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
140 } | 138 } |
141 | 139 |
142 base::StringValue username_value(username); | 140 base::StringValue username_value(username); |
143 | 141 |
144 UsersPrivateDelegate* delegate = | 142 UsersPrivateDelegate* delegate = |
145 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); | 143 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
146 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); | 144 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); |
147 bool added = prefs_util->AppendToListCrosSetting(chromeos::kAccountsPrefUsers, | 145 bool added = prefs_util->AppendToListCrosSetting(chromeos::kAccountsPrefUsers, |
148 username_value); | 146 username_value); |
149 return RespondNow( | 147 return RespondNow(OneArgument(base::MakeUnique<base::Value>(added))); |
150 OneArgument(base::MakeUnique<base::FundamentalValue>(added))); | |
151 } | 148 } |
152 | 149 |
153 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
154 // UsersPrivateRemoveWhitelistedUserFunction | 151 // UsersPrivateRemoveWhitelistedUserFunction |
155 | 152 |
156 UsersPrivateRemoveWhitelistedUserFunction:: | 153 UsersPrivateRemoveWhitelistedUserFunction:: |
157 UsersPrivateRemoveWhitelistedUserFunction() | 154 UsersPrivateRemoveWhitelistedUserFunction() |
158 : chrome_details_(this) { | 155 : chrome_details_(this) { |
159 } | 156 } |
160 | 157 |
161 UsersPrivateRemoveWhitelistedUserFunction:: | 158 UsersPrivateRemoveWhitelistedUserFunction:: |
162 ~UsersPrivateRemoveWhitelistedUserFunction() { | 159 ~UsersPrivateRemoveWhitelistedUserFunction() { |
163 } | 160 } |
164 | 161 |
165 ExtensionFunction::ResponseAction | 162 ExtensionFunction::ResponseAction |
166 UsersPrivateRemoveWhitelistedUserFunction::Run() { | 163 UsersPrivateRemoveWhitelistedUserFunction::Run() { |
167 std::unique_ptr<api::users_private::RemoveWhitelistedUser::Params> | 164 std::unique_ptr<api::users_private::RemoveWhitelistedUser::Params> |
168 parameters = | 165 parameters = |
169 api::users_private::RemoveWhitelistedUser::Params::Create(*args_); | 166 api::users_private::RemoveWhitelistedUser::Params::Create(*args_); |
170 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 167 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
171 | 168 |
172 // Non-owners should not be able to remove users. | 169 // Non-owners should not be able to remove users. |
173 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { | 170 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { |
174 return RespondNow( | 171 return RespondNow(OneArgument(base::MakeUnique<base::Value>(false))); |
175 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
176 } | 172 } |
177 | 173 |
178 base::StringValue canonical_email(gaia::CanonicalizeEmail(parameters->email)); | 174 base::StringValue canonical_email(gaia::CanonicalizeEmail(parameters->email)); |
179 | 175 |
180 UsersPrivateDelegate* delegate = | 176 UsersPrivateDelegate* delegate = |
181 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); | 177 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
182 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); | 178 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); |
183 bool removed = prefs_util->RemoveFromListCrosSetting( | 179 bool removed = prefs_util->RemoveFromListCrosSetting( |
184 chromeos::kAccountsPrefUsers, canonical_email); | 180 chromeos::kAccountsPrefUsers, canonical_email); |
185 user_manager::UserManager::Get()->RemoveUser( | 181 user_manager::UserManager::Get()->RemoveUser( |
186 AccountId::FromUserEmail(parameters->email), NULL); | 182 AccountId::FromUserEmail(parameters->email), NULL); |
187 return RespondNow( | 183 return RespondNow(OneArgument(base::MakeUnique<base::Value>(removed))); |
188 OneArgument(base::MakeUnique<base::FundamentalValue>(removed))); | |
189 } | 184 } |
190 | 185 |
191 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
192 // UsersPrivateIsCurrentUserOwnerFunction | 187 // UsersPrivateIsCurrentUserOwnerFunction |
193 | 188 |
194 UsersPrivateIsCurrentUserOwnerFunction::UsersPrivateIsCurrentUserOwnerFunction() | 189 UsersPrivateIsCurrentUserOwnerFunction::UsersPrivateIsCurrentUserOwnerFunction() |
195 : chrome_details_(this) { | 190 : chrome_details_(this) { |
196 } | 191 } |
197 | 192 |
198 UsersPrivateIsCurrentUserOwnerFunction:: | 193 UsersPrivateIsCurrentUserOwnerFunction:: |
199 ~UsersPrivateIsCurrentUserOwnerFunction() { | 194 ~UsersPrivateIsCurrentUserOwnerFunction() { |
200 } | 195 } |
201 | 196 |
202 ExtensionFunction::ResponseAction | 197 ExtensionFunction::ResponseAction |
203 UsersPrivateIsCurrentUserOwnerFunction::Run() { | 198 UsersPrivateIsCurrentUserOwnerFunction::Run() { |
204 bool is_owner = | 199 bool is_owner = |
205 chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile()); | 200 chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile()); |
206 return RespondNow( | 201 return RespondNow(OneArgument(base::MakeUnique<base::Value>(is_owner))); |
207 OneArgument(base::MakeUnique<base::FundamentalValue>(is_owner))); | |
208 } | 202 } |
209 | 203 |
210 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// |
211 // UsersPrivateIsWhitelistManagedFunction | 205 // UsersPrivateIsWhitelistManagedFunction |
212 | 206 |
213 UsersPrivateIsWhitelistManagedFunction:: | 207 UsersPrivateIsWhitelistManagedFunction:: |
214 UsersPrivateIsWhitelistManagedFunction() { | 208 UsersPrivateIsWhitelistManagedFunction() { |
215 } | 209 } |
216 | 210 |
217 UsersPrivateIsWhitelistManagedFunction:: | 211 UsersPrivateIsWhitelistManagedFunction:: |
218 ~UsersPrivateIsWhitelistManagedFunction() { | 212 ~UsersPrivateIsWhitelistManagedFunction() { |
219 } | 213 } |
220 | 214 |
221 ExtensionFunction::ResponseAction | 215 ExtensionFunction::ResponseAction |
222 UsersPrivateIsWhitelistManagedFunction::Run() { | 216 UsersPrivateIsWhitelistManagedFunction::Run() { |
223 bool is_managed = g_browser_process->platform_part() | 217 bool is_managed = g_browser_process->platform_part() |
224 ->browser_policy_connector_chromeos() | 218 ->browser_policy_connector_chromeos() |
225 ->IsEnterpriseManaged(); | 219 ->IsEnterpriseManaged(); |
226 return RespondNow( | 220 return RespondNow(OneArgument(base::MakeUnique<base::Value>(is_managed))); |
227 OneArgument(base::MakeUnique<base::FundamentalValue>(is_managed))); | |
228 } | 221 } |
229 | 222 |
230 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |