Commit bcf5d8ef authored by Owen Min's avatar Owen Min Committed by Commit Bot

Fix an issue when fetching policy without local cache of token policy.

Because the first policy cache will be loaded synchronously before local_state
creation. We'll miss its OnStoreLoaded/Error event as CloudPolicyService
has to be created after |local_state|. It means we won't know the result of
cache loading.

To resolve this, check the initialization status once the CloudPolicyService
has been created. Fetch policy from server if cache is not loaded properly.

Bug: 832694
Change-Id: Idd0b9e35ea2afded586b73c765197b5574ba3900
Reviewed-on: https://chromium-review.googlesource.com/1011211
Commit-Queue: Owen Min <zmin@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550684}
parent 86738ed0
......@@ -117,10 +117,7 @@ void MachineLevelUserCloudPolicyFetcher::OnInitializationCompleted(
// Note that Chrome will not fetch policy again immediately here if DM server
// returns a policy that Chrome is not able to validate.
if (!policy_manager_->IsClientRegistered()) {
std::string dm_token = BrowserDMTokenStorage::Get()->RetrieveDMToken();
std::string client_id = BrowserDMTokenStorage::Get()->RetrieveClientId();
if (!dm_token.empty() && !client_id.empty())
SetupRegistrationAndFetchPolicy(dm_token, client_id);
TryToFetchPolicy();
}
}
......@@ -129,6 +126,21 @@ void MachineLevelUserCloudPolicyFetcher::InitializeManager(
policy_manager_->Connect(local_state_, system_request_context_,
std::move(client));
policy_manager_->core()->service()->AddObserver(this);
// If CloudPolicyStore is already initialized then |OnInitializationCompleted|
// has already fired. Fetch policy if CloudPolicyClient hasn't been registered
// which means there is no valid policy cache.
if (policy_manager_->store()->is_initialized() &&
!policy_manager_->IsClientRegistered()) {
TryToFetchPolicy();
}
}
void MachineLevelUserCloudPolicyFetcher::TryToFetchPolicy() {
std::string dm_token = BrowserDMTokenStorage::Get()->RetrieveDMToken();
std::string client_id = BrowserDMTokenStorage::Get()->RetrieveClientId();
if (!dm_token.empty() && !client_id.empty())
SetupRegistrationAndFetchPolicy(dm_token, client_id);
}
} // namespace policy
......@@ -77,6 +77,8 @@ class MachineLevelUserCloudPolicyFetcher : public CloudPolicyService::Observer {
private:
void InitializeManager(std::unique_ptr<CloudPolicyClient> client);
// Fetch policy if device is enrolled.
void TryToFetchPolicy();
MachineLevelUserCloudPolicyManager* policy_manager_;
PrefService* local_state_;
......
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