Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Unified Diff: components/policy/core/common/cloud/cloud_policy_service.cc

Issue 751703003: Implemented consumer management unenrollment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dcpm
Patch Set: Rebase. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/cloud/cloud_policy_service.cc
diff --git a/components/policy/core/common/cloud/cloud_policy_service.cc b/components/policy/core/common/cloud/cloud_policy_service.cc
index b09e69d0cc34ec813bffba89d7b12cf3b8da9cde..e79a52534d968b01e613c27a4b1c81686571e44b 100644
--- a/components/policy/core/common/cloud/cloud_policy_service.cc
+++ b/components/policy/core/common/cloud/cloud_policy_service.cc
@@ -5,6 +5,7 @@
#include "components/policy/core/common/cloud/cloud_policy_service.h"
#include "base/callback.h"
+#include "base/logging.h"
#include "policy/proto/device_management_backend.pb.h"
namespace em = enterprise_management;
@@ -20,6 +21,7 @@ CloudPolicyService::CloudPolicyService(const std::string& policy_type,
client_(client),
store_(store),
refresh_state_(REFRESH_NONE),
+ unregister_state_(UNREGISTER_NONE),
initialization_complete_(false) {
client_->AddPolicyTypeToFetch(policy_type_, settings_entity_id_);
client_->AddObserver(this);
@@ -48,8 +50,8 @@ std::string CloudPolicyService::ManagedBy() const {
}
void CloudPolicyService::RefreshPolicy(const RefreshPolicyCallback& callback) {
- // If the client is not registered, bail out.
- if (!client_->is_registered()) {
+ // If the client is not registered or is unregistering, bail out.
+ if (!client_->is_registered() || unregister_state_ != UNREGISTER_NONE) {
callback.Run(false);
return;
}
@@ -60,6 +62,20 @@ void CloudPolicyService::RefreshPolicy(const RefreshPolicyCallback& callback) {
client_->FetchPolicy();
}
+void CloudPolicyService::Unregister(const UnregisterCallback& callback) {
+ // Abort all pending refresh requests.
+ if (refresh_state_ != REFRESH_NONE)
+ RefreshCompleted(false);
+
+ // Abort previous unregister request if any.
+ if (unregister_state_ != UNREGISTER_NONE)
+ UnregisterCompleted(false);
+
+ unregister_callback_ = callback;
+ unregister_state_ = UNREGISTER_PENDING;
+ client_->Unregister();
+}
+
void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
if (client_->status() != DM_STATUS_SUCCESS) {
RefreshCompleted(false);
@@ -78,11 +94,15 @@ void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
}
void CloudPolicyService::OnRegistrationStateChanged(CloudPolicyClient* client) {
+ if (unregister_state_ == UNREGISTER_PENDING)
+ UnregisterCompleted(true);
}
void CloudPolicyService::OnClientError(CloudPolicyClient* client) {
if (refresh_state_ == REFRESH_POLICY_FETCH)
RefreshCompleted(false);
+ if (unregister_state_ == UNREGISTER_PENDING)
+ UnregisterCompleted(false);
}
void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
@@ -152,6 +172,15 @@ void CloudPolicyService::RefreshCompleted(bool success) {
}
}
+void CloudPolicyService::UnregisterCompleted(bool success) {
+ if (!success)
+ LOG(ERROR) << "Unregister request failed.";
+
+ unregister_state_ = UNREGISTER_NONE;
+ unregister_callback_.Run(success);
+ unregister_callback_ = UnregisterCallback(); // Reset.
+}
+
void CloudPolicyService::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}

Powered by Google App Engine
This is Rietveld 408576698