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

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

Issue 6091002: Refactor the windows policy provider to use AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows tests 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 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/policy/asynchronous_policy_provider.h" 12 #include "chrome/browser/policy/asynchronous_policy_provider.h"
13 13
14 namespace policy { 14 namespace policy {
15 15
16 class ConfigurationPolicyProvider; 16 class ConfigurationPolicyProvider;
17 17
18 // Used by the implementation of asynchronous policy provider to manage the 18 // Used by the implementation of asynchronous policy provider to manage the
19 // tasks on the file thread that do the heavy lifting of loading policies. 19 // tasks on the file thread that do the heavy lifting of loading policies.
20 class AsynchronousPolicyLoader 20 class AsynchronousPolicyLoader
21 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { 21 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> {
22 public: 22 public:
23 explicit AsynchronousPolicyLoader( 23 explicit AsynchronousPolicyLoader(
24 AsynchronousPolicyProvider::Delegate* delegate); 24 AsynchronousPolicyProvider::Delegate* delegate,
25 int reload_interval_minutes);
25 26
26 // Triggers initial policy load. 27 // Triggers initial policy load.
27 virtual void Init(); 28 virtual void Init();
28 29
29 // Reloads policy, sending notification of changes if necessary. Must be 30 // Reloads policy, sending notification of changes if necessary. Must be
30 // called on the file thread. 31 // called on the file thread.
31 virtual void Reload(); 32 virtual void Reload();
32 33
33 // Stops any pending reload tasks. 34 // Stops any pending reload tasks.
34 virtual void Stop(); 35 virtual void Stop();
(...skipping 13 matching lines...) Expand all
48 virtual ~AsynchronousPolicyLoader(); 49 virtual ~AsynchronousPolicyLoader();
49 50
50 // Schedules a call to UpdatePolicy on |origin_loop_|. Takes ownership of 51 // Schedules a call to UpdatePolicy on |origin_loop_|. Takes ownership of
51 // |new_policy|. 52 // |new_policy|.
52 void PostUpdatePolicyTask(DictionaryValue* new_policy); 53 void PostUpdatePolicyTask(DictionaryValue* new_policy);
53 54
54 AsynchronousPolicyProvider::Delegate* delegate() { 55 AsynchronousPolicyProvider::Delegate* delegate() {
55 return delegate_.get(); 56 return delegate_.get();
56 } 57 }
57 58
58 AsynchronousPolicyProvider* provider() { 59 // Performs start operations that must be performed on the file thread.
59 return provider_; 60 virtual void InitOnFileThread();
60 } 61
62 // Performs stop operations that must be performed on the file thread.
63 virtual void StopOnFileThread();
64
65 // Schedules a reload task to run when |delay| expires. Must be called on the
66 // file thread.
67 void ScheduleReloadTask(const base::TimeDelta& delay);
68
69 // Schedules a reload task to run after the number of minutes specified
70 // in |reload_interval_minutes_|. Must be called on the file thread.
71 void ScheduleFallbackReloadTask();
72
73 void CancelReloadTask();
74
75 // Invoked from the reload task on the file thread.
76 void ReloadFromTask();
61 77
62 private: 78 private:
63 friend class AsynchronousPolicyLoaderTest; 79 friend class AsynchronousPolicyLoaderTest;
64 80
81 // Finishes loader initialization after the threading system has been fully
82 // intialized.
83 void InitAfterFileThreadAvailable();
84
65 // Replaces the existing policy to value map with a new one, sending 85 // Replaces the existing policy to value map with a new one, sending
66 // notification to the provider if there is a policy change. Must be called on 86 // notification to the provider if there is a policy change. Must be called on
67 // |origin_loop_| so that it's safe to call back into the provider, which is 87 // |origin_loop_| so that it's safe to call back into the provider, which is
68 // not thread-safe. Takes ownership of |new_policy|. 88 // not thread-safe. Takes ownership of |new_policy|.
69 void UpdatePolicy(DictionaryValue* new_policy); 89 void UpdatePolicy(DictionaryValue* new_policy);
70 90
71 // Provides the low-level mechanics for loading policy. 91 // Provides the low-level mechanics for loading policy.
72 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; 92 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_;
73 93
74 // Current policy. 94 // Current policy.
75 scoped_ptr<DictionaryValue> policy_; 95 scoped_ptr<DictionaryValue> policy_;
76 96
77 // The provider this loader is associated with. Access only on the thread that 97 // The provider this loader is associated with. Access only on the thread that
78 // called the constructor. See |origin_loop_| below. 98 // called the constructor. See |origin_loop_| below.
79 AsynchronousPolicyProvider* provider_; 99 AsynchronousPolicyProvider* provider_;
80 100
101 // The reload task. Access only on the file thread. Holds a reference to the
102 // currently posted task, so we can cancel and repost it if necessary.
103 CancelableTask* reload_task_;
104
105 // The interval at which a policy reload will be triggered as a fallback.
106 const base::TimeDelta reload_interval_;
107
81 // The message loop on which this object was constructed. Recorded so that 108 // The message loop on which this object was constructed. Recorded so that
82 // it's possible to call back into the non thread safe provider to fire the 109 // it's possible to call back into the non thread safe provider to fire the
83 // notification. 110 // notification.
84 MessageLoop* origin_loop_; 111 MessageLoop* origin_loop_;
85 112
113 // True if Stop has been called.
114 bool stopped_;
115
86 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); 116 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader);
87 }; 117 };
88 118
89 } // namespace policy 119 } // namespace policy
90 120
91 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ 121 #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