Drop GCMStore account mappings once the account ID is migrated to Gaia ID
This CL removes the account mappings from the GCMStoreImpl during the
migration of the CoreAccountId from email to a Gaia ID. This is required
as the key of account mapping map stored on disk which was based on the
email does not correspond to the account ID once the identity manager
starts using Gaia IDs as the identifiers of an account.
Bug: 1028505
Change-Id: Ie4470d4f36a1fc7e15d488daf1ca5919932fd02b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954020
Reviewed-by: Alex Ilin <[email protected]>
Reviewed-by: David Roger <[email protected]>
Reviewed-by: Peter Beverloo <[email protected]>
Commit-Queue: Mihai Sardarescu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#723384}
diff --git a/components/gcm_driver/fake_gcm_client.cc b/components/gcm_driver/fake_gcm_client.cc
index 3b63d0a..54ee61a8 100644
--- a/components/gcm_driver/fake_gcm_client.cc
+++ b/components/gcm_driver/fake_gcm_client.cc
@@ -73,6 +73,7 @@
void FakeGCMClient::Initialize(
const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::RepeatingCallback<void(
diff --git a/components/gcm_driver/fake_gcm_client.h b/components/gcm_driver/fake_gcm_client.h
index 1e1d6b9..58ffb6b 100644
--- a/components/gcm_driver/fake_gcm_client.h
+++ b/components/gcm_driver/fake_gcm_client.h
@@ -47,6 +47,7 @@
void Initialize(
const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::RepeatingCallback<void(
diff --git a/components/gcm_driver/gcm_client.h b/components/gcm_driver/gcm_client.h
index cc14855..822b904 100644
--- a/components/gcm_driver/gcm_client.h
+++ b/components/gcm_driver/gcm_client.h
@@ -235,6 +235,9 @@
// connection. Must be called on |io_task_runner|.
// |chrome_build_info|: chrome info, i.e., version, channel and etc.
// |store_path|: path to the GCM store.
+ // |remove_account_mappings_with_email_key|: Whether account mappings having
+ // email as account key should be removed while loading. Required
+ // during the migration of account identifier from email to Gaia ID.
// |blocking_task_runner|: for running blocking file tasks.
// |io_task_runner|: for running IO tasks. When provided, it could be a
// wrapper on top of base::ThreadTaskRunnerHandle::Get() to provide power
@@ -248,6 +251,7 @@
virtual void Initialize(
const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::RepeatingCallback<void(
diff --git a/components/gcm_driver/gcm_client_impl.cc b/components/gcm_driver/gcm_client_impl.cc
index 1d67b55..f644b19 100644
--- a/components/gcm_driver/gcm_client_impl.cc
+++ b/components/gcm_driver/gcm_client_impl.cc
@@ -297,6 +297,7 @@
void GCMClientImpl::Initialize(
const ChromeBuildInfo& chrome_build_info,
const base::FilePath& path,
+ bool remove_account_mappings_with_email_key,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::RepeatingCallback<void(
@@ -316,7 +317,8 @@
network_connection_tracker_ = network_connection_tracker;
chrome_build_info_ = chrome_build_info;
gcm_store_.reset(
- new GCMStoreImpl(path, blocking_task_runner, std::move(encryptor)));
+ new GCMStoreImpl(path, remove_account_mappings_with_email_key,
+ blocking_task_runner, std::move(encryptor)));
delegate_ = delegate;
io_task_runner_ = std::move(io_task_runner);
recorder_.SetDelegate(this);
@@ -351,12 +353,10 @@
// Once the loading is completed, the check-in will be initiated.
// If we're in lazy start mode, don't create a new store since none is really
// using GCM functionality yet.
- gcm_store_->Load(
- (start_mode == IMMEDIATE_START) ?
- GCMStore::CREATE_IF_MISSING :
- GCMStore::DO_NOT_CREATE,
- base::Bind(&GCMClientImpl::OnLoadCompleted,
- weak_ptr_factory_.GetWeakPtr()));
+ gcm_store_->Load((start_mode == IMMEDIATE_START) ? GCMStore::CREATE_IF_MISSING
+ : GCMStore::DO_NOT_CREATE,
+ base::Bind(&GCMClientImpl::OnLoadCompleted,
+ weak_ptr_factory_.GetWeakPtr()));
state_ = LOADING;
}
diff --git a/components/gcm_driver/gcm_client_impl.h b/components/gcm_driver/gcm_client_impl.h
index 539a62d..6460f0b6 100644
--- a/components/gcm_driver/gcm_client_impl.h
+++ b/components/gcm_driver/gcm_client_impl.h
@@ -115,6 +115,7 @@
void Initialize(
const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::RepeatingCallback<void(
diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc
index 698f189..153fdf2 100644
--- a/components/gcm_driver/gcm_client_impl_unittest.cc
+++ b/components/gcm_driver/gcm_client_impl_unittest.cc
@@ -594,6 +594,7 @@
chrome_build_info.product_category_for_subtypes = kProductCategoryForSubtypes;
gcm_client_->Initialize(
chrome_build_info, gcm_store_path(),
+ /*remove_account_mappings_with_email_key=*/true,
task_environment_.GetMainThreadTaskRunner(),
base::ThreadTaskRunnerHandle::Get(), base::DoNothing(),
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
diff --git a/components/gcm_driver/gcm_desktop_utils.cc b/components/gcm_driver/gcm_desktop_utils.cc
index 0f730080..e1fd3d0 100644
--- a/components/gcm_driver/gcm_desktop_utils.cc
+++ b/components/gcm_driver/gcm_desktop_utils.cc
@@ -86,6 +86,7 @@
std::unique_ptr<GCMClientFactory> gcm_client_factory,
PrefService* prefs,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
@@ -101,9 +102,9 @@
GetChromeBuildInfo(channel, product_category_for_subtypes),
GetChannelStatusRequestUrl(channel),
syncer::MakeUserAgentForSync(channel), prefs, store_path,
- get_socket_factory_callback, std::move(url_loader_factory),
- network_connection_tracker, ui_task_runner, io_task_runner,
- blocking_task_runner));
+ remove_account_mappings_with_email_key, get_socket_factory_callback,
+ std::move(url_loader_factory), network_connection_tracker, ui_task_runner,
+ io_task_runner, blocking_task_runner));
}
} // namespace gcm
diff --git a/components/gcm_driver/gcm_desktop_utils.h b/components/gcm_driver/gcm_desktop_utils.h
index a438caff0a..efcbf151 100644
--- a/components/gcm_driver/gcm_desktop_utils.h
+++ b/components/gcm_driver/gcm_desktop_utils.h
@@ -32,6 +32,7 @@
std::unique_ptr<GCMClientFactory> gcm_client_factory,
PrefService* prefs,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc
index 365eb88..cfb7db8 100644
--- a/components/gcm_driver/gcm_driver_desktop.cc
+++ b/components/gcm_driver/gcm_driver_desktop.cc
@@ -72,6 +72,7 @@
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
@@ -148,6 +149,7 @@
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
@@ -163,10 +165,11 @@
network::SharedURLLoaderFactory::Create(
std::move(pending_loader_factory));
- gcm_client_->Initialize(chrome_build_info, store_path, blocking_task_runner,
- io_thread_, std::move(get_socket_factory_callback),
- url_loader_factory_for_io, network_connection_tracker,
- std::make_unique<SystemEncryptor>(), this);
+ gcm_client_->Initialize(
+ chrome_build_info, store_path, remove_account_mappings_with_email_key,
+ blocking_task_runner, io_thread_, std::move(get_socket_factory_callback),
+ url_loader_factory_for_io, network_connection_tracker,
+ std::make_unique<SystemEncryptor>(), this);
}
void GCMDriverDesktop::IOWorker::OnRegisterFinished(
@@ -515,6 +518,7 @@
const std::string& user_agent,
PrefService* prefs,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
@@ -552,7 +556,8 @@
base::BindOnce(
&GCMDriverDesktop::IOWorker::Initialize,
base::Unretained(io_worker_.get()), std::move(gcm_client_factory),
- chrome_build_info, store_path, std::move(get_socket_factory_callback),
+ chrome_build_info, store_path, remove_account_mappings_with_email_key,
+ std::move(get_socket_factory_callback),
// ->Clone() permits creation of an equivalent
// SharedURLLoaderFactory on IO thread.
url_loader_factory_for_ui->Clone(),
diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h
index 6b8d681..cba92bd 100644
--- a/components/gcm_driver/gcm_driver_desktop.h
+++ b/components/gcm_driver/gcm_driver_desktop.h
@@ -49,6 +49,9 @@
class GCMDriverDesktop : public GCMDriver,
protected InstanceIDHandler {
public:
+ // |remove_account_mappings_with_email_key| indicates whether account mappings
+ // having email as account key should be removed while loading. This is
+ // required during the migration of account identifier from email to Gaia ID.
GCMDriverDesktop(
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
@@ -56,6 +59,7 @@
const std::string& user_agent,
PrefService* prefs,
const base::FilePath& store_path,
+ bool remove_account_mappings_with_email_key,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
diff --git a/components/gcm_driver/gcm_driver_desktop_unittest.cc b/components/gcm_driver/gcm_driver_desktop_unittest.cc
index 8320726..9d3982ff 100644
--- a/components/gcm_driver/gcm_driver_desktop_unittest.cc
+++ b/components/gcm_driver/gcm_driver_desktop_unittest.cc
@@ -250,7 +250,8 @@
std::unique_ptr<GCMClientFactory>(new FakeGCMClientFactory(
base::ThreadTaskRunnerHandle::Get(), io_thread_.task_runner())),
chrome_build_info, kTestChannelStatusRequestURL, "user-agent-string",
- &prefs_, temp_dir_.GetPath(), base::DoNothing(),
+ &prefs_, temp_dir_.GetPath(),
+ /*remove_account_mappings_with_email_key=*/true, base::DoNothing(),
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_),
network::TestNetworkConnectionTracker::GetInstance(),
diff --git a/components/gcm_driver/gcm_driver_unittest.cc b/components/gcm_driver/gcm_driver_unittest.cc
index 1bbde7d..9061c91 100644
--- a/components/gcm_driver/gcm_driver_unittest.cc
+++ b/components/gcm_driver/gcm_driver_unittest.cc
@@ -171,7 +171,8 @@
std::make_unique<FakeGCMClientFactory>(
base::ThreadTaskRunnerHandle::Get(), io_thread_.task_runner()),
chrome_build_info, kTestChannelStatusRequestURL, "user-agent-string",
- &prefs_, temp_dir_.GetPath(), base::DoNothing(),
+ &prefs_, temp_dir_.GetPath(),
+ /*remove_account_mappings_with_email_key=*/true, base::DoNothing(),
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_),
network::TestNetworkConnectionTracker::GetInstance(),
diff --git a/components/gcm_driver/gcm_profile_service.cc b/components/gcm_driver/gcm_profile_service.cc
index 25b087d..6bbf0e8 100644
--- a/components/gcm_driver/gcm_profile_service.cc
+++ b/components/gcm_driver/gcm_profile_service.cc
@@ -159,9 +159,15 @@
scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
: identity_manager_(identity_manager),
url_loader_factory_(std::move(url_loader_factory)) {
+ signin::IdentityManager::AccountIdMigrationState id_migration =
+ identity_manager_->GetAccountIdMigrationState();
+ bool remove_account_mappings_with_email_key =
+ (id_migration == signin::IdentityManager::MIGRATION_IN_PROGRESS) ||
+ (id_migration == signin::IdentityManager::MIGRATION_DONE);
driver_ = CreateGCMDriverDesktop(
std::move(gcm_client_factory), prefs,
path.Append(gcm_driver::kGCMStoreDirname),
+ remove_account_mappings_with_email_key,
base::BindRepeating(get_socket_factory_callback,
weak_ptr_factory_.GetWeakPtr()),
url_loader_factory_, network_connection_tracker, channel,