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

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

Issue 6731064: kqueue implementation of FilePathWatcher on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix up parens 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) 2011 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"
7 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
8 9
9 namespace { 10 namespace {
10 11
11 // 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
12 // them. This alleviates the problem of reading partially written files and 13 // them. This alleviates the problem of reading partially written files and
13 // makes it possible to batch quasi-simultaneous changes. 14 // makes it possible to batch quasi-simultaneous changes.
14 const int kSettleIntervalSeconds = 5; 15 const int kSettleIntervalSeconds = 5;
15 16
16 // 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
(...skipping 15 matching lines...) Expand all
32 FileBasedPolicyLoader::~FileBasedPolicyLoader() {} 33 FileBasedPolicyLoader::~FileBasedPolicyLoader() {}
33 34
34 class FileBasedPolicyWatcherDelegate : public FilePathWatcher::Delegate { 35 class FileBasedPolicyWatcherDelegate : public FilePathWatcher::Delegate {
35 public: 36 public:
36 explicit FileBasedPolicyWatcherDelegate( 37 explicit FileBasedPolicyWatcherDelegate(
37 scoped_refptr<FileBasedPolicyLoader> loader) 38 scoped_refptr<FileBasedPolicyLoader> loader)
38 : loader_(loader) {} 39 : loader_(loader) {}
39 virtual ~FileBasedPolicyWatcherDelegate() {} 40 virtual ~FileBasedPolicyWatcherDelegate() {}
40 41
41 // FilePathWatcher::Delegate implementation: 42 // FilePathWatcher::Delegate implementation:
42 void OnFilePathChanged(const FilePath& path) { 43 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
43 loader_->OnFilePathChanged(path); 44 loader_->OnFilePathChanged(path);
44 } 45 }
45 46
46 void OnError() { 47 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
47 loader_->OnError(); 48 loader_->OnFilePathError(path);
48 } 49 }
49 50
50 private: 51 private:
51 scoped_refptr<FileBasedPolicyLoader> loader_; 52 scoped_refptr<FileBasedPolicyLoader> loader_;
52 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate); 53 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate);
53 }; 54 };
54 55
55 void FileBasedPolicyLoader::OnFilePathChanged( 56 void FileBasedPolicyLoader::OnFilePathChanged(
56 const FilePath& path) { 57 const FilePath& path) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
58 Reload(); 59 Reload();
59 } 60 }
60 61
61 void FileBasedPolicyLoader::OnError() { 62 void FileBasedPolicyLoader::OnFilePathError(const FilePath& path) {
62 LOG(ERROR) << "FilePathWatcher on " << config_file_path().value() 63 LOG(ERROR) << "FilePathWatcher on " << path.value()
63 << " failed."; 64 << " failed.";
64 } 65 }
65 66
66 void FileBasedPolicyLoader::Reload() { 67 void FileBasedPolicyLoader::Reload() {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
68 69
69 if (!delegate()) 70 if (!delegate())
70 return; 71 return;
71 72
72 // 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
87 } 88 }
88 89
89 PostUpdatePolicyTask(new_policy.release()); 90 PostUpdatePolicyTask(new_policy.release());
90 91
91 ScheduleFallbackReloadTask(); 92 ScheduleFallbackReloadTask();
92 } 93 }
93 94
94 void FileBasedPolicyLoader::InitOnFileThread() { 95 void FileBasedPolicyLoader::InitOnFileThread() {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
96 watcher_.reset(new FilePathWatcher); 97 watcher_.reset(new FilePathWatcher);
97 if (!config_file_path().empty() && 98 const FilePath& path = config_file_path();
98 !watcher_->Watch( 99 if (!path.empty() &&
99 config_file_path(), 100 !watcher_->Watch(path, new FileBasedPolicyWatcherDelegate(this))) {
100 new FileBasedPolicyWatcherDelegate(this), 101 OnFilePathError(path);
101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))) {
102 OnError();
103 } 102 }
104 103
105 // 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
106 // construction of the loader and initialization of the watcher. Call reload 105 // construction of the loader and initialization of the watcher. Call reload
107 // to detect if that is the case. 106 // to detect if that is the case.
108 Reload(); 107 Reload();
109 108
110 ScheduleFallbackReloadTask(); 109 ScheduleFallbackReloadTask();
111 } 110 }
112 111
(...skipping 26 matching lines...) Expand all
139 base::TimeDelta age = now - last_modification_clock_; 138 base::TimeDelta age = now - last_modification_clock_;
140 if (age < settle_interval_) { 139 if (age < settle_interval_) {
141 *delay = settle_interval_ - age; 140 *delay = settle_interval_ - age;
142 return false; 141 return false;
143 } 142 }
144 143
145 return true; 144 return true;
146 } 145 }
147 146
148 } // 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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698