Commit 50e656e2 authored by gcasto@chromium.org's avatar gcasto@chromium.org

[Password Manager] Fix crash in reporting sync stats.

It is possible for password_sync_metrics::IsPasswordSyncUsername() to be
called during sync setup, which currently causes a stack overflow since
GetPasswordSyncUsername() will try to re-initialize sync. Fixed by not checking
to see if the user is syncing passwords, just if they have a saved username.
This is slightly less specific, but determining if password sync is occuring
during setup doesn't seem reasonable.

R=isherman@chromium.org
TBR=vabr@chromium.org
BUG=393626, 386403

Review URL: https://codereview.chromium.org/383083009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283254 0039d316-1c4b-4281-b951-d872f2087c98
parent 3418069e
...@@ -102,9 +102,9 @@ bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage() ...@@ -102,9 +102,9 @@ bool ChromePasswordManagerClient::IsPasswordManagerEnabledForCurrentPage()
return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost; return entry->GetURL().host() != chrome::kChromeUIChromeSigninHost;
} }
bool ChromePasswordManagerClient::IsPasswordSyncAccountCredential( bool ChromePasswordManagerClient::IsSyncAccountCredential(
const std::string& username, const std::string& origin) const { const std::string& username, const std::string& origin) const {
return password_manager_sync_metrics::IsPasswordSyncAccountCredential( return password_manager_sync_metrics::IsSyncAccountCredential(
profile_, username, origin); profile_, username, origin);
} }
......
...@@ -40,7 +40,7 @@ class ChromePasswordManagerClient ...@@ -40,7 +40,7 @@ class ChromePasswordManagerClient
// PasswordManagerClient implementation. // PasswordManagerClient implementation.
virtual bool IsAutomaticPasswordSavingEnabled() const OVERRIDE; virtual bool IsAutomaticPasswordSavingEnabled() const OVERRIDE;
virtual bool IsPasswordManagerEnabledForCurrentPage() const OVERRIDE; virtual bool IsPasswordManagerEnabledForCurrentPage() const OVERRIDE;
virtual bool IsPasswordSyncAccountCredential( virtual bool IsSyncAccountCredential(
const std::string& username, const std::string& origin) const OVERRIDE; const std::string& username, const std::string& origin) const OVERRIDE;
virtual void PromptUserToSavePassword( virtual void PromptUserToSavePassword(
password_manager::PasswordFormManager* form_to_save) OVERRIDE; password_manager::PasswordFormManager* form_to_save) OVERRIDE;
......
...@@ -228,7 +228,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( ...@@ -228,7 +228,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
NOTIMPLEMENTED(); NOTIMPLEMENTED();
#endif #endif
std::string sync_username = std::string sync_username =
password_manager_sync_metrics::GetPasswordSyncUsername(profile); password_manager_sync_metrics::GetSyncUsername(profile);
if (!ps || !ps->Init( if (!ps || !ps->Init(
sync_start_util::GetFlareForSyncableService(profile->GetPath()), sync_start_util::GetFlareForSyncableService(profile->GetPath()),
sync_username)) { sync_username)) {
......
...@@ -13,14 +13,7 @@ ...@@ -13,14 +13,7 @@
namespace password_manager_sync_metrics { namespace password_manager_sync_metrics {
std::string GetPasswordSyncUsername(Profile* profile) { std::string GetSyncUsername(Profile* profile) {
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
if (!sync_service ||
!sync_service->HasSyncSetupCompleted() ||
!sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS))
return "";
SigninManagerBase* signin_manager = SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile); SigninManagerFactory::GetForProfile(profile);
if (!signin_manager) if (!signin_manager)
...@@ -29,13 +22,13 @@ std::string GetPasswordSyncUsername(Profile* profile) { ...@@ -29,13 +22,13 @@ std::string GetPasswordSyncUsername(Profile* profile) {
return signin_manager->GetAuthenticatedUsername(); return signin_manager->GetAuthenticatedUsername();
} }
bool IsPasswordSyncAccountCredential(Profile* profile, bool IsSyncAccountCredential(Profile* profile,
const std::string& username, const std::string& username,
const std::string& origin) { const std::string& origin) {
if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec()) if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec())
return false; return false;
return gaia::AreEmailsSame(username, GetPasswordSyncUsername(profile)); return gaia::AreEmailsSame(username, GetSyncUsername(profile));
} }
} // namespace password_manager_sync_metrics } // namespace password_manager_sync_metrics
...@@ -12,14 +12,16 @@ class Profile; ...@@ -12,14 +12,16 @@ class Profile;
namespace password_manager_sync_metrics { namespace password_manager_sync_metrics {
// Returns the sync username for |profile|. Returns an empty string if the // Returns the sync username for |profile|. Returns an empty string if the
// |profile| isn't syncing passwords. // |profile| isn't syncing. It would be preferable to only return the username
std::string GetPasswordSyncUsername(Profile* profile); // if the user is syncing passwords, but that is not currently possible since
// this function can be called during sync setup (http://crbug.com/393626).
std::string GetSyncUsername(Profile* profile);
// Returns true if |username| and |origin| correspond to the account which is // Returns true if |username| and |origin| correspond to the account which is
// syncing passwords. Will return false if |profile| is not syncing passwords. // syncing. Will return false if |profile| is not syncing.
bool IsPasswordSyncAccountCredential(Profile* profile, bool IsSyncAccountCredential(Profile* profile,
const std::string& username, const std::string& username,
const std::string& origin); const std::string& origin);
} // namespace password_manager_sync_metrics } // namespace password_manager_sync_metrics
......
...@@ -129,7 +129,7 @@ void PasswordManagerPresenter::RequestShowPassword(size_t index) { ...@@ -129,7 +129,7 @@ void PasswordManagerPresenter::RequestShowPassword(size_t index) {
return; return;
} }
if (password_manager_sync_metrics::IsPasswordSyncAccountCredential( if (password_manager_sync_metrics::IsSyncAccountCredential(
password_view_->GetProfile(), password_view_->GetProfile(),
base::UTF16ToUTF8(password_list_[index]->username_value), base::UTF16ToUTF8(password_list_[index]->username_value),
password_list_[index]->signon_realm)) { password_list_[index]->signon_realm)) {
......
...@@ -561,7 +561,7 @@ void PasswordFormManager::UpdateLogin() { ...@@ -561,7 +561,7 @@ void PasswordFormManager::UpdateLogin() {
// Update metadata. // Update metadata.
++pending_credentials_.times_used; ++pending_credentials_.times_used;
if (client_->IsPasswordSyncAccountCredential( if (client_->IsSyncAccountCredential(
base::UTF16ToUTF8(pending_credentials_.username_value), base::UTF16ToUTF8(pending_credentials_.username_value),
pending_credentials_.signon_realm)) { pending_credentials_.signon_realm)) {
base::RecordAction( base::RecordAction(
......
...@@ -218,7 +218,7 @@ void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { ...@@ -218,7 +218,7 @@ void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) {
// Don't save credentials for the syncing account. See crbug.com/365832 for // Don't save credentials for the syncing account. See crbug.com/365832 for
// background. // background.
if (client_->IsPasswordSyncAccountCredential( if (client_->IsSyncAccountCredential(
base::UTF16ToUTF8(form.username_value), form.signon_realm)) { base::UTF16ToUTF8(form.username_value), form.signon_realm)) {
RecordFailure(SYNC_CREDENTIAL, form.origin.host(), logger.get()); RecordFailure(SYNC_CREDENTIAL, form.origin.host(), logger.get());
return; return;
......
...@@ -35,8 +35,8 @@ class PasswordManagerClient { ...@@ -35,8 +35,8 @@ class PasswordManagerClient {
virtual bool IsPasswordManagerEnabledForCurrentPage() const; virtual bool IsPasswordManagerEnabledForCurrentPage() const;
// Returns true if |username| and |origin| correspond to the account which is // Returns true if |username| and |origin| correspond to the account which is
// syncing passwords. // syncing.
virtual bool IsPasswordSyncAccountCredential( virtual bool IsSyncAccountCredential(
const std::string& username, const std::string& origin) const = 0; const std::string& username, const std::string& origin) const = 0;
// Informs the embedder of a password form that can be saved if the user // Informs the embedder of a password form that can be saved if the user
......
...@@ -43,7 +43,7 @@ namespace { ...@@ -43,7 +43,7 @@ namespace {
class MockPasswordManagerClient : public StubPasswordManagerClient { class MockPasswordManagerClient : public StubPasswordManagerClient {
public: public:
MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool()); MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool());
MOCK_CONST_METHOD2(IsPasswordSyncAccountCredential, MOCK_CONST_METHOD2(IsSyncAccountCredential,
bool(const std::string&, const std::string&)); bool(const std::string&, const std::string&));
MOCK_METHOD1(PromptUserToSavePassword, void(PasswordFormManager*)); MOCK_METHOD1(PromptUserToSavePassword, void(PasswordFormManager*));
MOCK_METHOD0(GetPasswordStore, PasswordStore*()); MOCK_METHOD0(GetPasswordStore, PasswordStore*());
...@@ -87,7 +87,7 @@ class PasswordManagerTest : public testing::Test { ...@@ -87,7 +87,7 @@ class PasswordManagerTest : public testing::Test {
EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage())
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
EXPECT_CALL(client_, IsPasswordSyncAccountCredential(_, _)) EXPECT_CALL(client_, IsSyncAccountCredential(_, _))
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_));
EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_));
...@@ -711,7 +711,7 @@ TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) { ...@@ -711,7 +711,7 @@ TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) {
} }
TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) {
EXPECT_CALL(client_, IsPasswordSyncAccountCredential(_, _)) EXPECT_CALL(client_, IsSyncAccountCredential(_, _))
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
// Simulate loading a simple form with no existing stored password. // Simulate loading a simple form with no existing stored password.
......
...@@ -10,7 +10,7 @@ StubPasswordManagerClient::StubPasswordManagerClient() {} ...@@ -10,7 +10,7 @@ StubPasswordManagerClient::StubPasswordManagerClient() {}
StubPasswordManagerClient::~StubPasswordManagerClient() {} StubPasswordManagerClient::~StubPasswordManagerClient() {}
bool StubPasswordManagerClient::IsPasswordSyncAccountCredential( bool StubPasswordManagerClient::IsSyncAccountCredential(
const std::string& username, const std::string& origin) const { const std::string& username, const std::string& origin) const {
return false; return false;
} }
......
...@@ -18,7 +18,7 @@ class StubPasswordManagerClient : public PasswordManagerClient { ...@@ -18,7 +18,7 @@ class StubPasswordManagerClient : public PasswordManagerClient {
virtual ~StubPasswordManagerClient(); virtual ~StubPasswordManagerClient();
// PasswordManagerClient: // PasswordManagerClient:
virtual bool IsPasswordSyncAccountCredential( virtual bool IsSyncAccountCredential(
const std::string& username, const std::string& origin) const OVERRIDE; const std::string& username, const std::string& origin) const OVERRIDE;
virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save) virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save)
OVERRIDE; OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment