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

Side by Side Diff: base/callback.h

Issue 11411319: Correct misleading definition of 'closure' in base/bind documentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « no previous file | base/callback.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py callback.h.pump 2 // pump.py callback.h.pump
3 // DO NOT EDIT BY HAND!!! 3 // DO NOT EDIT BY HAND!!!
4 4
5 5
6 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 6 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be 7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. 8 // found in the LICENSE file.
9 9
10 #ifndef BASE_CALLBACK_H_ 10 #ifndef BASE_CALLBACK_H_
11 #define BASE_CALLBACK_H_ 11 #define BASE_CALLBACK_H_
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/callback_internal.h" 14 #include "base/callback_internal.h"
15 #include "base/template_util.h" 15 #include "base/template_util.h"
16 16
17 // NOTE: Header files that do not require the full definition of Callback or 17 // NOTE: Header files that do not require the full definition of Callback or
18 // Closure should #include "base/callback_forward.h" instead of this file. 18 // Closure should #include "base/callback_forward.h" instead of this file.
19 19
20 // ----------------------------------------------------------------------------- 20 // -----------------------------------------------------------------------------
21 // Introduction 21 // Introduction
22 // ----------------------------------------------------------------------------- 22 // -----------------------------------------------------------------------------
23 // 23 //
24 // The templated Callback class is a generalized function object. Together 24 // The templated Callback class is a generalized function object. Together
25 // with the Bind() function in bind.h, they provide a type-safe method for 25 // with the Bind() function in bind.h, they provide a type-safe method for
26 // performing currying of arguments, and creating a "closure." 26 // performing partial application of functions.
27 // 27 //
28 // In programming languages, a closure is a first-class function where all its 28 // Partial application (or "currying") is the process of binding a subset of
29 // parameters have been bound (usually via currying). Closures are well 29 // a function's arguments to produce another function that takes fewer
30 // suited for representing, and passing around a unit of delayed execution. 30 // arguments. This can be used to pass around a unit of delayed execution,
31 // They are used in Chromium code to schedule tasks on different MessageLoops. 31 // much like lexical closures are used in other languages. For example, it
32 // is used in Chromium code to schedule tasks on different MessageLoops.
32 // 33 //
34 // A callback with no unbound input parameters (base::Callback<void(void)>)
35 // is called a base::Closure. Note that this is NOT the same as what other
36 // languages refer to as a closure -- it does not retain a reference to its
37 // enclosing environment.
33 // 38 //
34 // MEMORY MANAGEMENT AND PASSING 39 // MEMORY MANAGEMENT AND PASSING
35 // 40 //
36 // The Callback objects themselves should be passed by const-reference, and 41 // The Callback objects themselves should be passed by const-reference, and
37 // stored by copy. They internally store their state via a refcounted class 42 // stored by copy. They internally store their state via a refcounted class
38 // and thus do not need to be deleted. 43 // and thus do not need to be deleted.
39 // 44 //
40 // The reason to pass via a const-reference is to avoid unnecessary 45 // The reason to pass via a const-reference is to avoid unnecessary
41 // AddRef/Release pairs to the internal state. 46 // AddRef/Release pairs to the internal state.
42 // 47 //
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // - Returning an Callback<> with an arity matching the number of unbound 268 // - Returning an Callback<> with an arity matching the number of unbound
264 // parameters and that knows the correct refcounting semantics for the 269 // parameters and that knows the correct refcounting semantics for the
265 // target object if we are binding a method. 270 // target object if we are binding a method.
266 // 271 //
267 // The Bind functions do the above using type-inference, and template 272 // The Bind functions do the above using type-inference, and template
268 // specializations. 273 // specializations.
269 // 274 //
270 // By default Bind() will store copies of all bound parameters, and attempt 275 // By default Bind() will store copies of all bound parameters, and attempt
271 // to refcount a target object if the function being bound is a class method. 276 // to refcount a target object if the function being bound is a class method.
272 // These copies are created even if the function takes parameters as const 277 // These copies are created even if the function takes parameters as const
273 // references. (Binding to non-const references is forbidden, see bind.h) 278 // references. (Binding to non-const references is forbidden, see bind.h.)
274 // 279 //
275 // To change this behavior, we introduce a set of argument wrappers 280 // To change this behavior, we introduce a set of argument wrappers
276 // (e.g., Unretained(), and ConstRef()). These are simple container templates 281 // (e.g., Unretained(), and ConstRef()). These are simple container templates
277 // that are passed by value, and wrap a pointer to argument. See the 282 // that are passed by value, and wrap a pointer to argument. See the
278 // file-level comment in base/bind_helpers.h for more info. 283 // file-level comment in base/bind_helpers.h for more info.
279 // 284 //
280 // These types are passed to the Unwrap() functions, and the MaybeRefcount() 285 // These types are passed to the Unwrap() functions, and the MaybeRefcount()
281 // functions respectively to modify the behavior of Bind(). The Unwrap() 286 // functions respectively to modify the behavior of Bind(). The Unwrap()
282 // and MaybeRefcount() functions change behavior by doing partial 287 // and MaybeRefcount() functions change behavior by doing partial
283 // specialization based on whether or not a parameter is a wrapper type. 288 // specialization based on whether or not a parameter is a wrapper type.
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 }; 756 };
752 757
753 758
754 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it 759 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it
755 // will be used in a lot of APIs with delayed execution. 760 // will be used in a lot of APIs with delayed execution.
756 typedef Callback<void(void)> Closure; 761 typedef Callback<void(void)> Closure;
757 762
758 } // namespace base 763 } // namespace base
759 764
760 #endif // BASE_CALLBACK_H 765 #endif // BASE_CALLBACK_H
OLDNEW
« no previous file with comments | « no previous file | base/callback.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698