| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <type_traits> | 9 #include <type_traits> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 | 17 |
| 18 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h. | 18 // TODO(tzik): Merge this file to media/base/bind_to_current_loop.h. |
| 19 | 19 |
| 20 namespace sync_file_system { | 20 namespace sync_file_system { |
| 21 namespace drive_backend { | 21 namespace drive_backend { |
| 22 | 22 |
| 23 namespace internal { | 23 namespace internal { |
| 24 | 24 |
| 25 template <typename T> | 25 template <typename T> |
| 26 base::internal::PassedWrapper<scoped_ptr<T>> RebindForward(scoped_ptr<T>& t) { | 26 base::internal::PassedWrapper<std::unique_ptr<T>> RebindForward( |
| 27 std::unique_ptr<T>& t) { |
| 27 return base::Passed(&t); | 28 return base::Passed(&t); |
| 28 } | 29 } |
| 29 | 30 |
| 30 template <typename T> | 31 template <typename T> |
| 31 T& RebindForward(T& t) { | 32 T& RebindForward(T& t) { |
| 32 return t; | 33 return t; |
| 33 } | 34 } |
| 34 | 35 |
| 35 template <typename T> | 36 template <typename T> |
| 36 class CallbackHolder { | 37 class CallbackHolder { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 delete callback; | 51 delete callback; |
| 51 } | 52 } |
| 52 | 53 |
| 53 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } | 54 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } |
| 54 const tracked_objects::Location& from_here() const { return from_here_; } | 55 const tracked_objects::Location& from_here() const { return from_here_; } |
| 55 const base::Callback<T>& callback() const { return *callback_; } | 56 const base::Callback<T>& callback() const { return *callback_; } |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 59 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 59 const tracked_objects::Location from_here_; | 60 const tracked_objects::Location from_here_; |
| 60 scoped_ptr<base::Callback<T> > callback_; | 61 std::unique_ptr<base::Callback<T>> callback_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(CallbackHolder); | 63 DISALLOW_COPY_AND_ASSIGN(CallbackHolder); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 template <typename> | 66 template <typename> |
| 66 struct RelayToTaskRunnerHelper; | 67 struct RelayToTaskRunnerHelper; |
| 67 | 68 |
| 68 template <typename... Args> | 69 template <typename... Args> |
| 69 struct RelayToTaskRunnerHelper<void(Args...)> { | 70 struct RelayToTaskRunnerHelper<void(Args...)> { |
| 70 static void Run(CallbackHolder<void(Args...)>* holder, Args... args) { | 71 static void Run(CallbackHolder<void(Args...)>* holder, Args... args) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 97 const base::Callback<T>& callback) { | 98 const base::Callback<T>& callback) { |
| 98 return RelayCallbackToTaskRunner( | 99 return RelayCallbackToTaskRunner( |
| 99 base::ThreadTaskRunnerHandle::Get(), | 100 base::ThreadTaskRunnerHandle::Get(), |
| 100 from_here, callback); | 101 from_here, callback); |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace drive_backend | 104 } // namespace drive_backend |
| 104 } // namespace sync_file_system | 105 } // namespace sync_file_system |
| 105 | 106 |
| 106 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ | 107 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CALLBACK_HELPER_H_ |
| OLD | NEW |