OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #include "platform/CrossThreadCopier.h" | |
32 | |
33 #include "platform/network/ResourceError.h" | |
34 #include "platform/network/ResourceRequest.h" | |
35 #include "platform/network/ResourceResponse.h" | |
36 #include "platform/weborigin/KURL.h" | |
37 #include "wtf/text/WTFString.h" | |
38 #include <memory> | |
39 | |
40 namespace blink { | |
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 | |
67 // Test CrossThreadCopier using static_assert. | |
68 | |
69 // Verify that ThreadSafeRefCounted objects get handled correctly. | |
70 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS
afeRefCountedTest> { | |
71 }; | |
72 | |
73 // Add a generic specialization which will let's us verify that no other templat
e matches. | |
74 template<typename T> struct CrossThreadCopierBase<T, false> { | |
75 typedef int Type; | |
76 }; | |
77 | |
78 static_assert((std::is_same< | |
79 PassRefPtr<CopierThreadSafeRefCountedTest>, | |
80 CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest>>::Type | |
81 >::value), | |
82 "PassRefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); | |
83 static_assert((std::is_same< | |
84 RefPtr<CopierThreadSafeRefCountedTest>, | |
85 CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type | |
86 >::value), | |
87 "RefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); | |
88 static_assert((std::is_same< | |
89 int, | |
90 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type | |
91 >::value), | |
92 "Raw pointer + ThreadSafeRefCounted should NOT pass CrossThreadCopier"); | |
93 | |
94 // Verify that RefCounted objects only match our generic template which exposes
Type as int. | |
95 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> { | |
96 }; | |
97 | |
98 static_assert((std::is_same< | |
99 int, | |
100 CrossThreadCopier<CopierRefCountedTest*>::Type | |
101 >::value), | |
102 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); | |
103 | |
104 // Verify that std::unique_ptr gets passed through. | |
105 static_assert((std::is_same< | |
106 std::unique_ptr<float>, | |
107 CrossThreadCopier<std::unique_ptr<float>>::Type | |
108 >::value), | |
109 "std::unique_ptr test"); | |
110 | |
111 } // namespace blink | |
OLD | NEW |