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

Side by Side Diff: chrome/browser/policy/asynchronous_policy_loader.h

Issue 10386097: Refactored ConfigurationPolicyProvider to provide PolicyBundles instead of PolicyMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/policy/asynchronous_policy_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ 5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_
6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/policy/asynchronous_policy_provider.h" 14 #include "chrome/browser/policy/asynchronous_policy_provider.h"
15 #include "chrome/browser/policy/configuration_policy_provider.h"
16 #include "chrome/browser/policy/policy_map.h"
17 15
18 class MessageLoop; 16 class MessageLoop;
19 17
20 namespace policy { 18 namespace policy {
21 19
20 class PolicyBundle;
21 class PolicyMap;
22
22 // Used by the implementation of asynchronous policy provider to manage the 23 // Used by the implementation of asynchronous policy provider to manage the
23 // tasks on the FILE thread that do the heavy lifting of loading policies. 24 // tasks on the FILE thread that do the heavy lifting of loading policies.
24 class AsynchronousPolicyLoader 25 class AsynchronousPolicyLoader
25 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { 26 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> {
26 public: 27 public:
28 // The type of the callback passed to Init().
29 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
30
27 AsynchronousPolicyLoader(AsynchronousPolicyProvider::Delegate* delegate, 31 AsynchronousPolicyLoader(AsynchronousPolicyProvider::Delegate* delegate,
28 int reload_interval_minutes); 32 int reload_interval_minutes);
29 33
30 // Triggers initial policy load, and installs |callback| as the callback to 34 // Triggers initial policy load, and installs |callback| as the callback to
31 // invoke on policy updates. 35 // invoke on policy updates. |callback| takes ownership of the passed
32 virtual void Init(const base::Closure& callback); 36 // PolicyBundle, which contains all the policies that were loaded.
37 virtual void Init(const UpdateCallback& callback);
33 38
34 // Reloads policy, sending notification of changes if necessary. Must be 39 // Reloads policy, sending notification of changes if necessary. Must be
35 // called on the FILE thread. When |force| is true, the loader should do an 40 // called on the FILE thread. When |force| is true, the loader should do an
36 // immediate full reload. 41 // immediate full reload.
37 virtual void Reload(bool force); 42 virtual void Reload(bool force);
38 43
39 // Stops any pending reload tasks. Updates callbacks won't be performed 44 // Stops any pending reload tasks. Updates callbacks won't be performed
40 // anymore once the loader is stopped. 45 // anymore once the loader is stopped.
41 virtual void Stop(); 46 virtual void Stop();
42 47
43 const PolicyMap& policy() const { return policy_; }
44
45 protected: 48 protected:
46 // AsynchronousPolicyLoader objects should only be deleted by 49 // AsynchronousPolicyLoader objects should only be deleted by
47 // RefCountedThreadSafe. 50 // RefCountedThreadSafe.
48 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; 51 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>;
49 virtual ~AsynchronousPolicyLoader(); 52 virtual ~AsynchronousPolicyLoader();
50 53
51 // Schedules a call to UpdatePolicy on |origin_loop_|. Takes ownership of 54 // Schedules a call to UpdatePolicy on |origin_loop_|. Takes ownership of
52 // |new_policy|. 55 // |new_policy|.
53 void PostUpdatePolicyTask(PolicyMap* new_policy); 56 void PostUpdatePolicyTask(PolicyMap* new_policy);
54 57
(...skipping 20 matching lines...) Expand all
75 // Invoked from the reload task on the FILE thread. 78 // Invoked from the reload task on the FILE thread.
76 void ReloadFromTask(); 79 void ReloadFromTask();
77 80
78 private: 81 private:
79 friend class AsynchronousPolicyLoaderTest; 82 friend class AsynchronousPolicyLoaderTest;
80 83
81 // Finishes loader initialization after the threading system has been fully 84 // Finishes loader initialization after the threading system has been fully
82 // intialized. 85 // intialized.
83 void InitAfterFileThreadAvailable(); 86 void InitAfterFileThreadAvailable();
84 87
85 // Replaces the existing policy to value map with a new one, sending 88 // Invokes the |update_callback_| with a new PolicyBundle that maps
86 // notification to the observers if there is a policy change. Must be called 89 // the chrome namespace to |policy|. Must be called on |origin_loop_| so that
87 // on |origin_loop_| so that it's safe to call back into the provider, which 90 // it's safe to invoke |update_callback_|.
88 // is not thread-safe. Takes ownership of |new_policy|. 91 void UpdatePolicy(scoped_ptr<PolicyMap> policy);
89 void UpdatePolicy(PolicyMap* new_policy);
90 92
91 // Provides the low-level mechanics for loading policy. 93 // Provides the low-level mechanics for loading policy.
92 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; 94 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_;
93 95
94 // Current policy.
95 PolicyMap policy_;
96
97 // Used to create and invalidate WeakPtrs on the FILE thread. These are only 96 // Used to create and invalidate WeakPtrs on the FILE thread. These are only
98 // used to post reload tasks that can be cancelled. 97 // used to post reload tasks that can be cancelled.
99 base::WeakPtrFactory<AsynchronousPolicyLoader> weak_ptr_factory_; 98 base::WeakPtrFactory<AsynchronousPolicyLoader> weak_ptr_factory_;
100 99
101 // The interval at which a policy reload will be triggered as a fallback. 100 // The interval at which a policy reload will be triggered as a fallback.
102 const base::TimeDelta reload_interval_; 101 const base::TimeDelta reload_interval_;
103 102
104 // The message loop on which this object was constructed. Recorded so that 103 // The message loop on which this object was constructed. Recorded so that
105 // it's possible to call back into the non thread safe provider to fire the 104 // it's possible to call back into the non thread safe provider to fire the
106 // notification. 105 // notification.
107 MessageLoop* origin_loop_; 106 MessageLoop* origin_loop_;
108 107
109 // True if Stop has been called. 108 // True if Stop has been called.
110 bool stopped_; 109 bool stopped_;
111 110
112 // Callback to invoke on policy updates. 111 // Callback to invoke on policy updates.
113 base::Closure updates_callback_; 112 UpdateCallback update_callback_;
114 113
115 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); 114 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader);
116 }; 115 };
117 116
118 } // namespace policy 117 } // namespace policy
119 118
120 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ 119 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/asynchronous_policy_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698