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

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

Issue 5732002: Fix policy refresh. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check diffs 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
« no previous file with comments | « chrome/browser/policy/file_based_policy_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/policy/file_based_policy_loader.h" 5 #include "chrome/browser/policy/file_based_policy_loader.h"
6 6
7 namespace { 7 namespace {
8 8
9 // Amount of time we wait for the files on disk to settle before trying to load 9 // 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 10 // them. This alleviates the problem of reading partially written files and
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 void FileBasedPolicyLoader::Init() { 52 void FileBasedPolicyLoader::Init() {
53 AsynchronousPolicyLoader::Init(); 53 AsynchronousPolicyLoader::Init();
54 54
55 // Initialization can happen early when the file thread is not yet available, 55 // Initialization can happen early when the file thread is not yet available,
56 // but the watcher's initialization must be done on the file thread. Posting 56 // but the watcher's initialization must be done on the file thread. Posting
57 // to a to the file directly before the file thread is initialized will cause 57 // to a to the file directly before the file thread is initialized will cause
58 // the task to be forgotten. Instead, post a task to the ui thread to delay 58 // the task to be forgotten. Instead, post a task to the ui thread to delay
59 // the remainder of initialization until threading is fully initialized. 59 // the remainder of initialization until threading is fully initialized.
60 BrowserThread::PostTask( 60 BrowserThread::PostTask(
61 BrowserThread::FILE, FROM_HERE, 61 BrowserThread::UI, FROM_HERE,
62 NewRunnableMethod(this, 62 NewRunnableMethod(this,
63 &FileBasedPolicyLoader::InitAfterFileThreadAvailable)); 63 &FileBasedPolicyLoader::InitAfterFileThreadAvailable));
64 } 64 }
65 65
66 void FileBasedPolicyLoader::Stop() { 66 void FileBasedPolicyLoader::Stop() {
67 AsynchronousPolicyLoader::Stop(); 67 AsynchronousPolicyLoader::Stop();
68 BrowserThread::PostTask( 68 BrowserThread::PostTask(
69 BrowserThread::FILE, FROM_HERE, 69 BrowserThread::FILE, FROM_HERE,
70 NewRunnableMethod(this, &FileBasedPolicyLoader::StopOnFileThread)); 70 NewRunnableMethod(this, &FileBasedPolicyLoader::StopOnFileThread));
71 } 71 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 PostUpdatePolicyTask(new_policy.release()); 109 PostUpdatePolicyTask(new_policy.release());
110 110
111 ScheduleFallbackReloadTask(); 111 ScheduleFallbackReloadTask();
112 } 112 }
113 113
114 void FileBasedPolicyLoader::InitAfterFileThreadAvailable() { 114 void FileBasedPolicyLoader::InitAfterFileThreadAvailable() {
115 if (provider()) { 115 if (provider()) {
116 BrowserThread::PostTask( 116 BrowserThread::PostTask(
117 BrowserThread::FILE, FROM_HERE, 117 BrowserThread::FILE, FROM_HERE,
118 NewRunnableMethod(this, &FileBasedPolicyLoader::InitWatcher)); 118 NewRunnableMethod(this, &FileBasedPolicyLoader::InitOnFileThread));
119
120 ScheduleFallbackReloadTask();
121 } 119 }
122 } 120 }
123 121
124 void FileBasedPolicyLoader::InitWatcher() { 122 void FileBasedPolicyLoader::InitOnFileThread() {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
126 watcher_.reset(new FilePathWatcher); 124 watcher_.reset(new FilePathWatcher);
127 if (!config_file_path().empty() && 125 if (!config_file_path().empty() &&
128 !watcher_->Watch(config_file_path(), 126 !watcher_->Watch(config_file_path(),
129 new FileBasedPolicyWatcherDelegate(this))) { 127 new FileBasedPolicyWatcherDelegate(this))) {
130 OnError(); 128 OnError();
131 } 129 }
132 130
133 // There might have been changes to the directory in the time between 131 // There might have been changes to the directory in the time between
134 // construction of the loader and initialization of the watcher. Call reload 132 // construction of the loader and initialization of the watcher. Call reload
135 // to detect if that is the case. 133 // to detect if that is the case.
136 Reload(); 134 Reload();
135
136 ScheduleFallbackReloadTask();
137 } 137 }
138 138
139 void FileBasedPolicyLoader::StopOnFileThread() { 139 void FileBasedPolicyLoader::StopOnFileThread() {
140 watcher_.reset(); 140 watcher_.reset();
141 if (reload_task_) { 141 if (reload_task_) {
142 reload_task_->Cancel(); 142 reload_task_->Cancel();
143 reload_task_ = NULL; 143 reload_task_ = NULL;
144 } 144 }
145 } 145 }
146 146
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::TimeDelta age = now - last_modification_clock_; 198 base::TimeDelta age = now - last_modification_clock_;
199 if (age < settle_interval_) { 199 if (age < settle_interval_) {
200 *delay = settle_interval_ - age; 200 *delay = settle_interval_ - age;
201 return false; 201 return false;
202 } 202 }
203 203
204 return true; 204 return true;
205 } 205 }
206 206
207 } // namespace policy 207 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/file_based_policy_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698