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

Side by Side Diff: components/policy/core/common/async_policy_provider.cc

Issue 1130753002: [components/policy] Use ThreadTaskRunnerHandle instead of LoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/policy/core/common/async_policy_provider.h" 5 #include "components/policy/core/common/async_policy_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "components/policy/core/common/async_policy_loader.h" 13 #include "components/policy/core/common/async_policy_loader.h"
14 #include "components/policy/core/common/policy_bundle.h" 14 #include "components/policy/core/common/policy_bundle.h"
15 #include "components/policy/core/common/schema_registry.h" 15 #include "components/policy/core/common/schema_registry.h"
16 16
17 namespace policy { 17 namespace policy {
18 18
19 AsyncPolicyProvider::AsyncPolicyProvider( 19 AsyncPolicyProvider::AsyncPolicyProvider(
20 SchemaRegistry* registry, 20 SchemaRegistry* registry,
21 scoped_ptr<AsyncPolicyLoader> loader) 21 scoped_ptr<AsyncPolicyLoader> loader)
22 : loader_(loader.Pass()), 22 : loader_(loader.Pass()),
23 weak_factory_(this) { 23 weak_factory_(this) {
24 // Make an immediate synchronous load on startup. 24 // Make an immediate synchronous load on startup.
25 OnLoaderReloaded(loader_->InitialLoad(registry->schema_map())); 25 OnLoaderReloaded(loader_->InitialLoad(registry->schema_map()));
26 } 26 }
27 27
28 AsyncPolicyProvider::~AsyncPolicyProvider() { 28 AsyncPolicyProvider::~AsyncPolicyProvider() {
29 DCHECK(CalledOnValidThread()); 29 DCHECK(CalledOnValidThread());
30 } 30 }
31 31
32 void AsyncPolicyProvider::Init(SchemaRegistry* registry) { 32 void AsyncPolicyProvider::Init(SchemaRegistry* registry) {
33 DCHECK(CalledOnValidThread()); 33 DCHECK(CalledOnValidThread());
34 ConfigurationPolicyProvider::Init(registry); 34 ConfigurationPolicyProvider::Init(registry);
35 35
36 if (!loader_) 36 if (!loader_)
37 return; 37 return;
38 38
39 AsyncPolicyLoader::UpdateCallback callback = 39 AsyncPolicyLoader::UpdateCallback callback =
40 base::Bind(&AsyncPolicyProvider::LoaderUpdateCallback, 40 base::Bind(&AsyncPolicyProvider::LoaderUpdateCallback,
41 base::MessageLoopProxy::current(), 41 base::ThreadTaskRunnerHandle::Get(),
42 weak_factory_.GetWeakPtr()); 42 weak_factory_.GetWeakPtr());
43 bool post = loader_->task_runner()->PostTask( 43 bool post = loader_->task_runner()->PostTask(
44 FROM_HERE, 44 FROM_HERE,
45 base::Bind(&AsyncPolicyLoader::Init, 45 base::Bind(&AsyncPolicyLoader::Init,
46 base::Unretained(loader_.get()), 46 base::Unretained(loader_.get()),
47 callback)); 47 callback));
48 DCHECK(post) << "AsyncPolicyProvider::Init() called with threads not running"; 48 DCHECK(post) << "AsyncPolicyProvider::Init() called with threads not running";
49 } 49 }
50 50
51 void AsyncPolicyProvider::Shutdown() { 51 void AsyncPolicyProvider::Shutdown() {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void AsyncPolicyProvider::OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle) { 113 void AsyncPolicyProvider::OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle) {
114 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
115 // Only propagate policy updates if there are no pending refreshes, and if 115 // Only propagate policy updates if there are no pending refreshes, and if
116 // Shutdown() hasn't been called yet. 116 // Shutdown() hasn't been called yet.
117 if (refresh_callback_.IsCancelled() && loader_) 117 if (refresh_callback_.IsCancelled() && loader_)
118 UpdatePolicy(bundle.Pass()); 118 UpdatePolicy(bundle.Pass());
119 } 119 }
120 120
121 // static 121 // static
122 void AsyncPolicyProvider::LoaderUpdateCallback( 122 void AsyncPolicyProvider::LoaderUpdateCallback(
123 scoped_refptr<base::MessageLoopProxy> loop, 123 scoped_refptr<base::SingleThreadTaskRunner> runner,
124 base::WeakPtr<AsyncPolicyProvider> weak_this, 124 base::WeakPtr<AsyncPolicyProvider> weak_this,
125 scoped_ptr<PolicyBundle> bundle) { 125 scoped_ptr<PolicyBundle> bundle) {
126 loop->PostTask(FROM_HERE, 126 runner->PostTask(FROM_HERE,
127 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded, 127 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded,
128 weak_this, 128 weak_this,
129 base::Passed(&bundle))); 129 base::Passed(&bundle)));
130 } 130 }
131 131
132 } // namespace policy 132 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/async_policy_provider.h ('k') | components/policy/core/common/cloud/cloud_policy_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698