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
;
16 namespace password_manager
{
19 std::string
GetSyncUsernameIfSyncingPasswords(
20 const sync_driver::SyncService
* sync_service
,
21 const SigninManagerBase
* signin_manager
) {
25 // If sync is set up, return early if we aren't syncing passwords.
27 !sync_service
->GetPreferredDataTypes().Has(syncer::PASSWORDS
)) {
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
)) {
42 return gaia::AreEmailsSame(
43 base::UTF16ToUTF8(form
.username_value
),
44 GetSyncUsernameIfSyncingPasswords(sync_service
, signin_manager
));
47 } // namespace sync_util
48 } // namespace password_manager