Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / password_manager / sync_metrics.cc
blob304bb6d92954ef2d4e4b11df73cdf10adb9550b4
1 // Copyright 2014 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.
5 #include "chrome/browser/password_manager/sync_metrics.h"
7 #include "chrome/browser/signin/signin_manager_factory.h"
8 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "chrome/browser/sync/profile_sync_service_factory.h"
10 #include "components/signin/core/browser/signin_manager.h"
11 #include "google_apis/gaia/gaia_auth_util.h"
12 #include "google_apis/gaia/gaia_urls.h"
14 namespace password_manager_sync_metrics {
16 std::string GetSyncUsername(Profile* profile) {
17 // If sync is set up, return early if we aren't syncing passwords.
18 if (ProfileSyncServiceFactory::HasProfileSyncService(profile)) {
19 ProfileSyncService* sync_service =
20 ProfileSyncServiceFactory::GetForProfile(profile);
21 if (!sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS))
22 return std::string();
25 SigninManagerBase* signin_manager =
26 SigninManagerFactory::GetForProfile(profile);
28 if (!signin_manager)
29 return std::string();
31 return signin_manager->GetAuthenticatedUsername();
34 bool IsSyncAccountCredential(Profile* profile,
35 const std::string& username,
36 const std::string& origin) {
37 if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec())
38 return false;
40 return gaia::AreEmailsSame(username, GetSyncUsername(profile));
43 } // namespace password_manager_sync_metrics