Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 10 matching lines...) Expand all Loading... | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/CrossThreadCopier.h" | 31 #include "wtf/CrossThreadCopier.h" |
| 32 | 32 |
| 33 #include "platform/network/ResourceError.h" | 33 #include "wtf/PassRefPtr.h" |
| 34 #include "platform/network/ResourceRequest.h" | 34 #include "wtf/RefCounted.h" |
| 35 #include "platform/network/ResourceResponse.h" | 35 #include "wtf/RefPtr.h" |
| 36 #include "platform/weborigin/KURL.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
| 37 #include "wtf/text/WTFString.h" | |
| 38 #include <memory> | 37 #include <memory> |
| 38 #include <type_traits> | |
| 39 | 39 |
| 40 namespace blink { | 40 namespace WTF { |
| 41 | |
| 42 CrossThreadCopier<KURL>::Type CrossThreadCopier<KURL>::copy(const KURL& url) | |
| 43 { | |
| 44 return url.copy(); | |
| 45 } | |
| 46 | |
| 47 CrossThreadCopier<String>::Type CrossThreadCopier<String>::copy(const String& st r) | |
| 48 { | |
| 49 return str.isolatedCopy(); | |
| 50 } | |
| 51 | |
| 52 CrossThreadCopier<ResourceError>::Type CrossThreadCopier<ResourceError>::copy(co nst ResourceError& error) | |
| 53 { | |
| 54 return error.copy(); | |
| 55 } | |
| 56 | |
| 57 CrossThreadCopier<ResourceRequest>::Type CrossThreadCopier<ResourceRequest>::cop y(const ResourceRequest& request) | |
| 58 { | |
| 59 return passed(request.copyData()); | |
| 60 } | |
| 61 | |
| 62 CrossThreadCopier<ResourceResponse>::Type CrossThreadCopier<ResourceResponse>::c opy(const ResourceResponse& response) | |
| 63 { | |
| 64 return passed(response.copyData()); | |
| 65 } | |
| 66 | 41 |
| 67 // Test CrossThreadCopier using static_assert. | 42 // Test CrossThreadCopier using static_assert. |
| 68 | 43 |
| 69 // Verify that ThreadSafeRefCounted objects get handled correctly. | 44 // Verify that ThreadSafeRefCounted objects get handled correctly. |
| 70 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS afeRefCountedTest> { | 45 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS afeRefCountedTest> { |
| 71 }; | 46 }; |
| 72 | 47 |
| 73 // Add a generic specialization which will let's us verify that no other templat e matches. | 48 // Add a generic specialization which will let's us verify that no other templat e matches. |
| 74 template<typename T> struct CrossThreadCopierBase<T, false> { | 49 template<typename T> struct CrossThreadCopierBase<T, false> { |
| 75 typedef int Type; | 50 typedef int Type; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 101 >::value), | 76 >::value), |
| 102 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); | 77 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); |
| 103 | 78 |
| 104 // Verify that std::unique_ptr gets passed through. | 79 // Verify that std::unique_ptr gets passed through. |
| 105 static_assert((std::is_same< | 80 static_assert((std::is_same< |
| 106 std::unique_ptr<float>, | 81 std::unique_ptr<float>, |
| 107 CrossThreadCopier<std::unique_ptr<float>>::Type | 82 CrossThreadCopier<std::unique_ptr<float>>::Type |
| 108 >::value), | 83 >::value), |
| 109 "std::unique_ptr test"); | 84 "std::unique_ptr test"); |
| 110 | 85 |
| 111 } // namespace blink | 86 } // namespace blink |
|
Yuta Kitamura
2016/07/07 07:45:59
Ditto
| |
| OLD | NEW |