summaryrefslogtreecommitdiffstats
path: root/chrome/browser/password_manager/sync_metrics.cc
blob: 4eddf427ccd22db327b2fa421aaee66bd509056d (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
// Copyright 2014 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 "chrome/browser/password_manager/sync_metrics.h"

#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/signin/core/browser/signin_manager.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_urls.h"

namespace password_manager_sync_metrics {

std::string GetSyncUsername(Profile* profile) {
  SigninManagerBase* signin_manager =
      SigninManagerFactory::GetForProfile(profile);
  if (!signin_manager)
    return "";

  return signin_manager->GetAuthenticatedUsername();
}

bool IsSyncAccountCredential(Profile* profile,
                             const std::string& username,
                             const std::string& origin) {
  if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec())
    return false;

  return gaia::AreEmailsSame(username, GetSyncUsername(profile));
}

}  // namespace password_manager_sync_metrics