Commit a5b45b4c authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Add seq checks into CloudPolicyService

Add sequence checks that prevent incorrect (cross-thread)
usage of CloudPolicyService.

Bug: 727645
Change-Id: I41718cb9117e8e7acd03302416f585e398d6009a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214551
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772006}
parent 2d46a1f7
...@@ -38,12 +38,16 @@ CloudPolicyService::CloudPolicyService(const std::string& policy_type, ...@@ -38,12 +38,16 @@ CloudPolicyService::CloudPolicyService(const std::string& policy_type,
} }
CloudPolicyService::~CloudPolicyService() { CloudPolicyService::~CloudPolicyService() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
client_->RemovePolicyTypeToFetch(policy_type_, settings_entity_id_); client_->RemovePolicyTypeToFetch(policy_type_, settings_entity_id_);
client_->RemoveObserver(this); client_->RemoveObserver(this);
store_->RemoveObserver(this); store_->RemoveObserver(this);
} }
void CloudPolicyService::RefreshPolicy(RefreshPolicyCallback callback) { void CloudPolicyService::RefreshPolicy(RefreshPolicyCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// If the client is not registered or is unregistering, bail out. // If the client is not registered or is unregistering, bail out.
if (!client_->is_registered() || unregister_state_ != UNREGISTER_NONE) { if (!client_->is_registered() || unregister_state_ != UNREGISTER_NONE) {
std::move(callback).Run(false); std::move(callback).Run(false);
...@@ -57,6 +61,8 @@ void CloudPolicyService::RefreshPolicy(RefreshPolicyCallback callback) { ...@@ -57,6 +61,8 @@ void CloudPolicyService::RefreshPolicy(RefreshPolicyCallback callback) {
} }
void CloudPolicyService::Unregister(UnregisterCallback callback) { void CloudPolicyService::Unregister(UnregisterCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Abort all pending refresh requests. // Abort all pending refresh requests.
if (refresh_state_ != REFRESH_NONE) if (refresh_state_ != REFRESH_NONE)
RefreshCompleted(false); RefreshCompleted(false);
...@@ -71,6 +77,8 @@ void CloudPolicyService::Unregister(UnregisterCallback callback) { ...@@ -71,6 +77,8 @@ void CloudPolicyService::Unregister(UnregisterCallback callback) {
} }
void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) { void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (client_->status() != DM_STATUS_SUCCESS) { if (client_->status() != DM_STATUS_SUCCESS) {
RefreshCompleted(false); RefreshCompleted(false);
return; return;
...@@ -89,11 +97,15 @@ void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) { ...@@ -89,11 +97,15 @@ void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
} }
void CloudPolicyService::OnRegistrationStateChanged(CloudPolicyClient* client) { void CloudPolicyService::OnRegistrationStateChanged(CloudPolicyClient* client) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (unregister_state_ == UNREGISTER_PENDING) if (unregister_state_ == UNREGISTER_PENDING)
UnregisterCompleted(true); UnregisterCompleted(true);
} }
void CloudPolicyService::OnClientError(CloudPolicyClient* client) { void CloudPolicyService::OnClientError(CloudPolicyClient* client) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (refresh_state_ == REFRESH_POLICY_FETCH) if (refresh_state_ == REFRESH_POLICY_FETCH)
RefreshCompleted(false); RefreshCompleted(false);
if (unregister_state_ == UNREGISTER_PENDING) if (unregister_state_ == UNREGISTER_PENDING)
...@@ -101,6 +113,8 @@ void CloudPolicyService::OnClientError(CloudPolicyClient* client) { ...@@ -101,6 +113,8 @@ void CloudPolicyService::OnClientError(CloudPolicyClient* client) {
} }
void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) { void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Update the client with state from the store. // Update the client with state from the store.
const em::PolicyData* policy(store_->policy()); const em::PolicyData* policy(store_->policy());
...@@ -155,6 +169,8 @@ void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) { ...@@ -155,6 +169,8 @@ void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
} }
void CloudPolicyService::OnStoreError(CloudPolicyStore* store) { void CloudPolicyService::OnStoreError(CloudPolicyStore* store) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (refresh_state_ == REFRESH_POLICY_STORE) if (refresh_state_ == REFRESH_POLICY_STORE)
RefreshCompleted(false); RefreshCompleted(false);
CheckInitializationCompleted(); CheckInitializationCompleted();
...@@ -162,6 +178,8 @@ void CloudPolicyService::OnStoreError(CloudPolicyStore* store) { ...@@ -162,6 +178,8 @@ void CloudPolicyService::OnStoreError(CloudPolicyStore* store) {
} }
void CloudPolicyService::ReportValidationResult(CloudPolicyStore* store) { void CloudPolicyService::ReportValidationResult(CloudPolicyStore* store) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const CloudPolicyValidatorBase::ValidationResult* validation_result = const CloudPolicyValidatorBase::ValidationResult* validation_result =
store->validation_result(); store->validation_result();
if (!validation_result) if (!validation_result)
...@@ -241,10 +259,14 @@ void CloudPolicyService::UnregisterCompleted(bool success) { ...@@ -241,10 +259,14 @@ void CloudPolicyService::UnregisterCompleted(bool success) {
} }
void CloudPolicyService::AddObserver(Observer* observer) { void CloudPolicyService::AddObserver(Observer* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
void CloudPolicyService::RemoveObserver(Observer* observer) { void CloudPolicyService::RemoveObserver(Observer* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/sequence_checker.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h" #include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_store.h" #include "components/policy/core/common/cloud/cloud_policy_store.h"
#include "components/policy/policy_export.h" #include "components/policy/policy_export.h"
...@@ -78,12 +79,16 @@ class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, ...@@ -78,12 +79,16 @@ class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer,
void ReportValidationResult(CloudPolicyStore* store); void ReportValidationResult(CloudPolicyStore* store);
bool IsInitializationComplete() const { return initialization_complete_; } bool IsInitializationComplete() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return initialization_complete_;
}
// If initial policy refresh was completed returns its result. // If initial policy refresh was completed returns its result.
// This allows ChildPolicyObserver to know whether policy was fetched before // This allows ChildPolicyObserver to know whether policy was fetched before
// profile creation. // profile creation.
base::Optional<bool> initial_policy_refresh_result() const { base::Optional<bool> initial_policy_refresh_result() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return initial_policy_refresh_result_; return initial_policy_refresh_result_;
} }
...@@ -100,6 +105,9 @@ class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, ...@@ -100,6 +105,9 @@ class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer,
// flag is passed through to the unregister callback. // flag is passed through to the unregister callback.
void UnregisterCompleted(bool success); void UnregisterCompleted(bool success);
// Assert non-concurrent usage in debug builds.
SEQUENCE_CHECKER(sequence_checker_);
// The policy type that will be fetched by the |client_|, with the optional // The policy type that will be fetched by the |client_|, with the optional
// |settings_entity_id_|. // |settings_entity_id_|.
std::string policy_type_; std::string policy_type_;
......
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