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

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

Issue 5562002: Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge with TOT Created 10 years 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/asynchronous_policy_loader.cc
diff --git a/chrome/browser/policy/asynchronous_policy_loader.cc b/chrome/browser/policy/asynchronous_policy_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea27bb767dfd4e5bbd9021c310d7b858a1305ae7
--- /dev/null
+++ b/chrome/browser/policy/asynchronous_policy_loader.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2010 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/asynchronous_policy_loader.h"
+
+#include "base/message_loop.h"
+#include "base/task.h"
+#include "chrome/browser/browser_thread.h"
+
+namespace policy {
+
+AsynchronousPolicyLoader::AsynchronousPolicyLoader(
+ AsynchronousPolicyProvider::Delegate* delegate)
+ : delegate_(delegate),
+ provider_(NULL),
+ origin_loop_(MessageLoop::current()) {}
+
+void AsynchronousPolicyLoader::Init() {
+ policy_.reset(delegate_->Load());
+}
+
+void AsynchronousPolicyLoader::Stop() {
+ delegate_.reset();
+}
+
+void AsynchronousPolicyLoader::SetProvider(
+ AsynchronousPolicyProvider* provider) {
+ provider_ = provider;
+}
+
+// Manages the life cycle of a new policy map during until it's life cycle is
+// taken over by the policy loader.
+class UpdatePolicyTask : public Task {
+ public:
+ UpdatePolicyTask(scoped_refptr<AsynchronousPolicyLoader> loader,
+ DictionaryValue* new_policy)
+ : loader_(loader),
+ new_policy_(new_policy) {}
+
+ virtual void Run() {
+ loader_->UpdatePolicy(new_policy_.release());
+ }
+
+ private:
+ scoped_refptr<AsynchronousPolicyLoader> loader_;
+ scoped_ptr<DictionaryValue> new_policy_;
+ DISALLOW_COPY_AND_ASSIGN(UpdatePolicyTask);
+};
+
+void AsynchronousPolicyLoader::Reload() {
+ if (delegate_.get()) {
+ DictionaryValue* new_policy = delegate_->Load();
+ PostUpdatePolicyTask(new_policy);
+ }
+}
+
+void AsynchronousPolicyLoader::PostUpdatePolicyTask(
+ DictionaryValue* new_policy) {
+ origin_loop_->PostTask(FROM_HERE, new UpdatePolicyTask(this, new_policy));
+}
+
+void AsynchronousPolicyLoader::UpdatePolicy(DictionaryValue* new_policy_raw) {
+ DCHECK(policy_.get());
+ if (!policy_->Equals(new_policy_raw)) {
+ policy_.reset(new_policy_raw);
+ // TODO(danno): Change the notification between the provider and the
+ // PrefStore into a notification mechanism, removing the need for the
+ // WeakPtr for the provider.
+ if (provider_)
+ provider_->NotifyStoreOfPolicyChange();
+ }
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/policy/asynchronous_policy_loader.h ('k') | chrome/browser/policy/asynchronous_policy_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698