Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: sync/internal_api/public/util/weak_handle.h

Issue 16226028: Fix even more remaining uses of WeakPtr<T>'s operator T* conversion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Weak handles provides a way to refer to weak pointers from another 5 // Weak handles provides a way to refer to weak pointers from another
6 // thread. This is useful because it is not safe to reference a weak 6 // thread. This is useful because it is not safe to reference a weak
7 // pointer from a thread other than the thread on which it was 7 // pointer from a thread other than the thread on which it was
8 // created. 8 // created.
9 // 9 //
10 // Weak handles can be passed across threads, so for example, you can 10 // Weak handles can be passed across threads, so for example, you can
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 // May be destroyed on any thread. 202 // May be destroyed on any thread.
203 ~WeakHandleCore() {} 203 ~WeakHandleCore() {}
204 204
205 // GCC 4.2.1 on OS X gets confused if all the DoCall functions are 205 // GCC 4.2.1 on OS X gets confused if all the DoCall functions are
206 // named the same, so we distinguish them. 206 // named the same, so we distinguish them.
207 207
208 template <typename U> 208 template <typename U>
209 void DoCall0(void (U::*fn)(void)) const { 209 void DoCall0(void (U::*fn)(void)) const {
210 CHECK(IsOnOwnerThread()); 210 CHECK(IsOnOwnerThread());
211 if (!Get()) { 211 if (!Get().get()) {
212 return; 212 return;
213 } 213 }
214 (Get().get()->*fn)(); 214 (Get().get()->*fn)();
215 } 215 }
216 216
217 template <typename U, typename A1> 217 template <typename U, typename A1>
218 void DoCall1(void (U::*fn)(A1), 218 void DoCall1(void (U::*fn)(A1),
219 typename ParamTraits<A1>::ForwardType a1) const { 219 typename ParamTraits<A1>::ForwardType a1) const {
220 CHECK(IsOnOwnerThread()); 220 CHECK(IsOnOwnerThread());
221 if (!Get()) { 221 if (!Get().get()) {
222 return; 222 return;
223 } 223 }
224 (Get().get()->*fn)(a1); 224 (Get().get()->*fn)(a1);
225 } 225 }
226 226
227 template <typename U, typename A1, typename A2> 227 template <typename U, typename A1, typename A2>
228 void DoCall2(void (U::*fn)(A1, A2), 228 void DoCall2(void (U::*fn)(A1, A2),
229 typename ParamTraits<A1>::ForwardType a1, 229 typename ParamTraits<A1>::ForwardType a1,
230 typename ParamTraits<A2>::ForwardType a2) const { 230 typename ParamTraits<A2>::ForwardType a2) const {
231 CHECK(IsOnOwnerThread()); 231 CHECK(IsOnOwnerThread());
232 if (!Get()) { 232 if (!Get().get()) {
233 return; 233 return;
234 } 234 }
235 (Get().get()->*fn)(a1, a2); 235 (Get().get()->*fn)(a1, a2);
236 } 236 }
237 237
238 template <typename U, typename A1, typename A2, typename A3> 238 template <typename U, typename A1, typename A2, typename A3>
239 void DoCall3(void (U::*fn)(A1, A2, A3), 239 void DoCall3(void (U::*fn)(A1, A2, A3),
240 typename ParamTraits<A1>::ForwardType a1, 240 typename ParamTraits<A1>::ForwardType a1,
241 typename ParamTraits<A2>::ForwardType a2, 241 typename ParamTraits<A2>::ForwardType a2,
242 typename ParamTraits<A3>::ForwardType a3) const { 242 typename ParamTraits<A3>::ForwardType a3) const {
243 CHECK(IsOnOwnerThread()); 243 CHECK(IsOnOwnerThread());
244 if (!Get()) { 244 if (!Get().get()) {
245 return; 245 return;
246 } 246 }
247 (Get().get()->*fn)(a1, a2, a3); 247 (Get().get()->*fn)(a1, a2, a3);
248 } 248 }
249 249
250 template <typename U, typename A1, typename A2, typename A3, typename A4> 250 template <typename U, typename A1, typename A2, typename A3, typename A4>
251 void DoCall4(void (U::*fn)(A1, A2, A3, A4), 251 void DoCall4(void (U::*fn)(A1, A2, A3, A4),
252 typename ParamTraits<A1>::ForwardType a1, 252 typename ParamTraits<A1>::ForwardType a1,
253 typename ParamTraits<A2>::ForwardType a2, 253 typename ParamTraits<A2>::ForwardType a2,
254 typename ParamTraits<A3>::ForwardType a3, 254 typename ParamTraits<A3>::ForwardType a3,
255 typename ParamTraits<A4>::ForwardType a4) const { 255 typename ParamTraits<A4>::ForwardType a4) const {
256 CHECK(IsOnOwnerThread()); 256 CHECK(IsOnOwnerThread());
257 if (!Get()) { 257 if (!Get().get()) {
258 return; 258 return;
259 } 259 }
260 (Get().get()->*fn)(a1, a2, a3, a4); 260 (Get().get()->*fn)(a1, a2, a3, a4);
261 } 261 }
262 262
263 // Must be dereferenced only on the owner thread. May be destroyed 263 // Must be dereferenced only on the owner thread. May be destroyed
264 // from any thread. 264 // from any thread.
265 base::WeakPtr<T> ptr_; 265 base::WeakPtr<T> ptr_;
266 266
267 DISALLOW_COPY_AND_ASSIGN(WeakHandleCore); 267 DISALLOW_COPY_AND_ASSIGN(WeakHandleCore);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 // Makes a WeakHandle from a WeakPtr. 371 // Makes a WeakHandle from a WeakPtr.
372 template <typename T> 372 template <typename T>
373 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { 373 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) {
374 return WeakHandle<T>(ptr); 374 return WeakHandle<T>(ptr);
375 } 375 }
376 376
377 } // namespace syncer 377 } // namespace syncer
378 378
379 #endif // SYNC_UTIL_WEAK_HANDLE_H_ 379 #endif // SYNC_UTIL_WEAK_HANDLE_H_
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job_unittest.cc ('k') | sync/internal_api/public/util/weak_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698