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

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

Issue 10448118: Add the AsyncPolicyProvider and AsyncPolicyLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest Created 8 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_
6 #define CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_
7 #pragma once
8
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time.h"
14
15 class FilePath;
16
17 namespace base {
18 namespace files {
19 class FilePathWatcher;
20 } // namespace files
21 } // namespace base
22
23 namespace policy {
24
25 class PolicyBundle;
26
27 // Base implementation for platform-specific policy loaders. Together with the
28 // AsyncPolicyProvider, this base implementation takes care of the initial load,
29 // periodic reloads, watching file changes, refreshing policies and object
30 // lifetime.
31 //
32 // All methods are invoked on FILE, including the destructor. The only
33 // exceptions are the constructor (which may be called on any thread), and the
34 // initial Load() which is called on UI. LastModificationTime() is also invoked
35 // once on UI at startup.
36 class AsyncPolicyLoader {
37 public:
38 AsyncPolicyLoader();
39 virtual ~AsyncPolicyLoader();
40
41 // Returns the currently configured policies. Load() is always invoked on
42 // FILE, except for the initial Load() at startup which is invoked from UI.
Mattias Nissler (ping if slow) 2012/06/04 08:48:26 say FILE _thread_, otherwise this won't make any s
Joao da Silva 2012/06/04 14:05:06 Done.
43 virtual scoped_ptr<PolicyBundle> Load() = 0;
44
45 // Allows implementations to finalize their initialization on the FILE
46 // thread (e.g. setup file watchers with WatchPath()).
47 virtual void InitOnFile() = 0;
48
49 // Implementations should return the time of the last modification detected,
50 // or base::Time() if it doesn't apply, which is the default.
51 virtual base::Time LastModificationTime();
52
53 // Implementations should invoke Reload() when a change is detected. This
54 // must be invoked from FILE and will trigger a Load(), and pass the
55 // returned bundle to the provider.
56 // The load is immediate when |force| is true. Otherwise, the loader
57 // reschedules the reload until the LastModificationTime() is a couple of
58 // seconds in the past.
Mattias Nissler (ping if slow) 2012/06/04 08:48:26 explain why.
Joao da Silva 2012/06/04 14:05:06 Done.
59 //
60 // A reload is posted periodically, and whenever changes are detected to
61 // paths passed to WatchPath().
62 void Reload(bool force);
63
64 // Starts watching |path| and posts Reload() whenever a change is detected.
65 // Must be invoked on FILE.
66 void WatchPath(const FilePath& path);
Mattias Nissler (ping if slow) 2012/06/04 08:48:26 seems like this should be protected.
Joao da Silva 2012/06/04 14:05:06 Obsolete; this has been removed, as suggested else
67
68 private:
69 // Allow AsyncPolicyProvider to call Init().
70 friend class AsyncPolicyProvider;
71
72 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
73
74 // Used by the AsyncPolicyProvider to do the initial Load(). The first load
75 // is also used to initialize |last_modification_time_|.
76 scoped_ptr<PolicyBundle> InitialLoad();
77
78 // Used by the AsyncPolicyProvider to install the |update_callback_|.
79 // Invoked on FILE.
80 void Init(const UpdateCallback& update_callback);
81
82 // Cancels any pending periodic reload and posts one |delay| time units from
83 // now.
84 void ScheduleNextReload(base::TimeDelta delay);
85
86 // Checks if the underlying files haven't changed recently, by checking the
87 // LastModificationTime(). |delay| is updated with a suggested time to wait
88 // before retrying when this returns false.
89 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay);
90
91 // Callback for updates, passed in Init().
92 UpdateCallback update_callback_;
93
94 // |reload_weak_factory_| is used to get WeakPtrs for the periodic reload
95 // tasks, and |watchers_weak_factory_| to get WeakPtrs for the update callback
96 // passed to the |watchers_|. They're separate because |reload_weak_factory_|
97 // is invalidated whenever a new reload is scheduled, while
Mattias Nissler (ping if slow) 2012/06/04 08:48:26 use base/timer.h instead?
Joao da Silva 2012/06/04 14:05:06 The weak factory for the watchers is now gone. I t
98 // |watchers_weak_factory_| is valid until destruction of |this| object.
99 base::WeakPtrFactory<AsyncPolicyLoader> reload_weak_factory_;
100 base::WeakPtrFactory<AsyncPolicyLoader> watchers_weak_factory_;
101
102 // Records last known modification timestamp.
103 base::Time last_modification_time_;
104
105 // The wall clock time at which the last modification timestamp was
106 // recorded. It's better to not assume the file notification time and the
107 // wall clock times come from the same source, just in case there is some
108 // non-local filesystem involved.
109 base::Time last_modification_clock_;
110
111 // List of watchers, one per call to WatchPath.
112 ScopedVector<base::files::FilePathWatcher> watchers_;
113
114 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader);
115 };
116
117 } // namespace policy
118
119 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/async_policy_loader.cc » ('j') | chrome/browser/policy/async_policy_loader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698