OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/extensions/api/identity/identity_get_accounts_function.
h" |
| 6 |
| 7 #include "chrome/browser/extensions/api/identity/identity_api.h" |
| 8 #include "chrome/browser/extensions/api/identity/identity_constants.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/extensions/api/identity.h" |
| 11 #include "components/signin/core/common/profile_management_switches.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 IdentityGetAccountsFunction::IdentityGetAccountsFunction() { |
| 16 } |
| 17 |
| 18 IdentityGetAccountsFunction::~IdentityGetAccountsFunction() { |
| 19 } |
| 20 |
| 21 ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() { |
| 22 if (GetProfile()->IsOffTheRecord()) { |
| 23 return RespondNow(Error(identity_constants::kOffTheRecord)); |
| 24 } |
| 25 |
| 26 std::vector<std::string> gaia_ids = |
| 27 IdentityAPI::GetFactoryInstance()->Get(GetProfile())->GetAccounts(); |
| 28 DCHECK(gaia_ids.size() < 2 || switches::IsExtensionsMultiAccount()); |
| 29 |
| 30 std::unique_ptr<base::ListValue> infos(new base::ListValue()); |
| 31 |
| 32 for (std::vector<std::string>::const_iterator it = gaia_ids.begin(); |
| 33 it != gaia_ids.end(); |
| 34 ++it) { |
| 35 api::identity::AccountInfo account_info; |
| 36 account_info.id = *it; |
| 37 infos->Append(account_info.ToValue()); |
| 38 } |
| 39 |
| 40 return RespondNow(OneArgument(std::move(infos))); |
| 41 } |
| 42 |
| 43 } // namespace extensions |
OLD | NEW |