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

Side by Side Diff: remoting/host/policy_hack/policy_watcher_linux.cc

Issue 14299011: Remove all but one use of WeakPtrFactory::DetachFromThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove checks for death with correct error, which seem to fail on iOS 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
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.cc ('k') | ui/gl/gl_surface_glx.cc » ('j') | 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 // Most of this code is copied from various classes in 5 // Most of this code is copied from various classes in
6 // src/chrome/browser/policy. In particular, look at 6 // src/chrome/browser/policy. In particular, look at
7 // 7 //
8 // file_based_policy_loader.{h,cc} 8 // file_based_policy_loader.{h,cc}
9 // config_dir_policy_provider.{h,cc} 9 // config_dir_policy_provider.{h,cc}
10 // 10 //
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 } // namespace 45 } // namespace
46 46
47 class PolicyWatcherLinux : public PolicyWatcher { 47 class PolicyWatcherLinux : public PolicyWatcher {
48 public: 48 public:
49 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 49 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
50 const base::FilePath& config_dir) 50 const base::FilePath& config_dir)
51 : PolicyWatcher(task_runner), 51 : PolicyWatcher(task_runner),
52 config_dir_(config_dir), 52 config_dir_(config_dir),
53 weak_factory_(this) { 53 weak_factory_(this) {
54 // Detach the factory because we ensure that only the policy thread ever
55 // calls methods on this. Also, the API contract of having to call
56 // StopWatching() (which signals completion) after StartWatching()
57 // before this object can be destructed ensures there are no users of
58 // this object before it is destructed.
59 weak_factory_.DetachFromThread();
60 } 54 }
61 55
62 virtual ~PolicyWatcherLinux() {} 56 virtual ~PolicyWatcherLinux() {}
63 57
64 protected: 58 protected:
65 virtual void StartWatchingInternal() OVERRIDE { 59 virtual void StartWatchingInternal() OVERRIDE {
66 DCHECK(OnPolicyWatcherThread()); 60 DCHECK(OnPolicyWatcherThread());
67 watcher_.reset(new base::FilePathWatcher()); 61 watcher_.reset(new base::FilePathWatcher());
68 62
69 if (!config_dir_.empty() && 63 if (!config_dir_.empty() &&
70 !watcher_->Watch( 64 !watcher_->Watch(
71 config_dir_, false, 65 config_dir_, false,
72 base::Bind(&PolicyWatcherLinux::OnFilePathChanged, 66 base::Bind(&PolicyWatcherLinux::OnFilePathChanged,
73 weak_factory_.GetWeakPtr()))) { 67 weak_factory_.GetWeakPtr()))) {
74 OnFilePathChanged(config_dir_, true); 68 OnFilePathChanged(config_dir_, true);
75 } 69 }
76 70
77 // There might have been changes to the directory in the time between 71 // There might have been changes to the directory in the time between
78 // construction of the loader and initialization of the watcher. Call reload 72 // construction of the loader and initialization of the watcher. Call reload
79 // to detect if that is the case. 73 // to detect if that is the case.
80 Reload(); 74 Reload();
81 75
82 ScheduleFallbackReloadTask(); 76 ScheduleFallbackReloadTask();
83 } 77 }
84 78
85 virtual void StopWatchingInternal() OVERRIDE { 79 virtual void StopWatchingInternal() OVERRIDE {
86 DCHECK(OnPolicyWatcherThread()); 80 DCHECK(OnPolicyWatcherThread());
87 // Cancel any inflight requests. 81
82 // Stop watching for changes to files in the policies directory.
88 watcher_.reset(); 83 watcher_.reset();
84
85 // Orphan any pending OnFilePathChanged tasks.
86 weak_factory_.InvalidateWeakPtrs();
89 } 87 }
90 88
91 private: 89 private:
92 void OnFilePathChanged(const base::FilePath& path, bool error) { 90 void OnFilePathChanged(const base::FilePath& path, bool error) {
93 DCHECK(OnPolicyWatcherThread()); 91 DCHECK(OnPolicyWatcherThread());
94 92
95 if (!error) 93 if (!error)
96 Reload(); 94 Reload();
97 else 95 else
98 LOG(ERROR) << "PolicyWatcherLinux on " << path.value() << " failed."; 96 LOG(ERROR) << "PolicyWatcherLinux on " << path.value() << " failed.";
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 }; 244 };
247 245
248 PolicyWatcher* PolicyWatcher::Create( 246 PolicyWatcher* PolicyWatcher::Create(
249 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 247 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
250 base::FilePath policy_dir(kPolicyDir); 248 base::FilePath policy_dir(kPolicyDir);
251 return new PolicyWatcherLinux(task_runner, policy_dir); 249 return new PolicyWatcherLinux(task_runner, policy_dir);
252 } 250 }
253 251
254 } // namespace policy_hack 252 } // namespace policy_hack
255 } // namespace remoting 253 } // namespace remoting
OLDNEW
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.cc ('k') | ui/gl/gl_surface_glx.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698