Commit 9e97e293 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[CryptAuth] Add IsListening() method to GCM manager

The method returns true if the CryptAuth app handler has been added to
the GCM driver. This is particularly important to know when fetching
Instance ID data (see crbug.com/1006280). Child CLs will utilize this
method to confirm that the manager is listening before registering with
GCM or fetching Instance IDs.

---

This is ClientAppMetadata change-detection CL [1/4]:

This chain of CLs relates to the end goal of re-enrolling if
ClientAppMetadata has changed since the last successful enrollment. For
example, when Phone Hub become supported, we will want to re-enroll.

We were previously only fetching ClientAppMetadata on demand, for
instance, right before a periodic enrollment. Now, we need to fetch the
data every time the service starts up to see if it changed. We continue
to make the assumption that the data will not change during a user
session.

Bug: 1105703
Change-Id: Ifb08bc479b96e0ace0f85d27041a8259b9b29967
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2319327Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Josh Nohle <nohle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792408}
parent 4fb12627
......@@ -62,6 +62,9 @@ class CryptAuthGCMManager {
// after this function is called, then messages will also be handled properly.
virtual void StartListening() = 0;
// Returns true after StartListening() is called.
virtual bool IsListening() = 0;
// Begins registration with GCM. The Observer::OnGCMRegistrationResult()
// observer function will be called when registration completes.
virtual void RegisterWithGCM() = 0;
......
......@@ -230,12 +230,12 @@ CryptAuthGCMManagerImpl::CryptAuthGCMManagerImpl(gcm::GCMDriver* gcm_driver,
registration_in_progress_(false) {}
CryptAuthGCMManagerImpl::~CryptAuthGCMManagerImpl() {
if (gcm_driver_->GetAppHandler(kCryptAuthGcmAppId) == this)
if (IsListening())
gcm_driver_->RemoveAppHandler(kCryptAuthGcmAppId);
}
void CryptAuthGCMManagerImpl::StartListening() {
if (gcm_driver_->GetAppHandler(kCryptAuthGcmAppId) == this) {
if (IsListening()) {
PA_LOG(VERBOSE) << "GCM app handler already added";
return;
}
......@@ -243,6 +243,10 @@ void CryptAuthGCMManagerImpl::StartListening() {
gcm_driver_->AddAppHandler(kCryptAuthGcmAppId, this);
}
bool CryptAuthGCMManagerImpl::IsListening() {
return gcm_driver_->GetAppHandler(kCryptAuthGcmAppId) == this;
}
void CryptAuthGCMManagerImpl::RegisterWithGCM() {
if (registration_in_progress_) {
PA_LOG(VERBOSE) << "GCM Registration is already in progress";
......
......@@ -50,6 +50,7 @@ class CryptAuthGCMManagerImpl : public CryptAuthGCMManager,
// CryptAuthGCMManager:
void StartListening() override;
bool IsListening() override;
void RegisterWithGCM() override;
std::string GetRegistrationId() override;
void AddObserver(Observer* observer) override;
......
......@@ -912,8 +912,7 @@ class DeviceSyncServiceTest
void FinishInitialization() {
// CryptAuth classes are expected to be created and initialized.
EXPECT_TRUE(fake_cryptauth_gcm_manager_factory_->instance()
->has_started_listening());
EXPECT_TRUE(fake_cryptauth_gcm_manager_factory_->instance()->IsListening());
EXPECT_TRUE(fake_cryptauth_enrollment_manager()->has_started());
// If the device was already enrolled in CryptAuth, initialization should
......
......@@ -15,7 +15,11 @@ FakeCryptAuthGCMManager::FakeCryptAuthGCMManager(
FakeCryptAuthGCMManager::~FakeCryptAuthGCMManager() = default;
void FakeCryptAuthGCMManager::StartListening() {
has_started_listening_ = true;
is_listening_ = true;
}
bool FakeCryptAuthGCMManager::IsListening() {
return is_listening_;
}
void FakeCryptAuthGCMManager::RegisterWithGCM() {
......
......@@ -27,7 +27,6 @@ class FakeCryptAuthGCMManager : public CryptAuthGCMManager {
explicit FakeCryptAuthGCMManager(const std::string& registration_id);
~FakeCryptAuthGCMManager() override;
bool has_started_listening() { return has_started_listening_; }
bool registration_in_progress() { return registration_in_progress_; }
void set_registration_id(const std::string& registration_id) {
......@@ -52,13 +51,14 @@ class FakeCryptAuthGCMManager : public CryptAuthGCMManager {
// CryptAuthGCMManager:
void StartListening() override;
bool IsListening() override;
void RegisterWithGCM() override;
std::string GetRegistrationId() override;
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
private:
bool has_started_listening_ = false;
bool is_listening_ = false;
bool registration_in_progress_ = false;
// The registration id obtained from the last successful registration.
......
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