Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/identity/identity_get_profile_user_info_ function.h" | 5 #include "chrome/browser/extensions/api/identity/identity_get_profile_user_info_ function.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/identity/identity_constants.h" | 7 #include "chrome/browser/extensions/api/identity/identity_constants.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 10 #include "chrome/common/extensions/api/identity.h" | 9 #include "chrome/common/extensions/api/identity.h" |
| 11 #include "components/signin/core/browser/signin_manager.h" | 10 #include "content/public/common/service_manager_connection.h" |
| 12 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 13 #include "extensions/common/permissions/permissions_data.h" | 12 #include "extensions/common/permissions/permissions_data.h" |
| 13 #include "services/identity/public/interfaces/constants.mojom.h" | |
| 14 #include "services/service_manager/public/cpp/connector.h" | |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 IdentityGetProfileUserInfoFunction::IdentityGetProfileUserInfoFunction() { | 18 IdentityGetProfileUserInfoFunction::IdentityGetProfileUserInfoFunction() { |
| 18 } | 19 } |
| 19 | 20 |
| 20 IdentityGetProfileUserInfoFunction::~IdentityGetProfileUserInfoFunction() { | 21 IdentityGetProfileUserInfoFunction::~IdentityGetProfileUserInfoFunction() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 ExtensionFunction::ResponseAction IdentityGetProfileUserInfoFunction::Run() { | 24 ExtensionFunction::ResponseAction IdentityGetProfileUserInfoFunction::Run() { |
| 24 if (GetProfile()->IsOffTheRecord()) { | 25 if (GetProfile()->IsOffTheRecord()) { |
| 25 return RespondNow(Error(identity_constants::kOffTheRecord)); | 26 return RespondNow(Error(identity_constants::kOffTheRecord)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 AccountInfo account = SigninManagerFactory::GetForProfile( | 29 if (!identity_manager_.is_bound()) { |
|
Ken Rockot(use gerrit already)
2017/03/21 14:53:09
It's been a while, but IIRC this test is redundant
blundell
2017/03/21 16:08:47
+1000, I'd love to use this effort as a demonstrat
blundell
2017/03/24 09:37:59
Done.
| |
| 29 GetProfile())->GetAuthenticatedAccountInfo(); | 30 content::BrowserContext::GetConnectorFor(GetProfile()) |
| 30 api::identity::ProfileUserInfo profile_user_info; | 31 ->BindInterface(identity::mojom::kServiceName, |
| 31 if (extension()->permissions_data()->HasAPIPermission( | 32 mojo::MakeRequest(&identity_manager_)); |
| 32 APIPermission::kIdentityEmail)) { | |
| 33 profile_user_info.email = account.email; | |
| 34 profile_user_info.id = account.gaia; | |
| 35 } | 33 } |
| 36 | 34 |
| 37 return RespondNow(OneArgument(profile_user_info.ToValue())); | 35 identity_manager_->GetPrimaryAccountId(base::Bind( |
| 36 &IdentityGetProfileUserInfoFunction::OnReceivedPrimaryAccountId, this)); | |
| 37 | |
| 38 return RespondLater(); | |
| 39 } | |
| 40 | |
| 41 void IdentityGetProfileUserInfoFunction::OnReceivedPrimaryAccountId( | |
| 42 const base::Optional<AccountId>& account_id) { | |
| 43 api::identity::ProfileUserInfo profile_user_info; | |
| 44 if (account_id && extension()->permissions_data()->HasAPIPermission( | |
|
msarda
2017/03/23 10:48:57
I think there is no point in making a call to get
blundell
2017/03/24 09:37:59
Done.
| |
| 45 APIPermission::kIdentityEmail)) { | |
| 46 profile_user_info.email = account_id->GetUserEmail(); | |
| 47 profile_user_info.id = account_id->GetGaiaId(); | |
| 48 } | |
| 49 | |
| 50 Respond(OneArgument(profile_user_info.ToValue())); | |
| 38 } | 51 } |
| 39 | 52 |
| 40 } // namespace extensions | 53 } // namespace extensions |
| OLD | NEW |