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

Side by Side Diff: base/callback_helpers.h

Issue 2513363003: repro for crbug.com/663886
Patch Set: Created 4 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
« no previous file with comments | « base/callback_forward.h ('k') | base/callback_helpers.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 // This defines helpful methods for dealing with Callbacks. Because Callbacks 5 // This defines helpful methods for dealing with Callbacks. Because Callbacks
6 // are implemented using templates, with a class per callback signature, adding 6 // are implemented using templates, with a class per callback signature, adding
7 // methods to Callback<> itself is unattractive (lots of extra code gets 7 // methods to Callback<> itself is unattractive (lots of extra code gets
8 // generated). Instead, consider adding methods here. 8 // generated). Instead, consider adding methods here.
9 // 9 //
10 // ResetAndReturn(&cb) is like cb.Reset() but allows executing a callback (via a 10 // ResetAndReturn(&cb) is like cb.Reset() but allows executing a callback (via a
(...skipping 13 matching lines...) Expand all
24 base::Callback<Sig> ResetAndReturn(base::Callback<Sig>* cb) { 24 base::Callback<Sig> ResetAndReturn(base::Callback<Sig>* cb) {
25 base::Callback<Sig> ret(*cb); 25 base::Callback<Sig> ret(*cb);
26 cb->Reset(); 26 cb->Reset();
27 return ret; 27 return ret;
28 } 28 }
29 29
30 // ScopedClosureRunner is akin to std::unique_ptr<> for Closures. It ensures 30 // ScopedClosureRunner is akin to std::unique_ptr<> for Closures. It ensures
31 // that the Closure is executed no matter how the current scope exits. 31 // that the Closure is executed no matter how the current scope exits.
32 class BASE_EXPORT ScopedClosureRunner { 32 class BASE_EXPORT ScopedClosureRunner {
33 public: 33 public:
34 ScopedClosureRunner(); 34 ScopedClosureRunner() {}
35 explicit ScopedClosureRunner(const Closure& closure); 35 explicit ScopedClosureRunner(const Closure& closure) {}
36 ~ScopedClosureRunner(); 36 ~ScopedClosureRunner() {}
37 37
38 ScopedClosureRunner(ScopedClosureRunner&& other); 38 ScopedClosureRunner(ScopedClosureRunner&& other) {}
39 39
40 // Releases the current closure if it's set and replaces it with the closure 40 // Releases the current closure if it's set and replaces it with the closure
41 // from |other|. 41 // from |other|.
42 ScopedClosureRunner& operator=(ScopedClosureRunner&& other); 42 ScopedClosureRunner& operator=(ScopedClosureRunner&& other) {return *this;}
43 43
44 // Calls the current closure and resets it, so it wont be called again. 44 // Calls the current closure and resets it, so it wont be called again.
45 void RunAndReset(); 45 void RunAndReset() {}
46 46
47 // Replaces closure with the new one releasing the old one without calling it. 47 // Replaces closure with the new one releasing the old one without calling it.
48 void ReplaceClosure(const Closure& closure); 48 void ReplaceClosure(const Closure& closure) {}
49 49
50 // Releases the Closure without calling. 50 // Releases the Closure without calling.
51 Closure Release() WARN_UNUSED_RESULT; 51 Closure Release() WARN_UNUSED_RESULT {return Closure();}
52 52
53 private: 53 private:
54 Closure closure_;
55 54
56 DISALLOW_COPY_AND_ASSIGN(ScopedClosureRunner); 55 DISALLOW_COPY_AND_ASSIGN(ScopedClosureRunner);
57 }; 56 };
58 57
59 } // namespace base 58 } // namespace base
60 59
61 #endif // BASE_CALLBACK_HELPERS_H_ 60 #endif // BASE_CALLBACK_HELPERS_H_
OLDNEW
« no previous file with comments | « base/callback_forward.h ('k') | base/callback_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698