Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / callback_tracker_internal.h
blob665d2c13f042ac51d9f89a368ac40287b5981dd9
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_
8 #include "base/callback.h"
9 #include "base/callback_internal.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
13 namespace sync_file_system {
14 namespace drive_backend {
16 class CallbackTracker;
18 namespace internal {
20 class AbortHelper {
21 public:
22 explicit AbortHelper(CallbackTracker* tracker);
23 ~AbortHelper();
24 base::WeakPtr<AbortHelper> AsWeakPtr();
26 static scoped_ptr<AbortHelper> TakeOwnership(
27 const base::WeakPtr<AbortHelper>& abort_helper);
29 private:
30 CallbackTracker* tracker_; // Not owned.
31 base::WeakPtrFactory<AbortHelper> weak_ptr_factory_;
33 DISALLOW_COPY_AND_ASSIGN(AbortHelper);
36 template <typename>
37 struct InvokeAndInvalidateHelper;
39 template <typename... Args>
40 struct InvokeAndInvalidateHelper<void(Args...)> {
41 static void Run(const base::WeakPtr<AbortHelper>& abort_helper,
42 const base::Callback<void(Args...)>& callback,
43 Args... args) {
44 scoped_ptr<AbortHelper> deleter = AbortHelper::TakeOwnership(abort_helper);
45 if (deleter) {
46 callback.Run(base::internal::CallbackForward(args)...);
51 } // namespace internal
52 } // namespace drive_backend
53 } // namespace sync_file_system
55 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_TRACKER_INTERNAL_H_