OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/password_manager/sync_metrics.h" | 5 #include "chrome/browser/password_manager/sync_metrics.h" |
6 | 6 |
7 #include "chrome/browser/signin/signin_manager_factory.h" | 7 #include "chrome/browser/signin/signin_manager_factory.h" |
8 #include "chrome/browser/sync/profile_sync_service.h" | 8 #include "chrome/browser/sync/profile_sync_service.h" |
9 #include "chrome/browser/sync/profile_sync_service_factory.h" | 9 #include "chrome/browser/sync/profile_sync_service_factory.h" |
10 #include "components/signin/core/browser/signin_manager.h" | 10 #include "components/signin/core/browser/signin_manager.h" |
11 #include "google_apis/gaia/gaia_auth_util.h" | 11 #include "google_apis/gaia/gaia_auth_util.h" |
12 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
13 | 13 |
14 namespace password_manager_sync_metrics { | 14 namespace password_manager_sync_metrics { |
15 | 15 |
16 std::string GetSyncUsername(Profile* profile) { | 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->HasSyncSetupCompleted() || |
| 22 !sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) |
| 23 return std::string(); |
| 24 } |
| 25 |
17 SigninManagerBase* signin_manager = | 26 SigninManagerBase* signin_manager = |
18 SigninManagerFactory::GetForProfile(profile); | 27 SigninManagerFactory::GetForProfile(profile); |
| 28 |
19 if (!signin_manager) | 29 if (!signin_manager) |
20 return ""; | 30 return std::string(); |
21 | 31 |
22 return signin_manager->GetAuthenticatedUsername(); | 32 return signin_manager->GetAuthenticatedUsername(); |
23 } | 33 } |
24 | 34 |
25 bool IsSyncAccountCredential(Profile* profile, | 35 bool IsSyncAccountCredential(Profile* profile, |
26 const std::string& username, | 36 const std::string& username, |
27 const std::string& origin) { | 37 const std::string& origin) { |
28 if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec()) | 38 if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec()) |
29 return false; | 39 return false; |
30 | 40 |
31 return gaia::AreEmailsSame(username, GetSyncUsername(profile)); | 41 return gaia::AreEmailsSame(username, GetSyncUsername(profile)); |
32 } | 42 } |
33 | 43 |
34 } // namespace password_manager_sync_metrics | 44 } // namespace password_manager_sync_metrics |
OLD | NEW |