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

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

Issue 10912017: Fix stack corruption bug in FilePathWatcherTest.Callback. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased, added comment Created 8 years, 3 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
« no previous file with comments | « base/files/file_path_watcher_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_proxy.h" 10 #include "base/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 "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 16
17 namespace policy { 17 namespace policy {
18 18
19 namespace {
20
21 // Helper for a PostTaskAndReply used as a synchronization point between the
22 // main thread and FILE thread. See AsyncPolicyProvider::RefreshPolicies.
23 void Nop() {}
24
25 } // namespace
26
27 AsyncPolicyProvider::AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader> loader) 19 AsyncPolicyProvider::AsyncPolicyProvider(scoped_ptr<AsyncPolicyLoader> loader)
28 : loader_(loader.release()), 20 : loader_(loader.release()),
29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
30 // The FILE thread isn't ready early during startup. Post a task to the 22 // The FILE thread isn't ready early during startup. Post a task to the
31 // current loop to resume initialization on FILE once the loops are spinning. 23 // current loop to resume initialization on FILE once the loops are spinning.
32 MessageLoop::current()->PostTask( 24 MessageLoop::current()->PostTask(
33 FROM_HERE, 25 FROM_HERE,
34 base::Bind(&AsyncPolicyProvider::InitWithLoopsReady, 26 base::Bind(&AsyncPolicyProvider::InitWithLoopsReady,
35 weak_factory_.GetWeakPtr())); 27 weak_factory_.GetWeakPtr()));
36 // Make an immediate synchronous load on startup. 28 // Make an immediate synchronous load on startup.
(...skipping 23 matching lines...) Expand all
60 // However, it's also possible that an asynchronous Reload() is in progress 52 // However, it's also possible that an asynchronous Reload() is in progress
61 // and just posted OnLoaderReloaded(). Therefore a task is posted to the 53 // and just posted OnLoaderReloaded(). Therefore a task is posted to the
62 // FILE thread before posting the next Reload, to prevent a potential 54 // FILE thread before posting the next Reload, to prevent a potential
63 // concurrent Reload() from triggering a notification too early. If another 55 // concurrent Reload() from triggering a notification too early. If another
64 // refresh task has been posted, it is invalidated now. 56 // refresh task has been posted, it is invalidated now.
65 refresh_callback_.Reset( 57 refresh_callback_.Reset(
66 base::Bind(&AsyncPolicyProvider::ReloadAfterRefreshSync, 58 base::Bind(&AsyncPolicyProvider::ReloadAfterRefreshSync,
67 base::Unretained(this))); 59 base::Unretained(this)));
68 BrowserThread::PostTaskAndReply( 60 BrowserThread::PostTaskAndReply(
69 BrowserThread::FILE, FROM_HERE, 61 BrowserThread::FILE, FROM_HERE,
70 base::Bind(Nop), 62 base::Bind(base::DoNothing),
71 refresh_callback_.callback()); 63 refresh_callback_.callback());
72 } 64 }
73 65
74 void AsyncPolicyProvider::InitWithLoopsReady() { 66 void AsyncPolicyProvider::InitWithLoopsReady() {
75 DCHECK(CalledOnValidThread()); 67 DCHECK(CalledOnValidThread());
76 AsyncPolicyLoader::UpdateCallback callback = 68 AsyncPolicyLoader::UpdateCallback callback =
77 base::Bind(&AsyncPolicyProvider::LoaderUpdateCallback, 69 base::Bind(&AsyncPolicyProvider::LoaderUpdateCallback,
78 base::MessageLoopProxy::current(), 70 base::MessageLoopProxy::current(),
79 weak_factory_.GetWeakPtr()); 71 weak_factory_.GetWeakPtr());
80 BrowserThread::PostTask( 72 BrowserThread::PostTask(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 base::WeakPtr<AsyncPolicyProvider> weak_this, 106 base::WeakPtr<AsyncPolicyProvider> weak_this,
115 scoped_ptr<PolicyBundle> bundle) { 107 scoped_ptr<PolicyBundle> bundle) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
117 loop->PostTask(FROM_HERE, 109 loop->PostTask(FROM_HERE,
118 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded, 110 base::Bind(&AsyncPolicyProvider::OnLoaderReloaded,
119 weak_this, 111 weak_this,
120 base::Passed(&bundle))); 112 base::Passed(&bundle)));
121 } 113 }
122 114
123 } // namespace policy 115 } // namespace policy
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698