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

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

Issue 8586030: Added ConfigurationPolicyProvider::RefreshPolicies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/asynchronous_policy_provider.h" 5 #include "chrome/browser/policy/asynchronous_policy_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/policy/asynchronous_policy_loader.h" 8 #include "chrome/browser/policy/asynchronous_policy_loader.h"
9 #include "chrome/browser/policy/policy_map.h" 9 #include "chrome/browser/policy/policy_map.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
10 13
11 namespace policy { 14 namespace policy {
12 15
13 AsynchronousPolicyProvider::AsynchronousPolicyProvider( 16 AsynchronousPolicyProvider::AsynchronousPolicyProvider(
14 const PolicyDefinitionList* policy_list, 17 const PolicyDefinitionList* policy_list,
15 scoped_refptr<AsynchronousPolicyLoader> loader) 18 scoped_refptr<AsynchronousPolicyLoader> loader)
16 : ConfigurationPolicyProvider(policy_list), 19 : ConfigurationPolicyProvider(policy_list),
17 loader_(loader) { 20 loader_(loader),
21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
18 loader_->Init( 22 loader_->Init(
19 base::Bind(&AsynchronousPolicyProvider::NotifyPolicyUpdated, 23 base::Bind(&AsynchronousPolicyProvider::OnUnexpectedReload,
20 base::Unretained(this))); 24 base::Unretained(this)));
21 } 25 }
22 26
23 AsynchronousPolicyProvider::~AsynchronousPolicyProvider() { 27 AsynchronousPolicyProvider::~AsynchronousPolicyProvider() {
24 DCHECK(CalledOnValidThread()); 28 DCHECK(CalledOnValidThread());
25 // |loader_| won't invoke its callback anymore after Stop(), therefore 29 // |loader_| won't invoke its callback anymore after Stop(), therefore
26 // Unretained(this) is safe in the ctor. 30 // Unretained(this) is safe in the ctor.
27 loader_->Stop(); 31 loader_->Stop();
28 } 32 }
29 33
30 void AsynchronousPolicyProvider::ForceReload() {
31 loader_->Reload(true);
32 }
33
34 bool AsynchronousPolicyProvider::ProvideInternal(PolicyMap* map) { 34 bool AsynchronousPolicyProvider::ProvideInternal(PolicyMap* map) {
35 DCHECK(CalledOnValidThread()); 35 DCHECK(CalledOnValidThread());
36 DCHECK(loader_->policy()); 36 if (!loader_->policy())
37 return false;
37 map->LoadFrom(loader_->policy(), policy_definition_list()); 38 map->LoadFrom(loader_->policy(), policy_definition_list());
38 return true; 39 return true;
39 } 40 }
40 41
42 void AsynchronousPolicyProvider::RefreshPolicies() {
43 DCHECK(CalledOnValidThread());
44 // Invalidate any pending callbacks issued from here.
45 weak_ptr_factory_.InvalidateWeakPtrs();
46 // Post a new callback with a fresh WeakPtr to Reload.
47 BrowserThread::PostTask(
48 BrowserThread::FILE, FROM_HERE,
49 base::Bind(&AsynchronousPolicyLoader::Reload,
50 loader_,
51 base::Bind(&AsynchronousPolicyProvider::OnRefreshReload,
52 weak_ptr_factory_.GetWeakPtr()),
53 true));
54 }
55
56 void AsynchronousPolicyProvider::OnRefreshReload() {
57 DCHECK(CalledOnValidThread());
58 NotifyPolicyUpdated();
59 }
60
61 void AsynchronousPolicyProvider::OnUnexpectedReload() {
62 DCHECK(CalledOnValidThread());
63 // Don't notify now if we're waiting for a Reload requested from
64 // RefreshPolicies.
65 if (weak_ptr_factory_.HasWeakPtrs())
66 return;
67 NotifyPolicyUpdated();
68 }
69
41 } // namespace policy 70 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698