Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / password_manager / sync / browser / password_sync_util.cc
blob19292c5811c303394ff686b6cca8fc7358a5737d
1 // Copyright 2015 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 "components/password_manager/sync/browser/password_sync_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/common/password_form.h"
9 #include "google_apis/gaia/gaia_auth_util.h"
10 #include "google_apis/gaia/gaia_urls.h"
11 #include "url/origin.h"
13 using autofill::PasswordForm;
14 using url::Origin;
16 namespace password_manager {
17 namespace sync_util {
19 std::string GetSyncUsernameIfSyncingPasswords(
20 const sync_driver::SyncService* sync_service,
21 const SigninManagerBase* signin_manager) {
22 if (!signin_manager)
23 return std::string();
25 // If sync is set up, return early if we aren't syncing passwords.
26 if (sync_service &&
27 !sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS)) {
28 return std::string();
31 return signin_manager->GetAuthenticatedAccountInfo().email;
34 bool IsSyncAccountCredential(const autofill::PasswordForm& form,
35 const sync_driver::SyncService* sync_service,
36 const SigninManagerBase* signin_manager) {
37 const Origin gaia_origin(GaiaUrls::GetInstance()->gaia_url().GetOrigin());
38 if (!Origin(GURL(form.signon_realm)).IsSameOriginWith(gaia_origin)) {
39 return false;
42 return gaia::AreEmailsSame(
43 base::UTF16ToUTF8(form.username_value),
44 GetSyncUsernameIfSyncingPasswords(sync_service, signin_manager));
47 } // namespace sync_util
48 } // namespace password_manager