]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/base/cef_callback_helpers.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / base / cef_callback_helpers.h
1 // Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2012
2 // Google Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //    * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //    * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //    * Neither the name of Google Inc. nor the name Chromium Embedded
15 // Framework nor the names of its contributors may be used to endorse
16 // or promote products derived from this software without specific prior
17 // written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 // This defines helpful methods for dealing with Callbacks.  Because Callbacks
32 // are implemented using templates, with a class per callback signature, adding
33 // methods to Callback<> itself is unattractive (lots of extra code gets
34 // generated).  Instead, consider adding methods here.
35 //
36 // ResetAndReturn(&cb) is like cb.Reset() but allows executing a callback (via a
37 // copy) after the original callback is Reset().  This can be handy if Run()
38 // reads/writes the variable holding the Callback.
39
40 #ifndef CEF_INCLUDE_BASE_CEF_CALLBACK_HELPERS_H_
41 #define CEF_INCLUDE_BASE_CEF_CALLBACK_HELPERS_H_
42 #pragma once
43
44 #if defined(BASE_CALLBACK_HELPERS_H_)
45 // Do nothing if the Chromium header has already been included.
46 // This can happen in cases where Chromium code is used directly by the
47 // client application. When using Chromium code directly always include
48 // the Chromium header first to avoid type conflicts.
49 #elif defined(BUILDING_CEF_SHARED)
50 // When building CEF include the Chromium header directly.
51 #include "base/callback_helpers.h"
52 #else  // !BUILDING_CEF_SHARED
53 // The following is substantially similar to the Chromium implementation.
54 // If the Chromium implementation diverges the below implementation should be
55 // updated to match.
56
57 #include "include/base/cef_basictypes.h"
58 #include "include/base/cef_build.h"
59 #include "include/base/cef_callback.h"
60 #include "include/base/cef_macros.h"
61
62 namespace base {
63
64 template <typename Sig>
65 base::Callback<Sig> ResetAndReturn(base::Callback<Sig>* cb) {
66   base::Callback<Sig> ret(*cb);
67   cb->Reset();
68   return ret;
69 }
70
71 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the
72 // Closure is executed and deleted no matter how the current scope exits.
73 class ScopedClosureRunner {
74  public:
75   ScopedClosureRunner();
76   explicit ScopedClosureRunner(const Closure& closure);
77   ~ScopedClosureRunner();
78
79   void Reset();
80   void Reset(const Closure& closure);
81   Closure Release() WARN_UNUSED_RESULT;
82
83  private:
84   Closure closure_;
85
86   DISALLOW_COPY_AND_ASSIGN(ScopedClosureRunner);
87 };
88
89 }  // namespace base
90
91 #endif  // !BUILDING_CEF_SHARED
92
93 #endif  // CEF_INCLUDE_BASE_CEF_CALLBACK_HELPERS_H_