Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: chrome/browser/extensions/api/identity/identity_get_profile_user_info_function.cc

Issue 2753753007: Introduce Identity Service and its initial usage (Closed)
Patch Set: Response to reviews Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 (!extension()->permissions_data()->HasAPIPermission(
29 GetProfile())->GetAuthenticatedAccountInfo();
30 api::identity::ProfileUserInfo profile_user_info;
31 if (extension()->permissions_data()->HasAPIPermission(
32 APIPermission::kIdentityEmail)) { 30 APIPermission::kIdentityEmail)) {
33 profile_user_info.email = account.email; 31 api::identity::ProfileUserInfo profile_user_info;
34 profile_user_info.id = account.gaia; 32 return RespondNow(OneArgument(profile_user_info.ToValue()));
35 } 33 }
36 34
37 return RespondNow(OneArgument(profile_user_info.ToValue())); 35 content::BrowserContext::GetConnectorFor(GetProfile())
36 ->BindInterface(identity::mojom::kServiceName,
37 mojo::MakeRequest(&identity_manager_));
38
39 identity_manager_->GetPrimaryAccountId(base::Bind(
40 &IdentityGetProfileUserInfoFunction::OnReceivedPrimaryAccountId, this));
41
42 return RespondLater();
43 }
44
45 void IdentityGetProfileUserInfoFunction::OnReceivedPrimaryAccountId(
46 const base::Optional<AccountId>& account_id) {
47 DCHECK(extension()->permissions_data()->HasAPIPermission(
48 APIPermission::kIdentityEmail));
49
50 api::identity::ProfileUserInfo profile_user_info;
51
52 if (account_id) {
53 profile_user_info.email = account_id->GetUserEmail();
54 profile_user_info.id = account_id->GetGaiaId();
55 }
56
57 Respond(OneArgument(profile_user_info.ToValue()));
38 } 58 }
39 59
40 } // namespace extensions 60 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_get_profile_user_info_function.h ('k') | chrome/browser/profiles/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698