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

Side by Side Diff: chrome/browser/policy/file_based_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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
6 #define CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
7 #pragma once
8
9 #include "chrome/browser/policy/asynchronous_policy_loader.h"
10 #include "chrome/browser/policy/file_based_policy_provider.h"
11
12 namespace policy {
13
14 // A customized asynchronous policy loader that handles loading policy from a
15 // file using a FilePathWatcher. The loader creates a fallback task to load
16 // policy periodically in case the watcher fails and retries policy loads when
17 // the watched file is in flux.
18 class FileBasedPolicyLoader : public AsynchronousPolicyLoader {
19 public:
20 FileBasedPolicyLoader(
21 FileBasedPolicyProvider::ProviderDelegate* provider_delegate);
22
23 // AsynchronousPolicyLoader implementation:
24 virtual void Init();
25 virtual void Stop();
26 virtual void Reload();
27
28 void OnFilePathChanged(const FilePath& path);
29 void OnError();
30
31 protected:
32 // FileBasedPolicyLoader objects should only be deleted by
33 // RefCountedThreadSafe.
34 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>;
35 virtual ~FileBasedPolicyLoader() {}
36
37 const FilePath& config_file_path() { return config_file_path_; }
38
39 private:
40 // Creates the file path watcher and configures it watch |config_file_path_|.
41 void InitWatcher();
42
43 // Cancels file path watch notification and destroys the watcher.
44 // Must be called on file thread.
45 void StopOnFileThread();
46
47 // Schedules a reload task to run when |delay| expires. Must be called on the
48 // file thread.
49 void ScheduleReloadTask(const base::TimeDelta& delay);
50
51 // Schedules a reload task to run after the number of minutes specified
52 // in |reload_interval_minutes_|. Must be called on the file thread.
53 void ScheduleFallbackReloadTask();
54
55 // Invoked from the reload task on the file thread.
56 void ReloadFromTask();
57
58 // Checks whether policy information is safe to read. If not, returns false
59 // and then delays until it is considered safe to reload in |delay|.
60 // Must be called on the file thread.
61 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay);
62
63 FileBasedPolicyProvider::ProviderDelegate* provider_delegate_;
64
65 // The path at which we look for configuration files.
66 const FilePath config_file_path_;
67
68 scoped_ptr<FilePathWatcher> watcher_;
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 Can you comment on why we need a scoped_ptr to wra
danno 2010/12/06 14:05:12 Done.
69
70 // The reload task. Access only on the file thread. Holds a reference to the
71 // currently posted task, so we can cancel and repost it if necessary.
72 CancelableTask* reload_task_;
73
74 // The interval that a policy reload will be triggered as a fallback even if
75 // the delegate doesn't indicate that one is needed.
76 const base::TimeDelta reload_interval_;
77
78 // Settle interval.
79 const base::TimeDelta settle_interval_;
80
81 // Records last known modification timestamp of |config_file_path_|.
82 base::Time last_modification_file_;
83
84 // The wall clock time at which the last modification timestamp was
85 // recorded. It's better to not assume the file notification time and the
86 // wall clock times come from the same source, just in case there is some
87 // non-local filesystem involved.
88 base::Time last_modification_clock_;
89
90 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyLoader);
91 };
92
93 } // namespace policy
94
95 #endif // CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698