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

Side by Side Diff: chrome/browser/policy/file_based_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 9 years, 12 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
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_FILE_BASED_POLICY_LOADER_H_ 5 #ifndef CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
6 #define CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ 6 #define CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "chrome/browser/file_path_watcher/file_path_watcher.h" 9 #include "chrome/browser/file_path_watcher/file_path_watcher.h"
10 #include "chrome/browser/policy/asynchronous_policy_loader.h" 10 #include "chrome/browser/policy/asynchronous_policy_loader.h"
11 #include "chrome/browser/policy/file_based_policy_provider.h" 11 #include "chrome/browser/policy/file_based_policy_provider.h"
12 12
13 namespace policy { 13 namespace policy {
14 14
15 // A customized asynchronous policy loader that handles loading policy from a 15 // A customized asynchronous policy loader that handles loading policy from a
16 // file using a FilePathWatcher. The loader creates a fallback task to load 16 // file using a FilePathWatcher. The loader creates a fallback task to load
17 // policy periodically in case the watcher fails and retries policy loads when 17 // policy periodically in case the watcher fails and retries policy loads when
18 // the watched file is in flux. 18 // the watched file is in flux.
19 class FileBasedPolicyLoader : public AsynchronousPolicyLoader { 19 class FileBasedPolicyLoader : public AsynchronousPolicyLoader {
20 public: 20 public:
21 FileBasedPolicyLoader( 21 FileBasedPolicyLoader(
22 FileBasedPolicyProvider::ProviderDelegate* provider_delegate); 22 FileBasedPolicyProvider::ProviderDelegate* provider_delegate);
23 23
24 // AsynchronousPolicyLoader implementation: 24 // AsynchronousPolicyLoader overrides:
25 virtual void Init();
26 virtual void Stop();
27 virtual void Reload(); 25 virtual void Reload();
28 26
29 void OnFilePathChanged(const FilePath& path); 27 void OnFilePathChanged(const FilePath& path);
30 void OnError(); 28 void OnError();
31 29
32 protected: 30 protected:
33 // FileBasedPolicyLoader objects should only be deleted by 31 // FileBasedPolicyLoader objects should only be deleted by
34 // RefCountedThreadSafe. 32 // RefCountedThreadSafe.
35 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; 33 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>;
36 virtual ~FileBasedPolicyLoader(); 34 virtual ~FileBasedPolicyLoader();
37 35
38 const FilePath& config_file_path() { return config_file_path_; } 36 const FilePath& config_file_path() { return config_file_path_; }
39 37
38 // AsynchronousPolicyLoader overrides:
39
40 // Creates the file path watcher and configures it to watch
41 // |config_file_path_|. Must be called on the file thread.
42 virtual void InitOnFileThread();
43 virtual void StopOnFileThread();
44
40 private: 45 private:
41 // Finishes initialization after the threading system has been fully
42 // intiialized.
43 void InitAfterFileThreadAvailable();
44
45 // Creates the file path watcher, configures it to watch |config_file_path_|
46 // and schedules the fallback reload task. Must be called on the file thread.
47 void InitOnFileThread();
48
49 // Cancels file path watch notification and destroys the watcher.
50 // Must be called on file thread.
51 void StopOnFileThread();
52
53 // Schedules a reload task to run when |delay| expires. Must be called on the
54 // file thread.
55 void ScheduleReloadTask(const base::TimeDelta& delay);
56
57 // Schedules a reload task to run after the number of minutes specified
58 // in |reload_interval_minutes_|. Must be called on the file thread.
59 void ScheduleFallbackReloadTask();
60
61 // Invoked from the reload task on the file thread.
62 void ReloadFromTask();
63
64 // Checks whether policy information is safe to read. If not, returns false 46 // Checks whether policy information is safe to read. If not, returns false
65 // and then delays until it is considered safe to reload in |delay|. 47 // and then delays until it is considered safe to reload in |delay|.
66 // Must be called on the file thread. 48 // Must be called on the file thread.
67 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay); 49 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay);
68 50
69 // The path at which we look for configuration files. 51 // The path at which we look for configuration files.
70 const FilePath config_file_path_; 52 const FilePath config_file_path_;
71 53
72 // Managed with a scoped_ptr rather than being declared as an inline member to 54 // Managed with a scoped_ptr rather than being declared as an inline member to
73 // decouple the watcher's life cycle from the loader's. This decoupling makes 55 // decouple the watcher's life cycle from the loader's. This decoupling makes
74 // it possible to destroy the watcher before the loader's destructor is called 56 // it possible to destroy the watcher before the loader's destructor is called
75 // (e.g. during Stop), since |watcher_| internally holds a reference to the 57 // (e.g. during Stop), since |watcher_| internally holds a reference to the
76 // loader and keeps it alive. 58 // loader and keeps it alive.
77 scoped_ptr<FilePathWatcher> watcher_; 59 scoped_ptr<FilePathWatcher> watcher_;
78 60
79 // The reload task. Access only on the file thread. Holds a reference to the
80 // currently posted task, so we can cancel and repost it if necessary.
81 CancelableTask* reload_task_;
82
83 // The interval that a policy reload will be triggered as a fallback even if
84 // the delegate doesn't indicate that one is needed.
85 const base::TimeDelta reload_interval_;
86
87 // Settle interval. 61 // Settle interval.
88 const base::TimeDelta settle_interval_; 62 const base::TimeDelta settle_interval_;
89 63
90 // Records last known modification timestamp of |config_file_path_|. 64 // Records last known modification timestamp of |config_file_path_|.
91 base::Time last_modification_file_; 65 base::Time last_modification_file_;
92 66
93 // The wall clock time at which the last modification timestamp was 67 // 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 68 // 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 69 // wall clock times come from the same source, just in case there is some
96 // non-local filesystem involved. 70 // non-local filesystem involved.
97 base::Time last_modification_clock_; 71 base::Time last_modification_clock_;
98 72
99 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyLoader); 73 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyLoader);
100 }; 74 };
101 75
102 } // namespace policy 76 } // namespace policy
103 77
104 #endif // CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ 78 #endif // CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_provider_win_unittest.cc ('k') | chrome/browser/policy/file_based_policy_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698