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

Side by Side Diff: chrome/browser/policy/file_based_policy_loader.cc

Issue 6825063: Patch for bug 74983 (among others) to be applied to M11 696 branch. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/696/src
Patch Set: intentionally disabled mac tests. tested by hand. Created 9 years, 8 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) 2011 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 #include "chrome/browser/policy/file_based_policy_loader.h" 5 #include "chrome/browser/policy/file_based_policy_loader.h"
6 6
7 #include "base/compiler_specific.h"
8 #include "content/browser/browser_thread.h"
9
7 namespace { 10 namespace {
8 11
9 // Amount of time we wait for the files on disk to settle before trying to load 12 // Amount of time we wait for the files on disk to settle before trying to load
10 // them. This alleviates the problem of reading partially written files and 13 // them. This alleviates the problem of reading partially written files and
11 // makes it possible to batch quasi-simultaneous changes. 14 // makes it possible to batch quasi-simultaneous changes.
12 const int kSettleIntervalSeconds = 5; 15 const int kSettleIntervalSeconds = 5;
13 16
14 // The time interval for rechecking policy. This is our fallback in case the 17 // The time interval for rechecking policy. This is our fallback in case the
15 // delegate never reports a change to the ReloadObserver. 18 // delegate never reports a change to the ReloadObserver.
16 const int kReloadIntervalMinutes = 15; 19 const int kReloadIntervalMinutes = 15;
(...skipping 13 matching lines...) Expand all
30 FileBasedPolicyLoader::~FileBasedPolicyLoader() {} 33 FileBasedPolicyLoader::~FileBasedPolicyLoader() {}
31 34
32 class FileBasedPolicyWatcherDelegate : public FilePathWatcher::Delegate { 35 class FileBasedPolicyWatcherDelegate : public FilePathWatcher::Delegate {
33 public: 36 public:
34 explicit FileBasedPolicyWatcherDelegate( 37 explicit FileBasedPolicyWatcherDelegate(
35 scoped_refptr<FileBasedPolicyLoader> loader) 38 scoped_refptr<FileBasedPolicyLoader> loader)
36 : loader_(loader) {} 39 : loader_(loader) {}
37 virtual ~FileBasedPolicyWatcherDelegate() {} 40 virtual ~FileBasedPolicyWatcherDelegate() {}
38 41
39 // FilePathWatcher::Delegate implementation: 42 // FilePathWatcher::Delegate implementation:
40 void OnFilePathChanged(const FilePath& path) { 43 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
41 loader_->OnFilePathChanged(path); 44 loader_->OnFilePathChanged(path);
42 } 45 }
43 46
44 void OnError() { 47 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
45 loader_->OnError(); 48 loader_->OnFilePathError(path);
46 } 49 }
47 50
48 private: 51 private:
49 scoped_refptr<FileBasedPolicyLoader> loader_; 52 scoped_refptr<FileBasedPolicyLoader> loader_;
50 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate); 53 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate);
51 }; 54 };
52 55
53 void FileBasedPolicyLoader::OnFilePathChanged( 56 void FileBasedPolicyLoader::OnFilePathChanged(
54 const FilePath& path) { 57 const FilePath& path) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
56 Reload(); 59 Reload();
57 } 60 }
58 61
59 void FileBasedPolicyLoader::OnError() { 62 void FileBasedPolicyLoader::OnFilePathError(const FilePath& path) {
60 LOG(ERROR) << "FilePathWatcher on " << config_file_path().value() 63 LOG(ERROR) << "FilePathWatcher on " << path.value()
61 << " failed."; 64 << " failed.";
62 } 65 }
63 66
64 void FileBasedPolicyLoader::Reload() { 67 void FileBasedPolicyLoader::Reload() {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
66 69
67 if (!delegate()) 70 if (!delegate())
68 return; 71 return;
69 72
70 // Check the directory time in order to see whether a reload is required. 73 // Check the directory time in order to see whether a reload is required.
(...skipping 14 matching lines...) Expand all
85 } 88 }
86 89
87 PostUpdatePolicyTask(new_policy.release()); 90 PostUpdatePolicyTask(new_policy.release());
88 91
89 ScheduleFallbackReloadTask(); 92 ScheduleFallbackReloadTask();
90 } 93 }
91 94
92 void FileBasedPolicyLoader::InitOnFileThread() { 95 void FileBasedPolicyLoader::InitOnFileThread() {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
94 watcher_.reset(new FilePathWatcher); 97 watcher_.reset(new FilePathWatcher);
95 if (!config_file_path().empty() && 98 const FilePath& path = config_file_path();
96 !watcher_->Watch(config_file_path(), 99 if (!path.empty() &&
97 new FileBasedPolicyWatcherDelegate(this))) { 100 !watcher_->Watch(path, new FileBasedPolicyWatcherDelegate(this))) {
98 OnError(); 101 OnFilePathError(path);
99 } 102 }
100 103
101 // There might have been changes to the directory in the time between 104 // There might have been changes to the directory in the time between
102 // construction of the loader and initialization of the watcher. Call reload 105 // construction of the loader and initialization of the watcher. Call reload
103 // to detect if that is the case. 106 // to detect if that is the case.
104 Reload(); 107 Reload();
105 108
106 ScheduleFallbackReloadTask(); 109 ScheduleFallbackReloadTask();
107 } 110 }
108 111
(...skipping 26 matching lines...) Expand all
135 base::TimeDelta age = now - last_modification_clock_; 138 base::TimeDelta age = now - last_modification_clock_;
136 if (age < settle_interval_) { 139 if (age < settle_interval_) {
137 *delay = settle_interval_ - age; 140 *delay = settle_interval_ - age;
138 return false; 141 return false;
139 } 142 }
140 143
141 return true; 144 return true;
142 } 145 }
143 146
144 } // namespace policy 147 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/file_based_policy_loader.h ('k') | chrome/browser/user_style_sheet_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698