| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
| 6 #define GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 6 #define GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/template_util.h" | |
| 21 #include "google_apis/drive/base_requests.h" | 20 #include "google_apis/drive/base_requests.h" |
| 22 #include "google_apis/drive/drive_api_error_codes.h" | 21 #include "google_apis/drive/drive_api_error_codes.h" |
| 23 #include "google_apis/drive/task_util.h" | 22 #include "google_apis/drive/task_util.h" |
| 24 | 23 |
| 25 class GURL; | 24 class GURL; |
| 26 | 25 |
| 27 namespace base { | 26 namespace base { |
| 28 class FilePath; | 27 class FilePath; |
| 29 class RunLoop; | 28 class RunLoop; |
| 30 class Value; | 29 class Value; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 namespace internal { | 129 namespace internal { |
| 131 // Following helper templates are to support Chrome's move semantics. | 130 // Following helper templates are to support Chrome's move semantics. |
| 132 // Their goal is defining helper methods which are similar to: | 131 // Their goal is defining helper methods which are similar to: |
| 133 // void CopyResultCallback1(T1* out1, T1&& in1) | 132 // void CopyResultCallback1(T1* out1, T1&& in1) |
| 134 // void CopyResultCallback2(T1* out1, T2* out2, T1&& in1, T2&& in2) | 133 // void CopyResultCallback2(T1* out1, T2* out2, T1&& in1, T2&& in2) |
| 135 // : | 134 // : |
| 136 // in C++11. | 135 // in C++11. |
| 137 | 136 |
| 138 // Declare if the type is movable or not. Currently limited to scoped_ptr only. | 137 // Declare if the type is movable or not. Currently limited to scoped_ptr only. |
| 139 // We can add more types upon the usage. | 138 // We can add more types upon the usage. |
| 140 template<typename T> struct IsMovable : base::false_type {}; | 139 template<typename T> struct IsMovable : std::false_type {}; |
| 141 template<typename T, typename D> | 140 template<typename T, typename D> |
| 142 struct IsMovable<scoped_ptr<T, D> > : base::true_type {}; | 141 struct IsMovable<scoped_ptr<T, D> > : std::true_type {}; |
| 143 | 142 |
| 144 // InType is const T& if |UseConstRef| is true, otherwise |T|. | 143 // InType is const T& if |UseConstRef| is true, otherwise |T|. |
| 145 template<bool UseConstRef, typename T> struct InTypeHelper { | 144 template<bool UseConstRef, typename T> struct InTypeHelper { |
| 146 typedef const T& InType; | 145 typedef const T& InType; |
| 147 }; | 146 }; |
| 148 template<typename T> struct InTypeHelper<false, T> { | 147 template<typename T> struct InTypeHelper<false, T> { |
| 149 typedef T InType; | 148 typedef T InType; |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 // Simulates the std::move function in C++11. We use pointer here for argument, | 151 // Simulates the std::move function in C++11. We use pointer here for argument, |
| 153 // instead of rvalue reference. | 152 // instead of rvalue reference. |
| 154 template<bool IsMovable, typename T> struct MoveHelper { | 153 template<bool IsMovable, typename T> struct MoveHelper { |
| 155 static const T& Move(const T* in) { return *in; } | 154 static const T& Move(const T* in) { return *in; } |
| 156 }; | 155 }; |
| 157 template<typename T> struct MoveHelper<true, T> { | 156 template<typename T> struct MoveHelper<true, T> { |
| 158 static T Move(T* in) { return std::move(*in); } | 157 static T Move(T* in) { return std::move(*in); } |
| 159 }; | 158 }; |
| 160 | 159 |
| 161 // Helper to handle Chrome's move semantics correctly. | 160 // Helper to handle Chrome's move semantics correctly. |
| 162 template<typename T> | 161 template<typename T> |
| 163 struct CopyResultCallbackHelper | 162 struct CopyResultCallbackHelper |
| 164 // It is necessary to calculate the exact signature of callbacks we want | 163 // It is necessary to calculate the exact signature of callbacks we want |
| 165 // to create here. In our case, as we use value-parameters for primitive | 164 // to create here. In our case, as we use value-parameters for primitive |
| 166 // types and movable types in the callback declaration. | 165 // types and movable types in the callback declaration. |
| 167 // Thus the incoming type is as follows: | 166 // Thus the incoming type is as follows: |
| 168 // 1) If the argument type |T| is class type but doesn't movable, | 167 // 1) If the argument type |T| is class type but doesn't movable, |
| 169 // |InType| is const T&. | 168 // |InType| is const T&. |
| 170 // 2) Otherwise, |T| as is. | 169 // 2) Otherwise, |T| as is. |
| 171 : InTypeHelper< | 170 : InTypeHelper< |
| 172 base::is_class<T>::value && !IsMovable<T>::value, // UseConstRef | 171 std::is_class<T>::value && !IsMovable<T>::value, // UseConstRef |
| 173 T>, | 172 T>, |
| 174 MoveHelper<IsMovable<T>::value, T> { | 173 MoveHelper<IsMovable<T>::value, T> { |
| 175 }; | 174 }; |
| 176 | 175 |
| 177 // Copies the |in|'s value to |out|. | 176 // Copies the |in|'s value to |out|. |
| 178 template<typename T1> | 177 template<typename T1> |
| 179 void CopyResultCallback( | 178 void CopyResultCallback( |
| 180 T1* out, | 179 T1* out, |
| 181 typename CopyResultCallbackHelper<T1>::InType in) { | 180 typename CopyResultCallbackHelper<T1>::InType in) { |
| 182 *out = CopyResultCallbackHelper<T1>::Move(&in); | 181 *out = CopyResultCallbackHelper<T1>::Move(&in); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 const GetContentCallback callback_; | 293 const GetContentCallback callback_; |
| 295 ScopedVector<std::string> data_; | 294 ScopedVector<std::string> data_; |
| 296 | 295 |
| 297 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); | 296 DISALLOW_COPY_AND_ASSIGN(TestGetContentCallback); |
| 298 }; | 297 }; |
| 299 | 298 |
| 300 } // namespace test_util | 299 } // namespace test_util |
| 301 } // namespace google_apis | 300 } // namespace google_apis |
| 302 | 301 |
| 303 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ | 302 #endif // GOOGLE_APIS_DRIVE_TEST_UTIL_H_ |
| OLD | NEW |