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

Unified Diff: chrome/browser/policy/user_cloud_policy_store.cc

Issue 10693022: Add support for loading user cloud policy on desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaked some comments after self-review. Created 8 years, 5 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: chrome/browser/policy/user_cloud_policy_store.cc
diff --git a/chrome/browser/policy/user_cloud_policy_store.cc b/chrome/browser/policy/user_cloud_policy_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9817828acf22f3efc308df7eb13308945f38c3d0
--- /dev/null
+++ b/chrome/browser/policy/user_cloud_policy_store.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/policy/user_cloud_policy_store.h"
+
+#include "base/bind.h"
+#include "chrome/browser/policy/proto/cloud_policy.pb.h"
+#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+
+using enterprise_management::PolicyData;
+
+namespace policy {
+
+UserCloudPolicyStore::UserCloudPolicyStore(Profile* profile)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ profile_(profile) {
+}
+
+UserCloudPolicyStore::~UserCloudPolicyStore() {
+}
+
+void UserCloudPolicyStore::Load() {
+ // TODO(atwilson): Read policy from file.
+ policy_.reset();
+ policy_map_.Clear();
+ NotifyStoreLoaded();
+}
+
+void UserCloudPolicyStore::Store(
+ const enterprise_management::PolicyFetchResponse& policy) {
+ // Stop any pending requests to store policy, then validate the new policy
+ // before storing it.
+ weak_factory_.InvalidateWeakPtrs();
+ scoped_ptr<enterprise_management::PolicyFetchResponse> policy_copy(
+ new enterprise_management::PolicyFetchResponse(policy));
+ Validate(policy_copy.Pass(),
+ base::Bind(&UserCloudPolicyStore::StorePolicyAfterValidation,
+ weak_factory_.GetWeakPtr()));
+}
+
+void UserCloudPolicyStore::Validate(
+ scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
+ const UserCloudPolicyValidator::CompletionCallback& callback) {
+ // Configure the validator.
+ scoped_ptr<UserCloudPolicyValidator> validator =
+ CreateValidator(policy.Pass(), callback);
+ SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
+ std::string username = signin->GetAuthenticatedUsername();
+ DCHECK(!username.empty());
+ validator->ValidateUsername(username);
+
+ // Start validation. The Validator will free itself once validation is
+ // complete.
+ validator.release()->StartValidation();
+}
+
+void UserCloudPolicyStore::StorePolicyAfterValidation(
+ UserCloudPolicyValidator* validator) {
+ validation_status_ = validator->status();
+ if (!validator->success()) {
+ status_ = STATUS_VALIDATION_ERROR;
+ NotifyStoreError();
+ return;
+ }
+ // TODO(atwilson): Write policy to file.
+ InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass());
+ status_ = STATUS_OK;
+ NotifyStoreLoaded();
+}
+
+// static
+scoped_ptr<CloudPolicyStore> CloudPolicyStore::CreateUserPolicyStore(
+ Profile* profile) {
+ return scoped_ptr<CloudPolicyStore>(new UserCloudPolicyStore(profile));
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698