Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / drive_backend / callback_tracker_internal.h.pump
1 $$ This is a pump file for generating file templates.  Pump is a python
2 $$ script that is part of the Google Test suite of utilities.  Description
3 $$ can be found here:
4 $$
5 $$ http://code.google.com/p/googletest/wiki/PumpManual
6 $$
7 $$ See comment for MAX_ARITY in base/bind.h.pump.
8 $var MAX_ARITY = 7
9
10 // Copyright 2014 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file.
13
14 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_
15 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_
16
17 #include "base/callback.h"
18 #include "base/callback_internal.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/weak_ptr.h"
21
22 namespace sync_file_system {
23 namespace drive_backend {
24
25 class CallbackTracker;
26
27 namespace internal {
28
29 class AbortHelper {
30  public:
31   explicit AbortHelper(CallbackTracker* tracker);
32   ~AbortHelper();
33   base::WeakPtr<AbortHelper> AsWeakPtr();
34
35   static scoped_ptr<AbortHelper> TakeOwnership(
36       const base::WeakPtr<AbortHelper>& abort_helper);
37
38  private:
39   CallbackTracker* tracker_;  // Not owned.
40   base::WeakPtrFactory<AbortHelper> weak_ptr_factory_;
41
42   DISALLOW_COPY_AND_ASSIGN(AbortHelper);
43 };
44
45 template <typename>
46 struct InvokeAndInvalidateHelper;
47
48 $range ARITY 0..MAX_ARITY
49 $for ARITY [[
50 $range ARG 1..ARITY
51
52 template <$for ARG , [[typename A$(ARG)]]>
53 struct InvokeAndInvalidateHelper<void($for ARG , [[A$(ARG)]])> {
54   static void Run(const base::WeakPtr<AbortHelper>& abort_helper,
55                   const base::Callback<void($for ARG , [[A$(ARG)]])>& callback
56 $if ARITY != 0 [[, ]]
57 $for ARG , [[A$(ARG) a$(ARG)]]
58 ) {
59     scoped_ptr<AbortHelper> deleter = AbortHelper::TakeOwnership(abort_helper);
60     if (deleter) {
61       callback.Run(
62 $for ARG , [[base::internal::CallbackForward(a$(ARG))]]);
63     }
64   }
65 };
66
67 ]]  $$ for ARITY
68
69 }  // namespace internal
70 }  // namespace drive_backend
71 }  // namespace sync_file_system
72
73 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_