Commit 2e14167b authored by vasilii@chromium.org's avatar vasilii@chromium.org

Add StartSyncFlare to PasswordSyncableService.

BUG=95758

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255690 0039d316-1c4b-4281-b951-d872f2087c98
parent 68ccff23
......@@ -10,7 +10,7 @@
BrowserContextKeyedService* MockPasswordStoreService::Build(
content::BrowserContext* /*profile*/) {
scoped_refptr<PasswordStore> store(new MockPasswordStore);
if (!store || !store->Init())
if (!store || !store->Init(syncer::SyncableService::StartSyncFlare()))
return NULL;
return new MockPasswordStoreService(store);
}
......
......@@ -8,6 +8,7 @@
#include "base/environment.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/sync/glue/sync_start_util.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_constants.h"
......@@ -220,7 +221,8 @@ BrowserContextKeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
#else
NOTIMPLEMENTED();
#endif
if (!ps || !ps->Init()) {
if (!ps || !ps->Init(
sync_start_util::GetFlareForSyncableService(profile->GetPath()))) {
NOTREACHED() << "Could not initialize password manager.";
return NULL;
}
......
......@@ -838,14 +838,15 @@ PasswordStoreMac::PasswordStoreMac(
PasswordStoreMac::~PasswordStoreMac() {}
bool PasswordStoreMac::Init() {
bool PasswordStoreMac::Init(
const syncer::SyncableService::StartSyncFlare& flare) {
thread_.reset(new base::Thread("Chrome_PasswordStore_Thread"));
if (!thread_->Start()) {
thread_.reset(NULL);
return false;
}
return PasswordStore::Init();
return PasswordStore::Init(flare);
}
// Mac stores passwords in the system keychain, which can block for an
......
......@@ -33,7 +33,8 @@ class PasswordStoreMac : public PasswordStore {
LoginDatabase* login_db);
// Initializes |thread_|.
virtual bool Init() OVERRIDE;
virtual bool Init(
const syncer::SyncableService::StartSyncFlare& flare) OVERRIDE;
protected:
virtual ~PasswordStoreMac();
......
......@@ -1043,7 +1043,7 @@ class PasswordStoreMacTest : public testing::Test {
base::MessageLoopProxy::current(),
keychain_,
login_db_);
ASSERT_TRUE(store_->Init());
ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare()));
}
virtual void TearDown() {
......
......@@ -198,7 +198,7 @@ TEST_F(PasswordStoreWinTest, DISABLED_ConvertIE7Login) {
done.Wait();
store_ = CreatePasswordStore();
EXPECT_TRUE(store_->Init());
EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare()));
MockPasswordStoreConsumer consumer;
......@@ -251,7 +251,7 @@ TEST_F(PasswordStoreWinTest, DISABLED_ConvertIE7Login) {
// Crashy. http://crbug.com/86558
TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) {
store_ = CreatePasswordStore();
EXPECT_TRUE(store_->Init());
EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare()));
PasswordFormData form_data = {
PasswordForm::SCHEME_HTML,
......@@ -294,7 +294,7 @@ TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) {
done.Wait();
store_ = CreatePasswordStore();
EXPECT_TRUE(store_->Init());
EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare()));
MockPasswordStoreConsumer password_consumer;
// Make sure we quit the MessageLoop even if the test fails.
......@@ -356,7 +356,7 @@ TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) {
TEST_F(PasswordStoreWinTest, EmptyLogins) {
store_ = CreatePasswordStore();
store_->Init();
store_->Init(syncer::SyncableService::StartSyncFlare());
PasswordFormData form_data = {
PasswordForm::SCHEME_HTML,
......@@ -390,7 +390,7 @@ TEST_F(PasswordStoreWinTest, EmptyLogins) {
TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) {
store_ = CreatePasswordStore();
store_->Init();
store_->Init(syncer::SyncableService::StartSyncFlare());
MockPasswordStoreConsumer consumer;
......@@ -411,7 +411,7 @@ TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) {
TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) {
store_ = CreatePasswordStore();
store_->Init();
store_->Init(syncer::SyncableService::StartSyncFlare());
MockPasswordStoreConsumer consumer;
......
......@@ -260,7 +260,7 @@ TEST_P(PasswordStoreXTest, Notifications) {
base::MessageLoopProxy::current(),
login_db_.release(),
GetBackend()));
store->Init();
store->Init(syncer::SyncableService::StartSyncFlare());
PasswordFormData form_data =
{ PasswordForm::SCHEME_HTML,
......@@ -365,7 +365,7 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
base::MessageLoopProxy::current(),
login_db_.release(),
GetBackend()));
store->Init();
store->Init(syncer::SyncableService::StartSyncFlare());
MockPasswordStoreConsumer consumer;
......
......@@ -10,7 +10,7 @@
BrowserContextKeyedService* TestPasswordStoreService::Build(
content::BrowserContext* /*profile*/) {
scoped_refptr<PasswordStore> store(new TestPasswordStore);
if (!store || !store->Init())
if (!store || !store->Init(syncer::SyncableService::StartSyncFlare()))
return NULL;
return new TestPasswordStoreService(store);
}
......
......@@ -387,7 +387,7 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) {
// Need a MessageLoop for callbacks.
base::MessageLoop message_loop;
scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore;
CHECK(password_store->Init());
CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare()));
TestPasswordManagerClient client(password_store.get());
TestPasswordManager password_manager(&client);
......
......@@ -95,7 +95,7 @@ class PasswordManagerTest : public testing::Test {
true);
store_ = new MockPasswordStore;
CHECK(store_->Init());
CHECK(store_->Init(syncer::SyncableService::StartSyncFlare()));
EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_));
EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_));
......
......@@ -12,6 +12,7 @@
#include "base/stl_util.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_store_consumer.h"
#include "components/password_manager/core/browser/password_syncable_service.h"
#if defined(PASSWORD_MANAGER_ENABLE_SYNC)
#include "components/password_manager/core/browser/password_syncable_service.h"
......@@ -75,10 +76,10 @@ PasswordStore::PasswordStore(
observers_(new ObserverListThreadSafe<Observer>()),
shutdown_called_(false) {}
bool PasswordStore::Init() {
bool PasswordStore::Init(const syncer::SyncableService::StartSyncFlare& flare) {
ReportMetrics();
#if defined(PASSWORD_MANAGER_ENABLE_SYNC)
ScheduleTask(base::Bind(&PasswordStore::InitSyncableService, this));
ScheduleTask(base::Bind(&PasswordStore::InitSyncableService, this, flare));
#endif
return true;
}
......@@ -239,10 +240,12 @@ void PasswordStore::NotifyLoginsChanged(
}
#if defined(PASSWORD_MANAGER_ENABLE_SYNC)
void PasswordStore::InitSyncableService() {
void PasswordStore::InitSyncableService(
const syncer::SyncableService::StartSyncFlare& flare) {
DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
DCHECK(!syncable_service_);
syncable_service_.reset(new PasswordSyncableService(this));
syncable_service_->InjectStartSyncFlare(flare);
}
void PasswordStore::DestroySyncableService() {
......
......@@ -16,6 +16,7 @@
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "components/password_manager/core/browser/password_store_change.h"
#include "sync/api/syncable_service.h"
class PasswordStore;
class PasswordStoreConsumer;
......@@ -113,7 +114,7 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner);
// Reimplement this to add custom initialization. Always call this too.
virtual bool Init();
virtual bool Init(const syncer::SyncableService::StartSyncFlare& flare);
// Adds the given PasswordForm to the secure password store asynchronously.
virtual void AddLogin(const autofill::PasswordForm& form);
......@@ -283,7 +284,8 @@ class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
#if defined(PASSWORD_MANAGER_ENABLE_SYNC)
// Creates PasswordSyncableService instance on the background thread.
void InitSyncableService();
void InitSyncableService(
const syncer::SyncableService::StartSyncFlare& flare);
// Deletes PasswordSyncableService instance on the background thread.
void DestroySyncableService();
......
......@@ -71,7 +71,7 @@ TEST_F(PasswordStoreDefaultTest, NonASCIIData) {
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
login_db_.release()));
store->Init();
store->Init(syncer::SyncableService::StartSyncFlare());
// Some non-ASCII password form data.
static const PasswordFormData form_data[] = {
......@@ -117,7 +117,7 @@ TEST_F(PasswordStoreDefaultTest, Notifications) {
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
login_db_.release()));
store->Init();
store->Init(syncer::SyncableService::StartSyncFlare());
PasswordFormData form_data =
{ PasswordForm::SCHEME_HTML,
......
......@@ -29,6 +29,14 @@ class MockPasswordStoreConsumer : public PasswordStoreConsumer {
void(const std::vector<PasswordForm*>&));
};
class StartSyncFlareMock {
public:
StartSyncFlareMock() {}
~StartSyncFlareMock() {}
MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType));
};
} // namespace
class PasswordStoreTest : public testing::Test {
......@@ -58,7 +66,7 @@ TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) {
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
login_db_.release()));
store->Init();
store->Init(syncer::SyncableService::StartSyncFlare());
const time_t cutoff = 1325376000; // 00:00 Jan 1 2012 UTC
// The passwords are all empty because PasswordStoreDefault doesn't store the
......@@ -182,3 +190,21 @@ TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) {
store->Shutdown();
base::MessageLoop::current()->RunUntilIdle();
}
TEST_F(PasswordStoreTest, StartSyncFlare) {
scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
login_db_.release()));
StartSyncFlareMock mock;
store->Init(base::Bind(&StartSyncFlareMock::StartSyncFlare,
base::Unretained(&mock)));
{
PasswordForm form;
EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS));
store->AddLogin(form);
base::MessageLoop::current()->RunUntilIdle();
}
store->Shutdown();
base::MessageLoop::current()->RunUntilIdle();
}
......@@ -278,9 +278,18 @@ syncer::SyncError PasswordSyncableService::ProcessSyncChanges(
void PasswordSyncableService::ActOnPasswordStoreChanges(
const PasswordStoreChangeList& local_changes) {
DCHECK(CalledOnValidThread());
if (!sync_processor_) {
if (!flare_.is_null()) {
flare_.Run(syncer::PASSWORDS);
flare_.Reset();
}
return;
}
// ActOnPasswordStoreChanges() can be called from ProcessSyncChanges(). Do
// nothing in this case.
if (!sync_processor_ || is_processing_sync_changes_)
if (is_processing_sync_changes_)
return;
syncer::SyncChangeList sync_changes;
for (PasswordStoreChangeList::const_iterator it = local_changes.begin();
......@@ -294,6 +303,12 @@ void PasswordSyncableService::ActOnPasswordStoreChanges(
sync_processor_->ProcessSyncChanges(FROM_HERE, sync_changes);
}
void PasswordSyncableService::InjectStartSyncFlare(
const syncer::SyncableService::StartSyncFlare& flare) {
DCHECK(CalledOnValidThread());
flare_ = flare;
}
bool PasswordSyncableService::ReadFromPasswordStore(
ScopedVector<autofill::PasswordForm>* password_entries,
PasswordEntryMap* passwords_entry_map) const {
......
......@@ -55,6 +55,11 @@ class PasswordSyncableService : public syncer::SyncableService,
// Notifies sync of changes to the password database.
void ActOnPasswordStoreChanges(const PasswordStoreChangeList& changes);
// Provides a StartSyncFlare to the SyncableService. See
// sync_start_util for more.
void InjectStartSyncFlare(
const syncer::SyncableService::StartSyncFlare& flare);
private:
typedef std::vector<autofill::PasswordForm*> PasswordForms;
// Map from password sync tag to password form.
......@@ -102,7 +107,13 @@ class PasswordSyncableService : public syncer::SyncableService,
// The password store that adds/updates/deletes password entries.
PasswordStore* const password_store_;
// A signal to start sync as soon as possible.
syncer::SyncableService::StartSyncFlare flare_;
// True if processing sync changes is in progress.
bool is_processing_sync_changes_;
DISALLOW_COPY_AND_ASSIGN(PasswordSyncableService);
};
// Converts the |password| into a SyncData object.
......
......@@ -86,6 +86,8 @@ class MockPasswordSyncableService : public PasswordSyncableService {
MOCK_METHOD1(NotifyPasswordStoreOfLoginChanges,
void (const PasswordStoreChangeList&));
MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType));
};
// Class to verify the arguments passed to |PasswordStore|.
......@@ -610,4 +612,23 @@ TEST_F(PasswordSyncableServiceTest, MergeDataAndPushBack) {
scoped_ptr<syncer::SyncErrorFactory>());
}
// Calls ActOnPasswordStoreChanges without SyncChangeProcessor. StartSyncFlare
// should be called.
TEST_F(PasswordSyncableServiceTest, StartSyncFlare) {
autofill::PasswordForm form;
form.signon_realm = "abc";
PasswordStoreChangeList list;
list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
// No flare and no SyncChangeProcessor, the call shouldn't crash.
service()->ActOnPasswordStoreChanges(list);
// Set the flare. It should be called as there is no SyncChangeProcessor.
service()->InjectStartSyncFlare(
base::Bind(&MockPasswordSyncableService::StartSyncFlare,
base::Unretained(service())));
EXPECT_CALL(*service(), StartSyncFlare(syncer::PASSWORDS));
service()->ActOnPasswordStoreChanges(list);
}
} // namespace
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