Commit b8a7919f authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[USS] Remove dead code: AutofillDataTypeController

This CL removes another piece of dead-code after the successful launch
of the USS autocomplete implementation. This was unintentionally omitted
in the main cleanup CL
(https://chromium-review.googlesource.com/c/chromium/src/+/921621).

Bug: 702711
Change-Id: I4eb5ee4d81a87457ea978d9ee15df22bb2b8aaae
Reviewed-on: https://chromium-review.googlesource.com/1028231Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555339}
parent e92c5e4e
...@@ -154,8 +154,6 @@ static_library("browser") { ...@@ -154,8 +154,6 @@ static_library("browser") {
"webdata/autocomplete_sync_bridge.h", "webdata/autocomplete_sync_bridge.h",
"webdata/autofill_change.cc", "webdata/autofill_change.cc",
"webdata/autofill_change.h", "webdata/autofill_change.h",
"webdata/autofill_data_type_controller.cc",
"webdata/autofill_data_type_controller.h",
"webdata/autofill_entry.cc", "webdata/autofill_entry.cc",
"webdata/autofill_entry.h", "webdata/autofill_entry.h",
"webdata/autofill_profile_data_type_controller.cc", "webdata/autofill_profile_data_type_controller.cc",
...@@ -413,7 +411,6 @@ source_set("unit_tests") { ...@@ -413,7 +411,6 @@ source_set("unit_tests") {
"ui/card_unmask_prompt_controller_impl_unittest.cc", "ui/card_unmask_prompt_controller_impl_unittest.cc",
"validation_unittest.cc", "validation_unittest.cc",
"webdata/autocomplete_sync_bridge_unittest.cc", "webdata/autocomplete_sync_bridge_unittest.cc",
"webdata/autofill_data_type_controller_unittest.cc",
"webdata/autofill_profile_syncable_service_unittest.cc", "webdata/autofill_profile_syncable_service_unittest.cc",
"webdata/autofill_table_unittest.cc", "webdata/autofill_table_unittest.cc",
"webdata/autofill_wallet_metadata_syncable_service_unittest.cc", "webdata/autofill_wallet_metadata_syncable_service_unittest.cc",
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/webdata/autofill_data_type_controller.h"
#include <utility>
#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/sync/base/experiments.h"
#include "components/sync/driver/sync_client.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/model/sync_error.h"
#include "components/sync/model/syncable_service.h"
namespace browser_sync {
AutofillDataTypeController::AutofillDataTypeController(
scoped_refptr<base::SingleThreadTaskRunner> db_thread,
const base::Closure& dump_stack,
syncer::SyncClient* sync_client,
const scoped_refptr<autofill::AutofillWebDataService>& web_data_service)
: AsyncDirectoryTypeController(syncer::AUTOFILL,
dump_stack,
sync_client,
syncer::GROUP_DB,
std::move(db_thread)),
web_data_service_(web_data_service),
currently_enabled_(IsEnabled()) {
pref_registrar_.Init(sync_client_->GetPrefService());
pref_registrar_.Add(autofill::prefs::kAutofillEnabled,
base::Bind(&AutofillDataTypeController::OnUserPrefChanged,
base::AsWeakPtr(this)));
}
void AutofillDataTypeController::WebDatabaseLoaded() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(MODEL_STARTING, state());
OnModelLoaded();
}
AutofillDataTypeController::~AutofillDataTypeController() {
DCHECK(CalledOnValidThread());
}
bool AutofillDataTypeController::StartModels() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(MODEL_STARTING, state());
if (!IsEnabled()) {
DisableForPolicy();
return false;
}
if (!web_data_service_)
return false;
if (web_data_service_->IsDatabaseLoaded()) {
return true;
} else {
web_data_service_->RegisterDBLoadedCallback(base::Bind(
&AutofillDataTypeController::WebDatabaseLoaded, base::AsWeakPtr(this)));
return false;
}
}
bool AutofillDataTypeController::ReadyForStart() const {
DCHECK(CalledOnValidThread());
return currently_enabled_;
}
void AutofillDataTypeController::OnUserPrefChanged() {
DCHECK(CalledOnValidThread());
bool new_enabled = IsEnabled();
if (currently_enabled_ == new_enabled)
return; // No change to sync state.
currently_enabled_ = new_enabled;
if (currently_enabled_) {
// The preference was just enabled. Trigger a reconfiguration. This will do
// nothing if the type isn't preferred.
syncer::SyncService* sync_service = sync_client_->GetSyncService();
sync_service->ReenableDatatype(type());
} else {
DisableForPolicy();
}
}
bool AutofillDataTypeController::IsEnabled() {
DCHECK(CalledOnValidThread());
// Require the user-visible pref to be enabled to sync Autofill data.
PrefService* ps = sync_client_->GetPrefService();
return ps->GetBoolean(autofill::prefs::kAutofillEnabled);
}
void AutofillDataTypeController::DisableForPolicy() {
if (state() != NOT_RUNNING && state() != STOPPING) {
CreateErrorHandler()->OnUnrecoverableError(
syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR,
"Autofill syncing is disabled by policy.", type()));
}
}
} // namespace browser_sync
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_DATA_TYPE_CONTROLLER_H__
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_DATA_TYPE_CONTROLLER_H__
#include <string>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/sync/driver/async_directory_type_controller.h"
namespace autofill {
class AutofillWebDataService;
} // namespace autofill
namespace browser_sync {
// A class that manages the startup and shutdown of autofill sync.
class AutofillDataTypeController : public syncer::AsyncDirectoryTypeController {
public:
// |dump_stack| is called when an unrecoverable error occurs.
AutofillDataTypeController(
scoped_refptr<base::SingleThreadTaskRunner> db_thread,
const base::Closure& dump_stack,
syncer::SyncClient* sync_client,
const scoped_refptr<autofill::AutofillWebDataService>& web_data_service);
~AutofillDataTypeController() override;
protected:
// AsyncDirectoryTypeController implementation.
bool StartModels() override;
bool ReadyForStart() const override;
private:
friend class AutofillDataTypeControllerTest;
FRIEND_TEST_ALL_PREFIXES(AutofillDataTypeControllerTest, StartWDSReady);
FRIEND_TEST_ALL_PREFIXES(AutofillDataTypeControllerTest, StartWDSNotReady);
// Callback once WebDatabase has loaded.
void WebDatabaseLoaded();
// Callback for changes to the autofill pref.
void OnUserPrefChanged();
// Returns true if the pref is set such that autofill sync should be enabled.
bool IsEnabled();
// Report an error (which will stop the datatype asynchronously).
void DisableForPolicy();
// A reference to the AutofillWebDataService for this controller.
scoped_refptr<autofill::AutofillWebDataService> web_data_service_;
// Registrar for listening to kAutofillWEnabled status.
PrefChangeRegistrar pref_registrar_;
// Stores whether we're currently syncing autofill data. This is the last
// value computed by IsEnabled.
bool currently_enabled_;
DISALLOW_COPY_AND_ASSIGN(AutofillDataTypeController);
};
} // namespace browser_sync
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_DATA_TYPE_CONTROLLER_H__
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/webdata/autofill_data_type_controller.h"
#include <memory>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/driver/data_type_controller_mock.h"
#include "components/sync/driver/fake_generic_change_processor.h"
#include "components/sync/driver/fake_sync_client.h"
#include "components/sync/driver/sync_api_component_factory_mock.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/model/fake_syncable_service.h"
#include "components/sync/model/sync_error.h"
#include "testing/gtest/include/gtest/gtest.h"
using autofill::AutofillWebDataService;
namespace browser_sync {
namespace {
// Fake WebDataService implementation that stubs out the database loading.
class FakeWebDataService : public AutofillWebDataService {
public:
FakeWebDataService(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner)
: AutofillWebDataService(ui_task_runner, db_task_runner),
is_database_loaded_(false),
db_loaded_callback_(base::Callback<void(void)>()) {}
// Mark the database as loaded and send out the appropriate notification.
void LoadDatabase() {
is_database_loaded_ = true;
if (!db_loaded_callback_.is_null()) {
db_loaded_callback_.Run();
// Clear the callback here or the WDS and DTC will have refs to each other
// and create a memory leak.
db_loaded_callback_ = base::Callback<void(void)>();
}
}
bool IsDatabaseLoaded() override { return is_database_loaded_; }
void RegisterDBLoadedCallback(
const base::Callback<void(void)>& callback) override {
db_loaded_callback_ = callback;
}
private:
~FakeWebDataService() override {}
bool is_database_loaded_;
base::Callback<void(void)> db_loaded_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeWebDataService);
};
class AutofillDataTypeControllerTest : public testing::Test,
public syncer::FakeSyncClient {
public:
AutofillDataTypeControllerTest()
: syncer::FakeSyncClient(&profile_sync_factory_),
last_type_(syncer::UNSPECIFIED),
weak_ptr_factory_(this) {}
~AutofillDataTypeControllerTest() override {}
void SetUp() override {
prefs_.registry()->RegisterBooleanPref(autofill::prefs::kAutofillEnabled,
true);
web_data_service_ =
new FakeWebDataService(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get());
autofill_dtc_ = std::make_unique<AutofillDataTypeController>(
base::ThreadTaskRunnerHandle::Get(), base::DoNothing(), this,
web_data_service_);
last_type_ = syncer::UNSPECIFIED;
last_error_ = syncer::SyncError();
}
void TearDown() override {
// Make sure WebDataService is shutdown properly on DB thread before we
// destroy it.
// Must be done before we pump the loop.
syncable_service_.StopSyncing(syncer::AUTOFILL);
}
// FakeSyncClient overrides.
PrefService* GetPrefService() override { return &prefs_; }
base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType(
syncer::ModelType type) override {
return syncable_service_.AsWeakPtr();
}
void OnLoadFinished(syncer::ModelType type, const syncer::SyncError& error) {
last_type_ = type;
last_error_ = error;
}
protected:
void SetStartExpectations() {
autofill_dtc_->SetGenericChangeProcessorFactoryForTest(
base::WrapUnique<syncer::GenericChangeProcessorFactory>(
new syncer::FakeGenericChangeProcessorFactory(
std::make_unique<syncer::FakeGenericChangeProcessor>(
syncer::AUTOFILL, this))));
}
void Start() {
autofill_dtc_->LoadModels(
base::Bind(&AutofillDataTypeControllerTest::OnLoadFinished,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
if (autofill_dtc_->state() != syncer::DataTypeController::MODEL_LOADED)
return;
autofill_dtc_->StartAssociating(base::Bind(
&syncer::StartCallbackMock::Run, base::Unretained(&start_callback_)));
base::RunLoop().RunUntilIdle();
}
base::MessageLoop message_loop_;
TestingPrefServiceSimple prefs_;
syncer::StartCallbackMock start_callback_;
syncer::SyncApiComponentFactoryMock profile_sync_factory_;
syncer::FakeSyncableService syncable_service_;
std::unique_ptr<AutofillDataTypeController> autofill_dtc_;
scoped_refptr<FakeWebDataService> web_data_service_;
syncer::ModelType last_type_;
syncer::SyncError last_error_;
base::WeakPtrFactory<AutofillDataTypeControllerTest> weak_ptr_factory_;
};
// Load the WDS's database, then start the Autofill DTC.
TEST_F(AutofillDataTypeControllerTest, StartWDSReady) {
SetStartExpectations();
web_data_service_->LoadDatabase();
EXPECT_CALL(start_callback_,
Run(syncer::DataTypeController::OK, testing::_, testing::_));
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING, autofill_dtc_->state());
Start();
EXPECT_FALSE(last_error_.IsSet());
EXPECT_EQ(syncer::AUTOFILL, last_type_);
EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_dtc_->state());
}
// Start the autofill DTC without the WDS's database loaded, then
// start the DB. The Autofill DTC should be in the MODEL_STARTING
// state until the database in loaded.
TEST_F(AutofillDataTypeControllerTest, StartWDSNotReady) {
SetStartExpectations();
autofill_dtc_->LoadModels(
base::Bind(&AutofillDataTypeControllerTest::OnLoadFinished,
weak_ptr_factory_.GetWeakPtr()));
EXPECT_EQ(syncer::DataTypeController::MODEL_STARTING, autofill_dtc_->state());
web_data_service_->LoadDatabase();
EXPECT_CALL(start_callback_,
Run(syncer::DataTypeController::OK, testing::_, testing::_));
autofill_dtc_->StartAssociating(base::Bind(
&syncer::StartCallbackMock::Run, base::Unretained(&start_callback_)));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(last_error_.IsSet());
EXPECT_EQ(syncer::AUTOFILL, last_type_);
EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_dtc_->state());
}
TEST_F(AutofillDataTypeControllerTest, DatatypeDisabledWhileRunning) {
SetStartExpectations();
web_data_service_->LoadDatabase();
EXPECT_CALL(start_callback_,
Run(syncer::DataTypeController::OK, testing::_, testing::_));
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING, autofill_dtc_->state());
Start();
EXPECT_EQ(syncer::DataTypeController::RUNNING, autofill_dtc_->state());
GetPrefService()->SetBoolean(autofill::prefs::kAutofillEnabled, false);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(last_error_.IsSet());
}
TEST_F(AutofillDataTypeControllerTest, DatatypeDisabledAtStartup) {
SetStartExpectations();
web_data_service_->LoadDatabase();
GetPrefService()->SetBoolean(autofill::prefs::kAutofillEnabled, false);
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING, autofill_dtc_->state());
Start();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(last_error_.IsSet());
}
} // namespace
} // namespace browser_sync
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/autofill/core/browser/autofill_wallet_data_type_controller.h" #include "components/autofill/core/browser/autofill_wallet_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h" #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h" #include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/web_data_model_type_controller.h" #include "components/autofill/core/browser/webdata/web_data_model_type_controller.h"
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_change.h" #include "components/autofill/core/browser/webdata/autofill_change.h"
#include "components/autofill/core/browser/webdata/autofill_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h" #include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_table.h"
......
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