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

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

Issue 5562002: Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback 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.h
diff --git a/chrome/browser/policy/asynchronous_policy_loader.h b/chrome/browser/policy/asynchronous_policy_loader.h
new file mode 100644
index 0000000000000000000000000000000000000000..a7731146b200b07dfd75850ca93a64e64462cf3d
--- /dev/null
+++ b/chrome/browser/policy/asynchronous_policy_loader.h
@@ -0,0 +1,86 @@
+// 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.
+
+#ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_
+#define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_
+#pragma once
+
+#include "base/ref_counted.h"
+#include "base/values.h"
+#include "chrome/browser/policy/asynchronous_policy_provider.h"
+
+namespace policy {
+
+class ConfigurationPolicyProvider;
+
+// Used by the implementation of asynchronous policy provider to managed the
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 to manage
danno 2010/12/06 14:05:12 Done.
+// tasks on the file thread that do the heavy lifting of loading policies on the
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 "on the file thread" twice?
danno 2010/12/06 14:05:12 Done.
+// file thread.
+class AsynchronousPolicyLoader
+ : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> {
+ public:
+ explicit AsynchronousPolicyLoader(
+ AsynchronousPolicyProvider::Delegate* delegate);
+
+ // Triggers initial policy load and schedules fallback reload.
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 In the base implementation, it doesn't schedule fa
danno 2010/12/06 14:05:12 Done.
+ virtual void Init();
+
+ // Reloads policy, sending notification of changes if necessary. Must be
+ // called on the file thread.
+ virtual void Reload();
+
+ // Stops any pending reload tasks.
+ virtual void Stop();
+
+ // Associates a provider with the loader to allow the loader to notify the
+ // provider when policy changes.
+ void SetProvider(base::WeakPtr<AsynchronousPolicyProvider> provider);
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 If there is SetProvider(), you don't need to pass
danno 2010/12/06 14:05:12 Done. TODO already in .cc file.
+
+ const DictionaryValue* policy() const { return policy_.get(); }
+
+ protected:
+ friend class UpdatePolicyTask;
+
+ // AsynchronousPolicyLoader objects should only be deleted by
+ // RefCountedThreadSafe.
+ friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>;
+ virtual ~AsynchronousPolicyLoader() {}
+
+ // Schedules a call to UpdatePolicy on the ui thread. Must be called on the
+ // FILE thread.
+ void PostUpdatePolicyTask(DictionaryValue* new_policy);
+
+ // Replaces the existing policy to value map with a new once, sending
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 s/once/one/
danno 2010/12/06 14:05:12 Done.
+ // notification to the provider if there is a policy change. Must be called on
+ // the ui thread.
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 s/ui/UI/ (you say FILE thread above)
danno 2010/12/06 14:05:12 Done.
+ void UpdatePolicy(DictionaryValue* new_policy);
+
+ AsynchronousPolicyProvider::Delegate* delegate() {
+ return delegate_.get();
+ }
+
+ private:
+ friend class AsynchronousPolicyLoaderTest;
+
+ // Provides the low-level mechanics for loading policy.
+ scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_;
+
+ // Current policy.
+ scoped_ptr<DictionaryValue> policy_;
+
+ // The provider this loader is associated with. Access only on the thread that
+ // called the constructor. See |origin_loop_| below.
+ base::WeakPtr<AsynchronousPolicyProvider> provider_;
+
+ // The message loop on which this object was constructed and |provider_|
+ // received on. Recorded so we can call back into the non thread safe provider
+ // to fire the notification.
+ MessageLoop* origin_loop_;
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 Do we still need this? If yes, the comment above c
danno 2010/12/06 14:05:12 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_

Powered by Google App Engine
This is Rietveld 408576698