| 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> | |
| 10 | |
| 11 #include "base/memory/ptr_util.h" | |
| 12 #include "base/values.h" | 9 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/extensions/users_private/users_private_delegat
e.h" | 11 #include "chrome/browser/chromeos/extensions/users_private/users_private_delegat
e.h" |
| 15 #include "chrome/browser/chromeos/extensions/users_private/users_private_delegat
e_factory.h" | 12 #include "chrome/browser/chromeos/extensions/users_private/users_private_delegat
e_factory.h" |
| 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 13 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 21 #include "chrome/browser/extensions/chrome_extension_function.h" | 18 #include "chrome/browser/extensions/chrome_extension_function.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 ~UsersPrivateGetWhitelistedUsersFunction() { | 38 ~UsersPrivateGetWhitelistedUsersFunction() { |
| 42 } | 39 } |
| 43 | 40 |
| 44 ExtensionFunction::ResponseAction | 41 ExtensionFunction::ResponseAction |
| 45 UsersPrivateGetWhitelistedUsersFunction::Run() { | 42 UsersPrivateGetWhitelistedUsersFunction::Run() { |
| 46 Profile* profile = chrome_details_.GetProfile(); | 43 Profile* profile = chrome_details_.GetProfile(); |
| 47 std::unique_ptr<base::ListValue> user_list(new base::ListValue); | 44 std::unique_ptr<base::ListValue> user_list(new base::ListValue); |
| 48 | 45 |
| 49 // Non-owners should not be able to see the list of users. | 46 // Non-owners should not be able to see the list of users. |
| 50 if (!chromeos::ProfileHelper::IsOwnerProfile(profile)) | 47 if (!chromeos::ProfileHelper::IsOwnerProfile(profile)) |
| 51 return RespondNow(OneArgument(std::move(user_list))); | 48 return RespondNow(OneArgument(user_list.release())); |
| 52 | 49 |
| 53 // Create one list to set. This is needed because user white list update is | 50 // Create one list to set. This is needed because user white list update is |
| 54 // asynchronous and sequential. Before previous write comes back, cached list | 51 // asynchronous and sequential. Before previous write comes back, cached list |
| 55 // is stale and should not be used for appending. See http://crbug.com/127215 | 52 // is stale and should not be used for appending. See http://crbug.com/127215 |
| 56 std::unique_ptr<base::ListValue> email_list; | 53 std::unique_ptr<base::ListValue> email_list; |
| 57 | 54 |
| 58 UsersPrivateDelegate* delegate = | 55 UsersPrivateDelegate* delegate = |
| 59 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); | 56 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| 60 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); | 57 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); |
| 61 | 58 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Now populate the list of User objects for returning to the JS. | 94 // Now populate the list of User objects for returning to the JS. |
| 98 for (size_t i = 0; i < email_list->GetSize(); ++i) { | 95 for (size_t i = 0; i < email_list->GetSize(); ++i) { |
| 99 api::users_private::User user; | 96 api::users_private::User user; |
| 100 email_list->GetString(i, &user.email); | 97 email_list->GetString(i, &user.email); |
| 101 | 98 |
| 102 user.is_owner = chromeos::ProfileHelper::IsOwnerProfile(profile) && | 99 user.is_owner = chromeos::ProfileHelper::IsOwnerProfile(profile) && |
| 103 user.email == profile->GetProfileUserName(); | 100 user.email == profile->GetProfileUserName(); |
| 104 user_list->Append(user.ToValue().release()); | 101 user_list->Append(user.ToValue().release()); |
| 105 } | 102 } |
| 106 | 103 |
| 107 return RespondNow(OneArgument(std::move(user_list))); | 104 return RespondNow(OneArgument(user_list.release())); |
| 108 } | 105 } |
| 109 | 106 |
| 110 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
| 111 // UsersPrivateAddWhitelistedUserFunction | 108 // UsersPrivateAddWhitelistedUserFunction |
| 112 | 109 |
| 113 UsersPrivateAddWhitelistedUserFunction::UsersPrivateAddWhitelistedUserFunction() | 110 UsersPrivateAddWhitelistedUserFunction::UsersPrivateAddWhitelistedUserFunction() |
| 114 : chrome_details_(this) { | 111 : chrome_details_(this) { |
| 115 } | 112 } |
| 116 | 113 |
| 117 UsersPrivateAddWhitelistedUserFunction:: | 114 UsersPrivateAddWhitelistedUserFunction:: |
| 118 ~UsersPrivateAddWhitelistedUserFunction() { | 115 ~UsersPrivateAddWhitelistedUserFunction() { |
| 119 } | 116 } |
| 120 | 117 |
| 121 ExtensionFunction::ResponseAction | 118 ExtensionFunction::ResponseAction |
| 122 UsersPrivateAddWhitelistedUserFunction::Run() { | 119 UsersPrivateAddWhitelistedUserFunction::Run() { |
| 123 std::unique_ptr<api::users_private::AddWhitelistedUser::Params> parameters = | 120 std::unique_ptr<api::users_private::AddWhitelistedUser::Params> parameters = |
| 124 api::users_private::AddWhitelistedUser::Params::Create(*args_); | 121 api::users_private::AddWhitelistedUser::Params::Create(*args_); |
| 125 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 122 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 126 | 123 |
| 127 // Non-owners should not be able to add users. | 124 // Non-owners should not be able to add users. |
| 128 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { | 125 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { |
| 129 return RespondNow( | 126 return RespondNow(OneArgument(new base::FundamentalValue(false))); |
| 130 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
| 131 } | 127 } |
| 132 | 128 |
| 133 std::string username = gaia::CanonicalizeEmail(parameters->email); | 129 std::string username = gaia::CanonicalizeEmail(parameters->email); |
| 134 if (chromeos::CrosSettings::Get()->FindEmailInList( | 130 if (chromeos::CrosSettings::Get()->FindEmailInList( |
| 135 chromeos::kAccountsPrefUsers, username, NULL)) { | 131 chromeos::kAccountsPrefUsers, username, NULL)) { |
| 136 return RespondNow( | 132 return RespondNow(OneArgument(new base::FundamentalValue(false))); |
| 137 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
| 138 } | 133 } |
| 139 | 134 |
| 140 base::StringValue username_value(username); | 135 base::StringValue username_value(username); |
| 141 | 136 |
| 142 UsersPrivateDelegate* delegate = | 137 UsersPrivateDelegate* delegate = |
| 143 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); | 138 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| 144 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); | 139 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); |
| 145 bool added = prefs_util->AppendToListCrosSetting(chromeos::kAccountsPrefUsers, | 140 bool added = prefs_util->AppendToListCrosSetting(chromeos::kAccountsPrefUsers, |
| 146 username_value); | 141 username_value); |
| 147 return RespondNow( | 142 return RespondNow(OneArgument(new base::FundamentalValue(added))); |
| 148 OneArgument(base::MakeUnique<base::FundamentalValue>(added))); | |
| 149 } | 143 } |
| 150 | 144 |
| 151 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 152 // UsersPrivateRemoveWhitelistedUserFunction | 146 // UsersPrivateRemoveWhitelistedUserFunction |
| 153 | 147 |
| 154 UsersPrivateRemoveWhitelistedUserFunction:: | 148 UsersPrivateRemoveWhitelistedUserFunction:: |
| 155 UsersPrivateRemoveWhitelistedUserFunction() | 149 UsersPrivateRemoveWhitelistedUserFunction() |
| 156 : chrome_details_(this) { | 150 : chrome_details_(this) { |
| 157 } | 151 } |
| 158 | 152 |
| 159 UsersPrivateRemoveWhitelistedUserFunction:: | 153 UsersPrivateRemoveWhitelistedUserFunction:: |
| 160 ~UsersPrivateRemoveWhitelistedUserFunction() { | 154 ~UsersPrivateRemoveWhitelistedUserFunction() { |
| 161 } | 155 } |
| 162 | 156 |
| 163 ExtensionFunction::ResponseAction | 157 ExtensionFunction::ResponseAction |
| 164 UsersPrivateRemoveWhitelistedUserFunction::Run() { | 158 UsersPrivateRemoveWhitelistedUserFunction::Run() { |
| 165 std::unique_ptr<api::users_private::RemoveWhitelistedUser::Params> | 159 std::unique_ptr<api::users_private::RemoveWhitelistedUser::Params> |
| 166 parameters = | 160 parameters = |
| 167 api::users_private::RemoveWhitelistedUser::Params::Create(*args_); | 161 api::users_private::RemoveWhitelistedUser::Params::Create(*args_); |
| 168 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 162 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 169 | 163 |
| 170 // Non-owners should not be able to remove users. | 164 // Non-owners should not be able to remove users. |
| 171 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { | 165 if (!chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile())) { |
| 172 return RespondNow( | 166 return RespondNow(OneArgument(new base::FundamentalValue(false))); |
| 173 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
| 174 } | 167 } |
| 175 | 168 |
| 176 base::StringValue canonical_email(gaia::CanonicalizeEmail(parameters->email)); | 169 base::StringValue canonical_email(gaia::CanonicalizeEmail(parameters->email)); |
| 177 | 170 |
| 178 UsersPrivateDelegate* delegate = | 171 UsersPrivateDelegate* delegate = |
| 179 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); | 172 UsersPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| 180 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); | 173 PrefsUtil* prefs_util = delegate->GetPrefsUtil(); |
| 181 bool removed = prefs_util->RemoveFromListCrosSetting( | 174 bool removed = prefs_util->RemoveFromListCrosSetting( |
| 182 chromeos::kAccountsPrefUsers, canonical_email); | 175 chromeos::kAccountsPrefUsers, canonical_email); |
| 183 user_manager::UserManager::Get()->RemoveUser( | 176 user_manager::UserManager::Get()->RemoveUser( |
| 184 AccountId::FromUserEmail(parameters->email), NULL); | 177 AccountId::FromUserEmail(parameters->email), NULL); |
| 185 return RespondNow( | 178 return RespondNow(OneArgument(new base::FundamentalValue(removed))); |
| 186 OneArgument(base::MakeUnique<base::FundamentalValue>(removed))); | |
| 187 } | 179 } |
| 188 | 180 |
| 189 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
| 190 // UsersPrivateIsCurrentUserOwnerFunction | 182 // UsersPrivateIsCurrentUserOwnerFunction |
| 191 | 183 |
| 192 UsersPrivateIsCurrentUserOwnerFunction::UsersPrivateIsCurrentUserOwnerFunction() | 184 UsersPrivateIsCurrentUserOwnerFunction::UsersPrivateIsCurrentUserOwnerFunction() |
| 193 : chrome_details_(this) { | 185 : chrome_details_(this) { |
| 194 } | 186 } |
| 195 | 187 |
| 196 UsersPrivateIsCurrentUserOwnerFunction:: | 188 UsersPrivateIsCurrentUserOwnerFunction:: |
| 197 ~UsersPrivateIsCurrentUserOwnerFunction() { | 189 ~UsersPrivateIsCurrentUserOwnerFunction() { |
| 198 } | 190 } |
| 199 | 191 |
| 200 ExtensionFunction::ResponseAction | 192 ExtensionFunction::ResponseAction |
| 201 UsersPrivateIsCurrentUserOwnerFunction::Run() { | 193 UsersPrivateIsCurrentUserOwnerFunction::Run() { |
| 202 bool is_owner = | 194 bool is_owner = |
| 203 chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile()); | 195 chromeos::ProfileHelper::IsOwnerProfile(chrome_details_.GetProfile()); |
| 204 return RespondNow( | 196 return RespondNow(OneArgument(new base::FundamentalValue(is_owner))); |
| 205 OneArgument(base::MakeUnique<base::FundamentalValue>(is_owner))); | |
| 206 } | 197 } |
| 207 | 198 |
| 208 //////////////////////////////////////////////////////////////////////////////// | 199 //////////////////////////////////////////////////////////////////////////////// |
| 209 // UsersPrivateIsWhitelistManagedFunction | 200 // UsersPrivateIsWhitelistManagedFunction |
| 210 | 201 |
| 211 UsersPrivateIsWhitelistManagedFunction:: | 202 UsersPrivateIsWhitelistManagedFunction:: |
| 212 UsersPrivateIsWhitelistManagedFunction() { | 203 UsersPrivateIsWhitelistManagedFunction() { |
| 213 } | 204 } |
| 214 | 205 |
| 215 UsersPrivateIsWhitelistManagedFunction:: | 206 UsersPrivateIsWhitelistManagedFunction:: |
| 216 ~UsersPrivateIsWhitelistManagedFunction() { | 207 ~UsersPrivateIsWhitelistManagedFunction() { |
| 217 } | 208 } |
| 218 | 209 |
| 219 ExtensionFunction::ResponseAction | 210 ExtensionFunction::ResponseAction |
| 220 UsersPrivateIsWhitelistManagedFunction::Run() { | 211 UsersPrivateIsWhitelistManagedFunction::Run() { |
| 221 bool is_managed = g_browser_process->platform_part() | 212 bool is_managed = g_browser_process->platform_part() |
| 222 ->browser_policy_connector_chromeos() | 213 ->browser_policy_connector_chromeos() |
| 223 ->IsEnterpriseManaged(); | 214 ->IsEnterpriseManaged(); |
| 224 return RespondNow( | 215 return RespondNow(OneArgument(new base::FundamentalValue(is_managed))); |
| 225 OneArgument(base::MakeUnique<base::FundamentalValue>(is_managed))); | |
| 226 } | 216 } |
| 227 | 217 |
| 228 } // namespace extensions | 218 } // namespace extensions |
| OLD | NEW |