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

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

Issue 15061007: Added a PolicyDomainDescriptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | Annotate | Revision Log
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 #include "chrome/browser/policy/async_policy_provider.h" 5 #include "chrome/browser/policy/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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "chrome/browser/policy/async_policy_loader.h" 11 #include "chrome/browser/policy/async_policy_loader.h"
12 #include "chrome/browser/policy/policy_bundle.h" 12 #include "chrome/browser/policy/policy_bundle.h"
13 #include "chrome/browser/policy/policy_domain_descriptor.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 17
17 namespace policy { 18 namespace policy {
18 19
19 AsyncPolicyProvider::AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader> loader) 20 AsyncPolicyProvider::AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader> loader)
20 : loader_(loader.release()), 21 : loader_(loader.release()),
21 weak_factory_(this) { 22 weak_factory_(this) {
22 // Make an immediate synchronous load on startup. 23 // Make an immediate synchronous load on startup.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // made before this call. So if a caller has modified the policy settings and 73 // made before this call. So if a caller has modified the policy settings and
73 // invoked RefreshPolicies(), then by the next notification these policies 74 // invoked RefreshPolicies(), then by the next notification these policies
74 // should already be provided. 75 // should already be provided.
75 // However, it's also possible that an asynchronous Reload() is in progress 76 // However, it's also possible that an asynchronous Reload() is in progress
76 // and just posted OnLoaderReloaded(). Therefore a task is posted to the 77 // and just posted OnLoaderReloaded(). Therefore a task is posted to the
77 // FILE thread before posting the next Reload, to prevent a potential 78 // FILE thread before posting the next Reload, to prevent a potential
78 // concurrent Reload() from triggering a notification too early. If another 79 // concurrent Reload() from triggering a notification too early. If another
79 // refresh task has been posted, it is invalidated now. 80 // refresh task has been posted, it is invalidated now.
80 refresh_callback_.Reset( 81 refresh_callback_.Reset(
81 base::Bind(&AsyncPolicyProvider::ReloadAfterRefreshSync, 82 base::Bind(&AsyncPolicyProvider::ReloadAfterRefreshSync,
82 base::Unretained(this))); 83 weak_factory_.GetWeakPtr()));
83 BrowserThread::PostTaskAndReply( 84 BrowserThread::PostTaskAndReply(
84 BrowserThread::FILE, FROM_HERE, 85 BrowserThread::FILE, FROM_HERE,
85 base::Bind(base::DoNothing), 86 base::Bind(base::DoNothing),
86 refresh_callback_.callback()); 87 refresh_callback_.callback());
87 } 88 }
88 89
90 void AsyncPolicyProvider::RegisterPolicyDomain(
91 scoped_refptr<const PolicyDomainDescriptor> descriptor) {
92 if (loader_) {
93 BrowserThread::PostTask(BrowserThread::FILE,
94 FROM_HERE,
95 base::Bind(&AsyncPolicyLoader::RegisterPolicyDomain,
96 base::Unretained(loader_),
97 descriptor));
98 }
99 }
100
89 void AsyncPolicyProvider::ReloadAfterRefreshSync() { 101 void AsyncPolicyProvider::ReloadAfterRefreshSync() {
90 DCHECK(CalledOnValidThread()); 102 DCHECK(CalledOnValidThread());
91 // This task can only enter if it was posted from RefreshPolicies(), and it 103 // This task can only enter if it was posted from RefreshPolicies(), and it
92 // hasn't been cancelled meanwhile by another call to RefreshPolicies(). 104 // hasn't been cancelled meanwhile by another call to RefreshPolicies().
93 DCHECK(!refresh_callback_.IsCancelled()); 105 DCHECK(!refresh_callback_.IsCancelled());
94 // There can't be another refresh callback pending now, since its creation 106 // There can't be another refresh callback pending now, since its creation
95 // in RefreshPolicies() would have cancelled the current execution. So it's 107 // in RefreshPolicies() would have cancelled the current execution. So it's
96 // safe to cancel the |refresh_callback_| now, so that OnLoaderReloaded() 108 // safe to cancel the |refresh_callback_| now, so that OnLoaderReloaded()
97 // sees that there is no refresh pending. 109 // sees that there is no refresh pending.
98 refresh_callback_.Cancel(); 110 refresh_callback_.Cancel();
(...skipping 22 matching lines...) Expand all
121 base::WeakPtr<AsyncPolicyProvider> weak_this, 133 base::WeakPtr<AsyncPolicyProvider> weak_this,
122 scoped_ptr<PolicyBundle> bundle) { 134 scoped_ptr<PolicyBundle> bundle) {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
124 loop->PostTask(FROM_HERE, 136 loop->PostTask(FROM_HERE,
125 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded, 137 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded,
126 weak_this, 138 weak_this,
127 base::Passed(&bundle))); 139 base::Passed(&bundle)));
128 } 140 }
129 141
130 } // namespace policy 142 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/async_policy_provider.h ('k') | chrome/browser/policy/browser_policy_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698