| 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" | |
| 16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "remoting/host/dns_blackhole_checker.h" | 17 #include "remoting/host/dns_blackhole_checker.h" |
| 19 | 18 |
| 20 #if !defined(NDEBUG) | 19 #if !defined(NDEBUG) |
| 21 #include "base/json/json_reader.h" | 20 #include "base/json/json_reader.h" |
| 22 #endif | 21 #endif |
| 23 | 22 |
| 24 namespace remoting { | 23 namespace remoting { |
| 25 namespace policy_hack { | 24 namespace policy_hack { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 base::Bind(&PolicyWatcher::StartWatching, | 157 base::Bind(&PolicyWatcher::StartWatching, |
| 159 base::Unretained(this), | 158 base::Unretained(this), |
| 160 policy_callback)); | 159 policy_callback)); |
| 161 return; | 160 return; |
| 162 } | 161 } |
| 163 | 162 |
| 164 policy_callback_ = policy_callback; | 163 policy_callback_ = policy_callback; |
| 165 StartWatchingInternal(); | 164 StartWatchingInternal(); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void PolicyWatcher::StopWatching(base::WaitableEvent* done) { | 167 void PolicyWatcher::StopWatching(const base::Closure& stopped_callback) { |
| 169 if (!OnPolicyWatcherThread()) { | 168 if (!OnPolicyWatcherThread()) { |
| 170 task_runner_->PostTask(FROM_HERE, | 169 task_runner_->PostTask(FROM_HERE, |
| 171 base::Bind(&PolicyWatcher::StopWatching, | 170 base::Bind(&PolicyWatcher::StopWatching, |
| 172 base::Unretained(this), done)); | 171 base::Unretained(this), |
| 172 stopped_callback)); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 StopWatchingInternal(); | 176 StopWatchingInternal(); |
| 177 weak_factory_.InvalidateWeakPtrs(); | 177 weak_factory_.InvalidateWeakPtrs(); |
| 178 policy_callback_.Reset(); | 178 policy_callback_.Reset(); |
| 179 | 179 stopped_callback.Run(); |
| 180 done->Signal(); | |
| 181 } | 180 } |
| 182 | 181 |
| 183 void PolicyWatcher::ScheduleFallbackReloadTask() { | 182 void PolicyWatcher::ScheduleFallbackReloadTask() { |
| 184 DCHECK(OnPolicyWatcherThread()); | 183 DCHECK(OnPolicyWatcherThread()); |
| 185 ScheduleReloadTask( | 184 ScheduleReloadTask( |
| 186 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); | 185 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); |
| 187 } | 186 } |
| 188 | 187 |
| 189 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { | 188 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { |
| 190 DCHECK(OnPolicyWatcherThread()); | 189 DCHECK(OnPolicyWatcherThread()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 old_policies_.swap(new_policies); | 227 old_policies_.swap(new_policies); |
| 229 | 228 |
| 230 // Notify our client of the changed policies. | 229 // Notify our client of the changed policies. |
| 231 if (!changed_policies->empty()) { | 230 if (!changed_policies->empty()) { |
| 232 policy_callback_.Run(changed_policies.Pass()); | 231 policy_callback_.Run(changed_policies.Pass()); |
| 233 } | 232 } |
| 234 } | 233 } |
| 235 | 234 |
| 236 } // namespace policy_hack | 235 } // namespace policy_hack |
| 237 } // namespace remoting | 236 } // namespace remoting |
| OLD | NEW |