Commit 6d4c95c1 authored by Pavol Marko's avatar Pavol Marko Committed by Commit Bot

Add timeout for blocking primary profile init on proxied policies

Blocking primary profile initialization on primary profile policies
having propagated to the device-wide PolicyService now has a timeout.
In case something goes wrong, chrome should never hang.
In a follow-up, UMA stat for the latency introduced by this will be
added.

Bug: 982936, 1002066
Test: unit_tests --gtest_filter=*ProfilePolicyConnector*
Change-Id: Ibd2bf56ffa5d9f1e2f602fea2d6ce4733cce0027
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808869
Commit-Queue: Pavol Marko <pmarko@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701363}
parent 0270befd
......@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
......@@ -60,6 +61,13 @@ class ProxiedPoliciesPropagatedWatcher : PolicyService::ProviderUpdateObserver {
proxied_policies_propagated_callback_(
std::move(proxied_policies_propagated_callback)) {
device_wide_policy_service->AddProviderUpdateObserver(this);
timeout_timer_.Start(
FROM_HERE,
base::TimeDelta::FromSeconds(
kProxiedPoliciesPropagationTimeoutInSeconds),
this,
&ProxiedPoliciesPropagatedWatcher::OnProviderUpdatePropagationTimedOut);
}
~ProxiedPoliciesPropagatedWatcher() override {
......@@ -82,11 +90,21 @@ class ProxiedPoliciesPropagatedWatcher : PolicyService::ProviderUpdateObserver {
std::move(proxied_policies_propagated_callback_).Run();
}
void OnProviderUpdatePropagationTimedOut() {
if (!proxied_policies_propagated_callback_)
return;
LOG(WARNING) << "Waiting for proxied policies to propagate timed out.";
std::move(proxied_policies_propagated_callback_).Run();
}
private:
static constexpr int kProxiedPoliciesPropagationTimeoutInSeconds = 5;
PolicyService* const device_wide_policy_service_;
const ProxyPolicyProvider* const proxy_policy_provider_;
const ConfigurationPolicyProvider* const source_policy_provider_;
base::OnceClosure proxied_policies_propagated_callback_;
base::OneShotTimer timeout_timer_;
DISALLOW_COPY_AND_ASSIGN(ProxiedPoliciesPropagatedWatcher);
};
......@@ -268,6 +286,13 @@ bool ProfilePolicyConnector::IsProfilePolicy(const char* policy_key) const {
return provider == configuration_policy_provider_;
}
#if defined(OS_CHROMEOS)
void ProfilePolicyConnector::TriggerProxiedPoliciesWaitTimeoutForTesting() {
CHECK(proxied_policies_propagated_watcher_);
proxied_policies_propagated_watcher_->OnProviderUpdatePropagationTimedOut();
}
#endif // defined(OS_CHROMEOS)
const CloudPolicyStore* ProfilePolicyConnector::GetActualPolicyStore() const {
if (policy_store_)
return policy_store_;
......
......@@ -72,6 +72,12 @@ class ProfilePolicyConnector final {
// higher-level provider.
bool IsProfilePolicy(const char* policy_key) const;
#if defined(OS_CHROMEOS)
// Triggers the time out handling of waiting for the proxied primary user
// policies to propagate. May be only called form tests.
void TriggerProxiedPoliciesWaitTimeoutForTesting();
#endif // defined(OS_CHROMEOS)
private:
// Returns the policy store which is actually used.
const CloudPolicyStore* GetActualPolicyStore() const;
......
......@@ -56,6 +56,9 @@ void ProxyPolicyProvider::RefreshPolicies() {
void ProxyPolicyProvider::OnUpdatePolicy(
ConfigurationPolicyProvider* provider) {
if (block_policy_updates_for_testing_)
return;
DCHECK_EQ(delegate_, provider);
std::unique_ptr<PolicyBundle> bundle(new PolicyBundle());
bundle->CopyFrom(delegate_->policies());
......
......@@ -53,8 +53,15 @@ class POLICY_EXPORT ProxyPolicyProvider
// ConfigurationPolicyProvider::Observer:
void OnUpdatePolicy(ConfigurationPolicyProvider* provider) override;
// When set to true, this ProxyPolicyProvider will ignore subsequent policy
// updates.
void SetBlockPolicyUpdatesForTesting(bool block_policy_updates_for_testing) {
block_policy_updates_for_testing_ = block_policy_updates_for_testing;
}
private:
ConfigurationPolicyProvider* delegate_;
bool block_policy_updates_for_testing_ = false;
DISALLOW_COPY_AND_ASSIGN(ProxyPolicyProvider);
};
......
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