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