Commit c885020e authored by vabr's avatar vabr Committed by Commit bot

[Password Manager] Improve signature of PasswordManagerClient::IsPasswordSyncEnabled

Currently, IsPasswordSyncEnabled needs to know if the caller is interested in syncing passwords with a custom passphrase or without, and returns a Boolean depending on whether the expected syncing occurs or not.

This CL gets rid of the need to pass the expectation, and changes the Boolean return value to say: no password sync, p.s. without a custom passphrase, or p.s. with a custom passphrase. It also changes the name of the method and the associated enum to make sense with the new signature.

This is a cosmetic change, but will make a subsequent CL easier to digest.

R=melandory@chromium.org

BUG=400674,486739

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

Cr-Commit-Position: refs/heads/master@{#329637}
parent 0f3dfbe5
...@@ -82,8 +82,8 @@ void ReportMetrics(bool password_manager_enabled, ...@@ -82,8 +82,8 @@ void ReportMetrics(bool password_manager_enabled,
// May be null in tests. // May be null in tests.
if (store) { if (store) {
store->ReportMetrics(client->GetSyncUsername(), store->ReportMetrics(client->GetSyncUsername(),
client->IsPasswordSyncEnabled( client->GetPasswordSyncState() ==
password_manager::ONLY_CUSTOM_PASSPHRASE)); password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE);
} }
UMA_HISTOGRAM_BOOLEAN("PasswordManager.Enabled", password_manager_enabled); UMA_HISTOGRAM_BOOLEAN("PasswordManager.Enabled", password_manager_enabled);
} }
...@@ -305,20 +305,18 @@ ChromePasswordManagerClient::GetPasswordStore() const { ...@@ -305,20 +305,18 @@ ChromePasswordManagerClient::GetPasswordStore() const {
profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
} }
bool ChromePasswordManagerClient::IsPasswordSyncEnabled( password_manager::PasswordSyncState
password_manager::CustomPassphraseState state) const { ChromePasswordManagerClient::GetPasswordSyncState() const {
ProfileSyncService* sync_service = ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile_); ProfileSyncServiceFactory::GetForProfile(profile_);
if (sync_service && sync_service->HasSyncSetupCompleted() && if (sync_service && sync_service->HasSyncSetupCompleted() &&
sync_service->SyncActive() && sync_service->SyncActive() &&
sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) { sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) {
if (sync_service->IsUsingSecondaryPassphrase()) { return sync_service->IsUsingSecondaryPassphrase()
return state == password_manager::ONLY_CUSTOM_PASSPHRASE; ? password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE
} else { : password_manager::SYNCING_NORMAL_ENCRYPTION;
return state == password_manager::WITHOUT_CUSTOM_PASSPHRASE;
}
} }
return false; return password_manager::NOT_SYNCING_PASSWORDS;
} }
void ChromePasswordManagerClient::OnLogRouterAvailabilityChanged( void ChromePasswordManagerClient::OnLogRouterAvailabilityChanged(
......
...@@ -69,8 +69,7 @@ class ChromePasswordManagerClient ...@@ -69,8 +69,7 @@ class ChromePasswordManagerClient
const autofill::PasswordFormMap& best_matches) const override; const autofill::PasswordFormMap& best_matches) const override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
password_manager::PasswordStore* GetPasswordStore() const override; password_manager::PasswordStore* GetPasswordStore() const override;
bool IsPasswordSyncEnabled( password_manager::PasswordSyncState GetPasswordSyncState() const override;
password_manager::CustomPassphraseState state) const override;
void OnLogRouterAvailabilityChanged(bool router_can_be_used) override; void OnLogRouterAvailabilityChanged(bool router_can_be_used) override;
void LogSavePasswordProgress(const std::string& text) const override; void LogSavePasswordProgress(const std::string& text) const override;
bool IsLoggingActive() const override; bool IsLoggingActive() const override;
......
...@@ -357,7 +357,7 @@ TEST_F(ChromePasswordManagerClientTest, ...@@ -357,7 +357,7 @@ TEST_F(ChromePasswordManagerClientTest,
EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage()); EXPECT_TRUE(client->IsPasswordManagementEnabledForCurrentPage());
} }
TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) { TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) {
ChromePasswordManagerClient* client = GetClient(); ChromePasswordManagerClient* client = GetClient();
ProfileSyncServiceMock* mock_sync_service = ProfileSyncServiceMock* mock_sync_service =
...@@ -376,39 +376,31 @@ TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) { ...@@ -376,39 +376,31 @@ TEST_F(ChromePasswordManagerClientTest, IsPasswordSyncEnabled) {
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
// Passwords are syncing and custom passphrase isn't used. // Passwords are syncing and custom passphrase isn't used.
EXPECT_FALSE( EXPECT_EQ(password_manager::SYNCING_NORMAL_ENCRYPTION,
client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); client->GetPasswordSyncState());
EXPECT_TRUE(client->IsPasswordSyncEnabled(
password_manager::WITHOUT_CUSTOM_PASSPHRASE));
// Again, using a custom passphrase. // Again, using a custom passphrase.
EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
EXPECT_TRUE( EXPECT_EQ(password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE,
client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); client->GetPasswordSyncState());
EXPECT_FALSE(client->IsPasswordSyncEnabled(
password_manager::WITHOUT_CUSTOM_PASSPHRASE));
// Always return false if we aren't syncing passwords. // Report correctly if we aren't syncing passwords.
active_types.Remove(syncer::PASSWORDS); active_types.Remove(syncer::PASSWORDS);
active_types.Put(syncer::BOOKMARKS); active_types.Put(syncer::BOOKMARKS);
EXPECT_CALL(*mock_sync_service, GetActiveDataTypes()) EXPECT_CALL(*mock_sync_service, GetActiveDataTypes())
.WillRepeatedly(Return(active_types)); .WillRepeatedly(Return(active_types));
EXPECT_FALSE( EXPECT_EQ(password_manager::NOT_SYNCING_PASSWORDS,
client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); client->GetPasswordSyncState());
EXPECT_FALSE(client->IsPasswordSyncEnabled(
password_manager::WITHOUT_CUSTOM_PASSPHRASE));
// Again, without a custom passphrase. // Again, without a custom passphrase.
EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase()) EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
EXPECT_FALSE( EXPECT_EQ(password_manager::NOT_SYNCING_PASSWORDS,
client->IsPasswordSyncEnabled(password_manager::ONLY_CUSTOM_PASSPHRASE)); client->GetPasswordSyncState());
EXPECT_FALSE(client->IsPasswordSyncEnabled(
password_manager::WITHOUT_CUSTOM_PASSPHRASE));
} }
TEST_F(ChromePasswordManagerClientTest, IsOffTheRecordTest) { TEST_F(ChromePasswordManagerClientTest, IsOffTheRecordTest) {
......
...@@ -57,8 +57,8 @@ bool PasswordGenerationManager::IsGenerationEnabled() const { ...@@ -57,8 +57,8 @@ bool PasswordGenerationManager::IsGenerationEnabled() const {
} }
// Don't consider sync enabled if the user has a custom passphrase. See // Don't consider sync enabled if the user has a custom passphrase. See
// crbug.com/358998 for more details. // http://crbug.com/358998 for more details.
if (!client_->IsPasswordSyncEnabled(WITHOUT_CUSTOM_PASSPHRASE)) { if (client_->GetPasswordSyncState() != SYNCING_NORMAL_ENCRYPTION) {
VLOG(2) << "Generation disabled because passwords are not being synced or" VLOG(2) << "Generation disabled because passwords are not being synced or"
<< " custom passphrase is used."; << " custom passphrase is used.";
return false; return false;
......
...@@ -66,7 +66,7 @@ class TestPasswordManagerDriver : public StubPasswordManagerDriver { ...@@ -66,7 +66,7 @@ class TestPasswordManagerDriver : public StubPasswordManagerDriver {
class MockPasswordManagerClient : public StubPasswordManagerClient { class MockPasswordManagerClient : public StubPasswordManagerClient {
public: public:
MOCK_CONST_METHOD1(IsPasswordSyncEnabled, bool(CustomPassphraseState)); MOCK_CONST_METHOD0(GetPasswordSyncState, PasswordSyncState());
MOCK_CONST_METHOD0(IsSavingEnabledForCurrentPage, bool()); MOCK_CONST_METHOD0(IsSavingEnabledForCurrentPage, bool());
MOCK_CONST_METHOD0(IsOffTheRecord, bool()); MOCK_CONST_METHOD0(IsOffTheRecord, bool());
...@@ -122,24 +122,32 @@ class PasswordGenerationManagerTest : public testing::Test { ...@@ -122,24 +122,32 @@ class PasswordGenerationManagerTest : public testing::Test {
TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) {
// Enabling the PasswordManager and password sync should cause generation to // Enabling the PasswordManager and password sync should cause generation to
// be enabled. // be enabled, unless the sync is with a custom passphrase.
EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(true));
EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION));
EXPECT_TRUE(IsGenerationEnabled()); EXPECT_TRUE(IsGenerationEnabled());
EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(SYNCING_WITH_CUSTOM_PASSPHRASE));
EXPECT_FALSE(IsGenerationEnabled());
// Disabling password syncing should cause generation to be disabled. // Disabling password syncing should cause generation to be disabled.
EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(NOT_SYNCING_PASSWORDS));
EXPECT_FALSE(IsGenerationEnabled()); EXPECT_FALSE(IsGenerationEnabled());
// Disabling the PasswordManager should cause generation to be disabled even // Disabling the PasswordManager should cause generation to be disabled even
// if syncing is enabled. // if syncing is enabled.
EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION));
EXPECT_FALSE(IsGenerationEnabled());
EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(SYNCING_WITH_CUSTOM_PASSPHRASE));
EXPECT_FALSE(IsGenerationEnabled()); EXPECT_FALSE(IsGenerationEnabled());
} }
...@@ -147,8 +155,8 @@ TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { ...@@ -147,8 +155,8 @@ TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) {
// Setup so that IsGenerationEnabled() returns true. // Setup so that IsGenerationEnabled() returns true.
EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(true));
EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION));
autofill::FormData login_form; autofill::FormData login_form;
login_form.origin = GURL("http://www.yahoo.com/login/"); login_form.origin = GURL("http://www.yahoo.com/login/");
...@@ -201,8 +209,8 @@ TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncStateIncognito) { ...@@ -201,8 +209,8 @@ TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncStateIncognito) {
EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true));
PrefService* prefs = client_->GetPrefs(); PrefService* prefs = client_->GetPrefs();
prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true);
EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) EXPECT_CALL(*client_, GetPasswordSyncState())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION));
EXPECT_FALSE(IsGenerationEnabled()); EXPECT_FALSE(IsGenerationEnabled());
} }
......
...@@ -29,9 +29,8 @@ void PasswordManagerClient::PasswordAutofillWasBlocked( ...@@ -29,9 +29,8 @@ void PasswordManagerClient::PasswordAutofillWasBlocked(
const autofill::PasswordFormMap& best_matches) const { const autofill::PasswordFormMap& best_matches) const {
} }
bool PasswordManagerClient::IsPasswordSyncEnabled( PasswordSyncState PasswordManagerClient::GetPasswordSyncState() const {
CustomPassphraseState state) const { return NOT_SYNCING_PASSWORDS;
return false;
} }
void PasswordManagerClient::OnLogRouterAvailabilityChanged( void PasswordManagerClient::OnLogRouterAvailabilityChanged(
......
...@@ -24,9 +24,10 @@ class PasswordManager; ...@@ -24,9 +24,10 @@ class PasswordManager;
class PasswordManagerDriver; class PasswordManagerDriver;
class PasswordStore; class PasswordStore;
enum CustomPassphraseState { enum PasswordSyncState {
WITHOUT_CUSTOM_PASSPHRASE, NOT_SYNCING_PASSWORDS,
ONLY_CUSTOM_PASSPHRASE SYNCING_NORMAL_ENCRYPTION,
SYNCING_WITH_CUSTOM_PASSPHRASE
}; };
enum class CredentialSourceType { enum class CredentialSourceType {
...@@ -125,10 +126,9 @@ class PasswordManagerClient { ...@@ -125,10 +126,9 @@ class PasswordManagerClient {
// Returns the PasswordStore associated with this instance. // Returns the PasswordStore associated with this instance.
virtual PasswordStore* GetPasswordStore() const = 0; virtual PasswordStore* GetPasswordStore() const = 0;
// Returns true if password sync is enabled in the embedder. Return value for // Reports whether and how passwords are synced in the embedder. The default
// custom passphrase users depends on |state|. The default implementation // implementation always returns NOT_SYNCING_PASSWORDS.
// always returns false. virtual PasswordSyncState GetPasswordSyncState() const;
virtual bool IsPasswordSyncEnabled(CustomPassphraseState state) const;
// Only for clients which registered with a LogRouter: If called with // Only for clients which registered with a LogRouter: If called with
// |router_can_be_used| set to false, the client may no longer use the // |router_can_be_used| set to false, the client may no longer use the
......
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