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

Side by Side Diff: Source/platform/heap/Handle.h

Issue 1335303002: Add (back) assignment operator overloads over Persistent<> types. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 Persistent(std::nullptr_t) : Parent(nullptr) { } 281 Persistent(std::nullptr_t) : Parent(nullptr) { }
282 Persistent(T* raw) : Parent(raw) { } 282 Persistent(T* raw) : Parent(raw) { }
283 Persistent(T& raw) : Parent(raw) { } 283 Persistent(T& raw) : Parent(raw) { }
284 Persistent(const Persistent& other) : Parent(other) { } 284 Persistent(const Persistent& other) : Parent(other) { }
285 template<typename U> 285 template<typename U>
286 Persistent(const Persistent<U>& other) : Parent(other) { } 286 Persistent(const Persistent<U>& other) : Parent(other) { }
287 template<typename U> 287 template<typename U>
288 Persistent(const Member<U>& other) : Parent(other) { } 288 Persistent(const Member<U>& other) : Parent(other) { }
289 template<typename U> 289 template<typename U>
290 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } 290 Persistent(const RawPtr<U>& other) : Parent(other.get()) { }
291
292 template<typename U>
293 Persistent& operator=(U* other)
294 {
295 Parent::operator=(other);
296 return *this;
297 }
298
299 template<typename U>
sof 2015/09/12 17:26:17 Cut&paste error - this one shouldn't be parameteri
300 Persistent& operator=(std::nullptr_t)
301 {
302 Parent::operator=(nullptr);
303 return *this;
304 }
305
306 Persistent& operator=(const Persistent& other)
307 {
308 Parent::operator=(other);
309 return *this;
310 }
311
312 template<typename U>
313 Persistent& operator=(const Persistent<U>& other)
314 {
315 Parent::operator=(other);
316 return *this;
317 }
318
319 template<typename U>
320 Persistent& operator=(const Member<U>& other)
321 {
322 Parent::operator=(other);
323 return *this;
324 }
325
326 template<typename U>
327 Persistent& operator=(const RawPtr<U>& other)
328 {
329 Parent::operator=(other);
330 return *this;
331 }
291 }; 332 };
292 333
293 // WeakPersistent is a way to create a weak pointer from an off-heap object 334 // WeakPersistent is a way to create a weak pointer from an off-heap object
294 // to an on-heap object. The m_raw is automatically cleared when the pointee 335 // to an on-heap object. The m_raw is automatically cleared when the pointee
295 // gets collected. 336 // gets collected.
296 // 337 //
297 // We have to construct and destruct WeakPersistent in the same thread. 338 // We have to construct and destruct WeakPersistent in the same thread.
298 // 339 //
299 // Note that collections of WeakPersistents are not supported. Use a persistent 340 // Note that collections of WeakPersistents are not supported. Use a persistent
300 // collection of WeakMembers instead. 341 // collection of WeakMembers instead.
301 // 342 //
302 // HashSet<WeakPersistent<T>> m_set; // wrong 343 // HashSet<WeakPersistent<T>> m_set; // wrong
303 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct 344 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct
304 template<typename T> 345 template<typename T>
305 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin gleThreadPersistentConfiguration> { 346 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin gleThreadPersistentConfiguration> {
306 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten tConfiguration> Parent; 347 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten tConfiguration> Parent;
307 public: 348 public:
308 WeakPersistent() : Parent() { } 349 WeakPersistent() : Parent() { }
309 WeakPersistent(std::nullptr_t) : Parent(nullptr) { } 350 WeakPersistent(std::nullptr_t) : Parent(nullptr) { }
310 WeakPersistent(T* raw) : Parent(raw) { } 351 WeakPersistent(T* raw) : Parent(raw) { }
311 WeakPersistent(T& raw) : Parent(raw) { } 352 WeakPersistent(T& raw) : Parent(raw) { }
312 WeakPersistent(const WeakPersistent& other) : Parent(other) { } 353 WeakPersistent(const WeakPersistent& other) : Parent(other) { }
313 template<typename U> 354 template<typename U>
314 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { } 355 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { }
315 template<typename U> 356 template<typename U>
316 WeakPersistent(const Member<U>& other) : Parent(other) { } 357 WeakPersistent(const Member<U>& other) : Parent(other) { }
317 template<typename U> 358 template<typename U>
318 WeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } 359 WeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { }
360
361 template<typename U>
362 WeakPersistent& operator=(U* other)
363 {
364 Parent::operator=(other);
365 return *this;
366 }
367
368 template<typename U>
369 WeakPersistent& operator=(std::nullptr_t)
370 {
371 Parent::operator=(nullptr);
372 return *this;
373 }
374
375 WeakPersistent& operator=(const WeakPersistent& other)
376 {
377 Parent::operator=(other);
378 return *this;
379 }
380
381 template<typename U>
382 WeakPersistent& operator=(const WeakPersistent<U>& other)
383 {
384 Parent::operator=(other);
385 return *this;
386 }
387
388 template<typename U>
389 WeakPersistent& operator=(const Member<U>& other)
390 {
391 Parent::operator=(other);
392 return *this;
393 }
394
395 template<typename U>
396 WeakPersistent& operator=(const RawPtr<U>& other)
397 {
398 Parent::operator=(other);
399 return *this;
400 }
319 }; 401 };
320 402
321 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread 403 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread
322 // different from the construction thread. 404 // different from the construction thread.
323 template<typename T> 405 template<typename T>
324 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur ation, CrossThreadPersistentConfiguration> { 406 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur ation, CrossThreadPersistentConfiguration> {
325 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent; 407 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist entConfiguration> Parent;
326 public: 408 public:
327 CrossThreadPersistent() : Parent() { } 409 CrossThreadPersistent() : Parent() { }
328 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } 410 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { }
329 CrossThreadPersistent(T* raw) : Parent(raw) { } 411 CrossThreadPersistent(T* raw) : Parent(raw) { }
330 CrossThreadPersistent(T& raw) : Parent(raw) { } 412 CrossThreadPersistent(T& raw) : Parent(raw) { }
331 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { } 413 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) { }
332 template<typename U> 414 template<typename U>
333 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { } 415 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { }
334 template<typename U> 416 template<typename U>
335 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } 417 CrossThreadPersistent(const Member<U>& other) : Parent(other) { }
336 template<typename U> 418 template<typename U>
337 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } 419 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { }
420
421 template<typename U>
422 CrossThreadPersistent& operator=(U* other)
423 {
424 Parent::operator=(other);
425 return *this;
426 }
427
428 template<typename U>
429 CrossThreadPersistent& operator=(std::nullptr_t)
430 {
431 Parent::operator=(nullptr);
432 return *this;
433 }
434
435 CrossThreadPersistent& operator=(const CrossThreadPersistent& other)
436 {
437 Parent::operator=(other);
438 return *this;
439 }
440
441 template<typename U>
442 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other)
443 {
444 Parent::operator=(other);
445 return *this;
446 }
447
448 template<typename U>
449 CrossThreadPersistent& operator=(const Member<U>& other)
450 {
451 Parent::operator=(other);
452 return *this;
453 }
454
455 template<typename U>
456 CrossThreadPersistent& operator=(const RawPtr<U>& other)
457 {
458 Parent::operator=(other);
459 return *this;
460 }
338 }; 461 };
339 462
340 // Combines the behavior of CrossThreadPersistent and WeakPersistent. 463 // Combines the behavior of CrossThreadPersistent and WeakPersistent.
341 template<typename T> 464 template<typename T>
342 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> { 465 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu ration, CrossThreadPersistentConfiguration> {
343 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent; 466 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent Configuration> Parent;
344 public: 467 public:
345 CrossThreadWeakPersistent() : Parent() { } 468 CrossThreadWeakPersistent() : Parent() { }
346 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } 469 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { }
347 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } 470 CrossThreadWeakPersistent(T* raw) : Parent(raw) { }
348 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } 471 CrossThreadWeakPersistent(T& raw) : Parent(raw) { }
349 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { } 472 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o ther) { }
350 template<typename U> 473 template<typename U>
351 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { } 474 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren t(other) { }
352 template<typename U> 475 template<typename U>
353 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } 476 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { }
354 template<typename U> 477 template<typename U>
355 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } 478 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { }
479
480 template<typename U>
481 CrossThreadWeakPersistent& operator=(U* other)
482 {
483 Parent::operator=(other);
484 return *this;
485 }
486
487 template<typename U>
488 CrossThreadWeakPersistent& operator=(std::nullptr_t)
489 {
490 Parent::operator=(nullptr);
491 return *this;
492 }
493
494 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent& other)
495 {
496 Parent::operator=(other);
497 return *this;
498 }
499
500 template<typename U>
501 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth er)
502 {
503 Parent::operator=(other);
504 return *this;
505 }
506
507 template<typename U>
508 CrossThreadWeakPersistent& operator=(const Member<U>& other)
509 {
510 Parent::operator=(other);
511 return *this;
512 }
513
514 template<typename U>
515 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other)
516 {
517 Parent::operator=(other);
518 return *this;
519 }
356 }; 520 };
357 521
358 template<typename Collection> 522 template<typename Collection>
359 class PersistentHeapCollectionBase : public Collection { 523 class PersistentHeapCollectionBase : public Collection {
360 // We overload the various new and delete operators with using the WTF Defau ltAllocator to ensure persistent 524 // We overload the various new and delete operators with using the WTF Defau ltAllocator to ensure persistent
361 // heap collections are always allocated off-heap. This allows persistent co llections to be used in 525 // heap collections are always allocated off-heap. This allows persistent co llections to be used in
362 // DEFINE_STATIC_LOCAL et. al. 526 // DEFINE_STATIC_LOCAL et. al.
363 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); 527 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator);
364 public: 528 public:
365 PersistentHeapCollectionBase() 529 PersistentHeapCollectionBase()
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. 1373 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent.
1210 static T* unwrap(const StorageType& value) { return value.get(); } 1374 static T* unwrap(const StorageType& value) { return value.get(); }
1211 }; 1375 };
1212 1376
1213 template<typename T> 1377 template<typename T>
1214 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1378 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1215 1379
1216 } // namespace WTF 1380 } // namespace WTF
1217 1381
1218 #endif 1382 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698