| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/password_manager/sync/browser/password_sync_util.h" | 5 #include "components/password_manager/sync/browser/password_sync_util.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/common/password_form.h" | 8 #include "components/autofill/core/common/password_form.h" |
| 9 #include "google_apis/gaia/gaia_auth_util.h" | 9 #include "google_apis/gaia/gaia_auth_util.h" |
| 10 #include "google_apis/gaia/gaia_urls.h" | 10 #include "google_apis/gaia/gaia_urls.h" |
| 11 #include "url/origin.h" | 11 #include "url/origin.h" |
| 12 | 12 |
| 13 using autofill::PasswordForm; | 13 using autofill::PasswordForm; |
| 14 using url::Origin; | 14 using url::Origin; |
| 15 | 15 |
| 16 namespace password_manager { | 16 namespace password_manager { |
| 17 namespace sync_util { | 17 namespace sync_util { |
| 18 | 18 |
| 19 std::string GetSyncUsernameIfSyncingPasswords( | 19 std::string GetSyncUsernameIfSyncingPasswords( |
| 20 const sync_driver::SyncService* sync_service, | 20 const syncer::SyncService* sync_service, |
| 21 const SigninManagerBase* signin_manager) { | 21 const SigninManagerBase* signin_manager) { |
| 22 if (!signin_manager) | 22 if (!signin_manager) |
| 23 return std::string(); | 23 return std::string(); |
| 24 | 24 |
| 25 // If sync is set up, return early if we aren't syncing passwords. | 25 // If sync is set up, return early if we aren't syncing passwords. |
| 26 if (sync_service && | 26 if (sync_service && |
| 27 !sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS)) { | 27 !sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS)) { |
| 28 return std::string(); | 28 return std::string(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 return signin_manager->GetAuthenticatedAccountInfo().email; | 31 return signin_manager->GetAuthenticatedAccountInfo().email; |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool IsSyncAccountCredential(const autofill::PasswordForm& form, | 34 bool IsSyncAccountCredential(const autofill::PasswordForm& form, |
| 35 const sync_driver::SyncService* sync_service, | 35 const syncer::SyncService* sync_service, |
| 36 const SigninManagerBase* signin_manager) { | 36 const SigninManagerBase* signin_manager) { |
| 37 const Origin gaia_origin(GaiaUrls::GetInstance()->gaia_url().GetOrigin()); | 37 const Origin gaia_origin(GaiaUrls::GetInstance()->gaia_url().GetOrigin()); |
| 38 if (!Origin(GURL(form.signon_realm)).IsSameOriginWith(gaia_origin)) { | 38 if (!Origin(GURL(form.signon_realm)).IsSameOriginWith(gaia_origin)) { |
| 39 return false; | 39 return false; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // The empty username can mean that Chrome did not detect it correctly. For | 42 // The empty username can mean that Chrome did not detect it correctly. For |
| 43 // reasons described in http://crbug.com/636292#c1, the username is suspected | 43 // reasons described in http://crbug.com/636292#c1, the username is suspected |
| 44 // to be the sync username unless proven otherwise. | 44 // to be the sync username unless proven otherwise. |
| 45 if (form.username_value.empty()) | 45 if (form.username_value.empty()) |
| 46 return true; | 46 return true; |
| 47 | 47 |
| 48 return gaia::AreEmailsSame( | 48 return gaia::AreEmailsSame( |
| 49 base::UTF16ToUTF8(form.username_value), | 49 base::UTF16ToUTF8(form.username_value), |
| 50 GetSyncUsernameIfSyncingPasswords(sync_service, signin_manager)); | 50 GetSyncUsernameIfSyncingPasswords(sync_service, signin_manager)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace sync_util | 53 } // namespace sync_util |
| 54 } // namespace password_manager | 54 } // namespace password_manager |
| OLD | NEW |