Skip to content

Commit cdfe984

Browse files
Owen Minchromeos-ci-prod
authored andcommitted
Try to eliminate unknown policy fetch reason
We have lots of policy fetch with "Unspecified" reason on desktop and mobile platforms. The main reason is CBCM policy provider tracks schema change unnecessarily. Because we always download all component policies. And component_policy_service also listen to schema update and filter out unused ones locally. Hence there is no reason to refresh policy because of that. Also added a few new reasons that technically shouldn't trigger policy fetch request for future debugging purpose. Bug: b/369420289 Change-Id: Id8344ac4bd333969fccbeb7ea9c88fec9f657c8e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5891932 Commit-Queue: Owen Min <[email protected]> Reviewed-by: Yann Dago <[email protected]> Cr-Commit-Position: refs/heads/main@{#1363106} CrOS-Libchrome-Original-Commit: 5a57d06fdce53a37169d136ed2152ea03210ec9a
1 parent edb837a commit cdfe984

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

components/policy/core/common/command_line_policy_provider.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool CommandLinePolicyProvider::IsFirstPolicyLoadComplete(
6161
CommandLinePolicyProvider::CommandLinePolicyProvider(
6262
const base::CommandLine& command_line)
6363
: loader_(command_line) {
64-
RefreshPolicies(PolicyFetchReason::kUnspecified);
64+
RefreshPolicies(PolicyFetchReason::kBrowserStart);
6565
}
6666

6767
} // namespace policy

components/policy/core/common/policy_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ enum class PolicyFetchReason {
154154
kUserRequest,
155155
// Policy fetch as previous request failed.
156156
kRetry,
157+
// Schema Update
158+
kSchemaUpdated,
159+
// Disconnect from cloud management
160+
kDisconnect,
157161
};
158162

159163
} // namespace policy

components/policy/core/common/schema_registry_tracking_policy_provider.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "components/policy/core/common/policy_types.h"
1010
#include "components/policy/core/common/schema_map.h"
1111
#include "components/policy/core/common/schema_registry.h"
12+
#include "policy_types.h"
1213

1314
namespace policy {
1415

@@ -68,15 +69,15 @@ void SchemaRegistryTrackingPolicyProvider::OnSchemaRegistryReady() {
6869
}
6970

7071
state_ = WAITING_FOR_REFRESH;
71-
RefreshPolicies(PolicyFetchReason::kUnspecified);
72+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated);
7273
}
7374

7475
void SchemaRegistryTrackingPolicyProvider::OnSchemaRegistryUpdated(
7576
bool has_new_schemas) {
7677
if (state_ != READY)
7778
return;
7879
if (has_new_schemas) {
79-
RefreshPolicies(PolicyFetchReason::kUnspecified);
80+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated);
8081
} else {
8182
// Remove the policies that were being served for the component that have
8283
// been removed. This is important so that update notifications are also

components/policy/core/common/schema_registry_tracking_policy_provider_unittest.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ TEST_F(SchemaRegistryTrackingPolicyProviderTest, SchemaReadyWithComponents) {
132132
mock_provider_.UpdatePolicy(std::move(bundle));
133133
Mock::VerifyAndClearExpectations(&observer_);
134134

135-
EXPECT_CALL(mock_provider_, RefreshPolicies(PolicyFetchReason::kUnspecified))
135+
EXPECT_CALL(mock_provider_,
136+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated))
136137
.Times(0);
137138
schema_registry_.RegisterComponent(
138139
PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), CreateTestSchema());
139140
schema_registry_.SetExtensionsDomainsReady();
140141
Mock::VerifyAndClearExpectations(&mock_provider_);
141142

142-
EXPECT_CALL(mock_provider_, RefreshPolicies(PolicyFetchReason::kUnspecified));
143+
EXPECT_CALL(mock_provider_,
144+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated));
143145
schema_registry_.SetDomainReady(POLICY_DOMAIN_CHROME);
144146
Mock::VerifyAndClearExpectations(&mock_provider_);
145147

@@ -178,7 +180,8 @@ TEST_F(SchemaRegistryTrackingPolicyProviderTest, DelegateUpdates) {
178180
mock_provider_.UpdateChromePolicy(policy_map);
179181
Mock::VerifyAndClearExpectations(&observer_);
180182

181-
EXPECT_CALL(mock_provider_, RefreshPolicies(PolicyFetchReason::kUnspecified));
183+
EXPECT_CALL(mock_provider_,
184+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated));
182185
schema_registry_.SetAllDomainsReady();
183186
EXPECT_TRUE(schema_registry_.IsReady());
184187
Mock::VerifyAndClearExpectations(&mock_provider_);
@@ -201,7 +204,8 @@ TEST_F(SchemaRegistryTrackingPolicyProviderTest, DelegateUpdates) {
201204
}
202205

203206
TEST_F(SchemaRegistryTrackingPolicyProviderTest, RemoveAndAddComponent) {
204-
EXPECT_CALL(mock_provider_, RefreshPolicies(PolicyFetchReason::kUnspecified));
207+
EXPECT_CALL(mock_provider_,
208+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated));
205209
const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, "xyz");
206210
schema_registry_.RegisterComponent(ns, CreateTestSchema());
207211
schema_registry_.SetAllDomainsReady();
@@ -227,7 +231,8 @@ TEST_F(SchemaRegistryTrackingPolicyProviderTest, RemoveAndAddComponent) {
227231

228232
// Adding it back should serve the current policies again, even though they
229233
// haven't changed on the platform provider.
230-
EXPECT_CALL(mock_provider_, RefreshPolicies(PolicyFetchReason::kUnspecified));
234+
EXPECT_CALL(mock_provider_,
235+
RefreshPolicies(PolicyFetchReason::kSchemaUpdated));
231236
schema_registry_.RegisterComponent(ns, CreateTestSchema());
232237
Mock::VerifyAndClearExpectations(&mock_provider_);
233238

0 commit comments

Comments
 (0)