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

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: Addressed comments 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/weak_ptr.h"
12 #include "base/message_loop_proxy.h"
13 #include "base/time.h"
14
15 namespace policy {
16
17 class PolicyBundle;
18
19 // Base implementation for platform-specific policy loaders. Together with the
20 // AsyncPolicyProvider, this base implementation takes care of the initial load,
21 // periodic reloads, watching file changes, refreshing policies and object
22 // lifetime.
23 //
24 // All methods are invoked on the FILE thread, including the destructor.
25 // The only exceptions are the constructor (which may be called on any thread),
26 // and the initial Load() which is called on the thread that owns the provider.
27 // LastModificationTime() is also invoked once on that thread at startup.
28 class AsyncPolicyLoader {
29 public:
30 AsyncPolicyLoader();
31 virtual ~AsyncPolicyLoader();
32
33 // Returns the currently configured policies. Load() is always invoked on
34 // the FILE thread, except for the initial Load() at startup which is invoked
35 // from the thread that owns the provider.
36 virtual scoped_ptr<PolicyBundle> Load() = 0;
37
38 // Allows implementations to finalize their initialization on the FILE
39 // thread (e.g. setup file watchers).
40 virtual void InitOnFile() = 0;
41
42 // Implementations should return the time of the last modification detected,
43 // or base::Time() if it doesn't apply, which is the default.
44 virtual base::Time LastModificationTime();
45
46 // Implementations should invoke Reload() when a change is detected. This
47 // must be invoked from the FILE thread and will trigger a Load(), and pass
48 // the returned bundle to the provider.
49 // The load is immediate when |force| is true. Otherwise, the loader
50 // reschedules the reload until the LastModificationTime() is a couple of
51 // seconds in the past. This mitigates the problem of reading files that are
52 // currently being written to, and whose contents are incomplete.
53 // A reload is posted periodically, if it hasn't been triggered recently. This
54 // makes sure the policies are reloaded if the update events aren't triggered.
55 void Reload(bool force);
56
57 private:
58 // Allow AsyncPolicyProvider to call Init().
59 friend class AsyncPolicyProvider;
60
61 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
62
63 // Used by the AsyncPolicyProvider to do the initial Load(). The first load
64 // is also used to initialize |last_modification_time_|.
65 scoped_ptr<PolicyBundle> InitialLoad();
66
67 // Used by the AsyncPolicyProvider to install the |update_callback_|, which
68 // should be posted to the |provider_loop_| on updates.
69 // Invoked on the FILE thread.
70 void Init(scoped_refptr<base::MessageLoopProxy> provider_loop,
Mattias Nissler (ping if slow) 2012/06/04 15:25:39 Do we really need the loop? It seems that AsyncPol
Joao da Silva 2012/06/04 17:28:12 Done.
71 const UpdateCallback& update_callback);
72
73 // Cancels any pending periodic reload and posts one |delay| time units from
74 // now.
75 void ScheduleNextReload(base::TimeDelta delay);
76
77 // Checks if the underlying files haven't changed recently, by checking the
78 // LastModificationTime(). |delay| is updated with a suggested time to wait
79 // before retrying when this returns false.
80 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay);
81
82 // Callback for updates, passed in Init(). It is posted to the
83 // |provider_loop_| on updates..
Mattias Nissler (ping if slow) 2012/06/04 15:25:39 Excess period
Joao da Silva 2012/06/04 17:28:12 Done.
84 UpdateCallback update_callback_;
85 scoped_refptr<base::MessageLoopProxy> provider_loop_;
86
87 // Used to get WeakPtrs for the periodic reload task.
88 base::WeakPtrFactory<AsyncPolicyLoader> weak_factory_;
89
90 // Records last known modification timestamp.
91 base::Time last_modification_time_;
92
93 // The wall clock time at which the last modification timestamp was
94 // recorded. It's better to not assume the file notification time and the
95 // wall clock times come from the same source, just in case there is some
96 // non-local filesystem involved.
97 base::Time last_modification_clock_;
98
99 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader);
100 };
101
102 } // namespace policy
103
104 #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_provider.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698