| 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 #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_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 34 ConfigurationPolicyProvider::Init(); | 34 ConfigurationPolicyProvider::Init(); |
| 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::MessageLoopProxy::current(), |
| 42 weak_factory_.GetWeakPtr()); | 42 weak_factory_.GetWeakPtr()); |
| 43 BrowserThread::PostTask( | 43 bool post = BrowserThread::PostTask( |
| 44 BrowserThread::FILE, FROM_HERE, | 44 BrowserThread::FILE, FROM_HERE, |
| 45 base::Bind(&AsyncPolicyLoader::Init, | 45 base::Bind(&AsyncPolicyLoader::Init, |
| 46 base::Unretained(loader_), | 46 base::Unretained(loader_), |
| 47 callback)); | 47 callback)); |
| 48 DCHECK(post) << "AsyncPolicyProvider::Init() called with threads not running"; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void AsyncPolicyProvider::Shutdown() { | 51 void AsyncPolicyProvider::Shutdown() { |
| 51 DCHECK(CalledOnValidThread()); | 52 DCHECK(CalledOnValidThread()); |
| 52 // Note on the lifetime of |loader_|: | 53 // Note on the lifetime of |loader_|: |
| 53 // The |loader_| lives on the FILE thread, and is deleted from here. This | 54 // The |loader_| lives on the FILE thread, and is deleted from here. This |
| 54 // means that posting tasks on the |loader_| to FILE from the | 55 // means that posting tasks on the |loader_| to FILE from the |
| 55 // AsyncPolicyProvider is always safe, since a potential DeleteSoon() is only | 56 // AsyncPolicyProvider is always safe, since a potential DeleteSoon() is only |
| 56 // posted from here. The |loader_| posts back to the AsyncPolicyProvider | 57 // posted from here. The |loader_| posts back to the AsyncPolicyProvider |
| 57 // through the |update_callback_|, which has a WeakPtr to |this|. | 58 // through the |update_callback_|, which has a WeakPtr to |this|. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 base::WeakPtr<AsyncPolicyProvider> weak_this, | 118 base::WeakPtr<AsyncPolicyProvider> weak_this, |
| 118 scoped_ptr<PolicyBundle> bundle) { | 119 scoped_ptr<PolicyBundle> bundle) { |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 120 loop->PostTask(FROM_HERE, | 121 loop->PostTask(FROM_HERE, |
| 121 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded, | 122 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded, |
| 122 weak_this, | 123 weak_this, |
| 123 base::Passed(&bundle))); | 124 base::Passed(&bundle))); |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace policy | 127 } // namespace policy |
| OLD | NEW |