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

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: Created 6 years, 1 month 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 f54756317d12405260bee4e0fba938c211ba2519..7cfecee3b74148531518c63efd8070d0e92ad338 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;
@@ -18,6 +19,7 @@ CloudPolicyService::CloudPolicyService(const PolicyNamespaceKey& policy_ns_key,
client_(client),
store_(store),
refresh_state_(REFRESH_NONE),
+ unregister_state_(UNREGISTER_NONE),
initialization_complete_(false) {
client_->AddNamespaceToFetch(policy_ns_key_);
client_->AddObserver(this);
@@ -46,8 +48,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;
}
@@ -58,6 +60,17 @@ 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);
+ }
+
+ unregister_callback_ = callback;
bartfab (slow) 2014/11/28 13:25:18 What if there already is an unregistration in prog
davidyu 2014/12/01 17:05:23 Done.
+ unregister_state_ = UNREGISTER_PENDING;
+ client_->Unregister();
+}
+
void CloudPolicyService::OnPolicyFetched(CloudPolicyClient* client) {
if (client_->status() != DM_STATUS_SUCCESS) {
RefreshCompleted(false);
@@ -75,11 +88,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) {
@@ -149,6 +166,14 @@ 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);
bartfab (slow) 2014/11/28 13:25:18 Nit: Reset the callback after running it. This wil
davidyu 2014/12/01 17:05:23 Done.
+}
+
void CloudPolicyService::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}

Powered by Google App Engine
This is Rietveld 408576698