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

Side by Side Diff: remoting/host/policy_hack/policy_watcher.cc

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedbacks Created 6 years, 2 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
OLDNEW
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
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()) {
Wez 2014/10/17 17:58:01 This kind of trampoline doesn't need a separate fu
kelvinp 2014/10/20 00:21:18 I use PostTaskAndReply as I want the callback is b
170 task_runner_->PostTask(FROM_HERE, 169 task_runner_->PostTaskAndReply(
171 base::Bind(&PolicyWatcher::StopWatching, 170 FROM_HERE,
172 base::Unretained(this), done)); 171 base::Bind(&PolicyWatcher::StopWatchingOnPolicyWatcherThread,
172 base::Unretained(this)),
173 stopped_callback);
173 return; 174 return;
174 } 175 }
176 StopWatchingOnPolicyWatcherThread();
177 stopped_callback.Run();
178 }
175 179
180 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() {
176 StopWatchingInternal(); 181 StopWatchingInternal();
177 weak_factory_.InvalidateWeakPtrs(); 182 weak_factory_.InvalidateWeakPtrs();
178 policy_callback_.Reset(); 183 policy_callback_.Reset();
179
180 done->Signal();
181 } 184 }
182 185
183 void PolicyWatcher::ScheduleFallbackReloadTask() { 186 void PolicyWatcher::ScheduleFallbackReloadTask() {
184 DCHECK(OnPolicyWatcherThread()); 187 DCHECK(OnPolicyWatcherThread());
185 ScheduleReloadTask( 188 ScheduleReloadTask(
186 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); 189 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes));
187 } 190 }
188 191
189 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { 192 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) {
190 DCHECK(OnPolicyWatcherThread()); 193 DCHECK(OnPolicyWatcherThread());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 old_policies_.swap(new_policies); 231 old_policies_.swap(new_policies);
229 232
230 // Notify our client of the changed policies. 233 // Notify our client of the changed policies.
231 if (!changed_policies->empty()) { 234 if (!changed_policies->empty()) {
232 policy_callback_.Run(changed_policies.Pass()); 235 policy_callback_.Run(changed_policies.Pass());
233 } 236 }
234 } 237 }
235 238
236 } // namespace policy_hack 239 } // namespace policy_hack
237 } // namespace remoting 240 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698