Skip to content

Commit

Permalink
Fix an issue when fetching policy without local cache of token policy.
Browse files Browse the repository at this point in the history
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: Roger Tawa <rogerta@chromium.org>
Reviewed-by: Julian Pastarmov <pastarmovj@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#550684}(cherry picked from commit bcf5d8e)
Reviewed-on: https://chromium-review.googlesource.com/1013342
Reviewed-by: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/branch-heads/3396@{#10}
Cr-Branched-From: 9ef2aa8-refs/heads/master@{#550428}
  • Loading branch information
Owen Min committed Apr 15, 2018
1 parent d6f9bf7 commit 4736c59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 4736c59

Please sign in to comment.