summaryrefslogtreecommitdiff
path: root/chromium/services/identity/identity_manager.cc
blob: 8ea9d7250cfebd9e4b73f159a15f07bff6f70bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/identity/identity_manager.h"

#include "components/signin/core/account_id/account_id.h"
#include "components/signin/core/browser/account_info.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace identity {

// static
void IdentityManager::Create(mojom::IdentityManagerRequest request,
                             SigninManagerBase* signin_manager) {
  mojo::MakeStrongBinding(base::MakeUnique<IdentityManager>(signin_manager),
                          std::move(request));
}

IdentityManager::IdentityManager(SigninManagerBase* signin_manager)
    : signin_manager_(signin_manager) {}

IdentityManager::~IdentityManager() {}

void IdentityManager::GetPrimaryAccountId(
    const GetPrimaryAccountIdCallback& callback) {
  AccountId account_id = EmptyAccountId();

  if (signin_manager_->IsAuthenticated()) {
    AccountInfo account_info = signin_manager_->GetAuthenticatedAccountInfo();
    account_id =
        AccountId::FromUserEmailGaiaId(account_info.email, account_info.gaia);
  }

  callback.Run(account_id);
}

}  // namespace identity