OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Most of this code is copied from: | 5 // Most of this code is copied from: |
6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc} | 6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc} |
7 | 7 |
8 #include "remoting/host/policy_hack/policy_watcher.h" | 8 #include "remoting/host/policy_hack/policy_watcher.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/synchronization/waitable_event.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "remoting/host/dns_blackhole_checker.h" | 18 #include "remoting/host/dns_blackhole_checker.h" |
18 | 19 |
19 #if !defined(NDEBUG) | 20 #if !defined(NDEBUG) |
20 #include "base/json/json_reader.h" | 21 #include "base/json/json_reader.h" |
21 #endif | 22 #endif |
22 | 23 |
23 namespace remoting { | 24 namespace remoting { |
24 namespace policy_hack { | 25 namespace policy_hack { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 base::Bind(&PolicyWatcher::StartWatching, | 158 base::Bind(&PolicyWatcher::StartWatching, |
158 base::Unretained(this), | 159 base::Unretained(this), |
159 policy_callback)); | 160 policy_callback)); |
160 return; | 161 return; |
161 } | 162 } |
162 | 163 |
163 policy_callback_ = policy_callback; | 164 policy_callback_ = policy_callback; |
164 StartWatchingInternal(); | 165 StartWatchingInternal(); |
165 } | 166 } |
166 | 167 |
167 void PolicyWatcher::StopWatching(const base::Closure& stopped_callback) { | 168 void PolicyWatcher::StopWatching(base::WaitableEvent* done) { |
168 task_runner_->PostTaskAndReply( | 169 if (!OnPolicyWatcherThread()) { |
169 FROM_HERE, base::Bind(&PolicyWatcher::StopWatchingOnPolicyWatcherThread, | 170 task_runner_->PostTask(FROM_HERE, |
170 base::Unretained(this)), | 171 base::Bind(&PolicyWatcher::StopWatching, |
171 stopped_callback); | 172 base::Unretained(this), done)); |
172 } | 173 return; |
| 174 } |
173 | 175 |
174 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { | |
175 StopWatchingInternal(); | 176 StopWatchingInternal(); |
176 weak_factory_.InvalidateWeakPtrs(); | 177 weak_factory_.InvalidateWeakPtrs(); |
177 policy_callback_.Reset(); | 178 policy_callback_.Reset(); |
| 179 |
| 180 done->Signal(); |
178 } | 181 } |
179 | 182 |
180 void PolicyWatcher::ScheduleFallbackReloadTask() { | 183 void PolicyWatcher::ScheduleFallbackReloadTask() { |
181 DCHECK(OnPolicyWatcherThread()); | 184 DCHECK(OnPolicyWatcherThread()); |
182 ScheduleReloadTask( | 185 ScheduleReloadTask( |
183 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); | 186 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); |
184 } | 187 } |
185 | 188 |
186 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { | 189 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { |
187 DCHECK(OnPolicyWatcherThread()); | 190 DCHECK(OnPolicyWatcherThread()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 old_policies_.swap(new_policies); | 228 old_policies_.swap(new_policies); |
226 | 229 |
227 // Notify our client of the changed policies. | 230 // Notify our client of the changed policies. |
228 if (!changed_policies->empty()) { | 231 if (!changed_policies->empty()) { |
229 policy_callback_.Run(changed_policies.Pass()); | 232 policy_callback_.Run(changed_policies.Pass()); |
230 } | 233 } |
231 } | 234 } |
232 | 235 |
233 } // namespace policy_hack | 236 } // namespace policy_hack |
234 } // namespace remoting | 237 } // namespace remoting |
OLD | NEW |