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

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

Issue 8586030: Added ConfigurationPolicyProvider::RefreshPolicies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed win build Created 9 years, 1 month 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/files/file_path_watcher.h" 7 #include "base/files/file_path_watcher.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 private: 56 private:
57 scoped_refptr<FileBasedPolicyLoader> loader_; 57 scoped_refptr<FileBasedPolicyLoader> loader_;
58 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate); 58 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyWatcherDelegate);
59 }; 59 };
60 60
61 void FileBasedPolicyLoader::OnFilePathChanged( 61 void FileBasedPolicyLoader::OnFilePathChanged(
62 const FilePath& path) { 62 const FilePath& path) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
64 Reload(false); 64 Reload(default_callback(), false);
65 } 65 }
66 66
67 void FileBasedPolicyLoader::OnFilePathError(const FilePath& path) { 67 void FileBasedPolicyLoader::OnFilePathError(const FilePath& path) {
68 LOG(ERROR) << "FilePathWatcher on " << path.value() 68 LOG(ERROR) << "FilePathWatcher on " << path.value()
69 << " failed."; 69 << " failed.";
70 } 70 }
71 71
72 void FileBasedPolicyLoader::Reload(bool force) { 72 void FileBasedPolicyLoader::Reload(const base::Closure& callback, bool force) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
74 74
75 if (!delegate()) 75 if (!delegate()) {
76 PostUpdatePolicyTask(callback, NULL);
76 return; 77 return;
78 }
77 79
78 // Check the directory time in order to see whether a reload is required. 80 // Check the directory time in order to see whether a reload is required.
79 base::TimeDelta delay; 81 base::TimeDelta delay;
80 base::Time now = base::Time::Now(); 82 base::Time now = base::Time::Now();
81 if (!force && !IsSafeToReloadPolicy(now, &delay)) { 83 if (!force && !IsSafeToReloadPolicy(now, &delay)) {
82 ScheduleReloadTask(delay); 84 ScheduleReloadTask(callback, delay);
83 return; 85 return;
84 } 86 }
85 87
86 // Load the policy definitions. 88 // Load the policy definitions.
87 scoped_ptr<DictionaryValue> new_policy(delegate()->Load()); 89 scoped_ptr<DictionaryValue> new_policy(delegate()->Load());
88 90
89 // Check again in case the directory has changed while reading it. 91 // Check again in case the directory has changed while reading it.
90 if (!force && !IsSafeToReloadPolicy(now, &delay)) { 92 if (!force && !IsSafeToReloadPolicy(now, &delay)) {
91 ScheduleReloadTask(delay); 93 ScheduleReloadTask(callback, delay);
92 return; 94 return;
93 } 95 }
94 96
95 PostUpdatePolicyTask(new_policy.release()); 97 PostUpdatePolicyTask(callback, new_policy.release());
96 98
97 ScheduleFallbackReloadTask(); 99 ScheduleFallbackReloadTask();
98 } 100 }
99 101
100 void FileBasedPolicyLoader::InitOnFileThread() { 102 void FileBasedPolicyLoader::InitOnFileThread() {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
102 watcher_.reset(new FilePathWatcher); 104 watcher_.reset(new FilePathWatcher);
103 const FilePath& path = config_file_path(); 105 const FilePath& path = config_file_path();
104 if (!path.empty() && 106 if (!path.empty() &&
105 !watcher_->Watch(path, new FileBasedPolicyWatcherDelegate(this))) { 107 !watcher_->Watch(path, new FileBasedPolicyWatcherDelegate(this))) {
106 OnFilePathError(path); 108 OnFilePathError(path);
107 } 109 }
108 110
109 // There might have been changes to the directory in the time between 111 // There might have been changes to the directory in the time between
110 // construction of the loader and initialization of the watcher. Call reload 112 // construction of the loader and initialization of the watcher. Call reload
111 // to detect if that is the case. 113 // to detect if that is the case.
112 Reload(false); 114 Reload(default_callback(), false);
113 115
114 ScheduleFallbackReloadTask(); 116 ScheduleFallbackReloadTask();
115 } 117 }
116 118
117 void FileBasedPolicyLoader::StopOnFileThread() { 119 void FileBasedPolicyLoader::StopOnFileThread() {
118 watcher_.reset(); 120 watcher_.reset();
119 AsynchronousPolicyLoader::StopOnFileThread(); 121 AsynchronousPolicyLoader::StopOnFileThread();
120 } 122 }
121 123
122 bool FileBasedPolicyLoader::IsSafeToReloadPolicy( 124 bool FileBasedPolicyLoader::IsSafeToReloadPolicy(
(...skipping 20 matching lines...) Expand all
143 base::TimeDelta age = now - last_modification_clock_; 145 base::TimeDelta age = now - last_modification_clock_;
144 if (age < settle_interval_) { 146 if (age < settle_interval_) {
145 *delay = settle_interval_ - age; 147 *delay = settle_interval_ - age;
146 return false; 148 return false;
147 } 149 }
148 150
149 return true; 151 return true;
150 } 152 }
151 153
152 } // namespace policy 154 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698