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

Side by Side Diff: Source/core/platform/CrossThreadCopier.cpp

Issue 31483002: Move CrossThreadCopier.cpp/.h to platform/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 7 years, 2 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
(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 "config.h"
32
33 #include "core/platform/CrossThreadCopier.h"
34
35 #include "platform/network/ResourceError.h"
36 #include "platform/network/ResourceRequest.h"
37 #include "platform/network/ResourceResponse.h"
38 #include "weborigin/KURL.h"
39 #include "wtf/Assertions.h"
40 #include "wtf/text/WTFString.h"
41
42 namespace WebCore {
43
44 CrossThreadCopierBase<false, false, KURL>::Type CrossThreadCopierBase<false, fal se, KURL>::copy(const KURL& url)
45 {
46 return url.copy();
47 }
48
49 CrossThreadCopierBase<false, false, String>::Type CrossThreadCopierBase<false, f alse, String>::copy(const String& str)
50 {
51 return str.isolatedCopy();
52 }
53
54 CrossThreadCopierBase<false, false, ResourceError>::Type CrossThreadCopierBase<f alse, false, ResourceError>::copy(const ResourceError& error)
55 {
56 return error.copy();
57 }
58
59 CrossThreadCopierBase<false, false, ResourceRequest>::Type CrossThreadCopierBase <false, false, ResourceRequest>::copy(const ResourceRequest& request)
60 {
61 return request.copyData();
62 }
63
64 CrossThreadCopierBase<false, false, ResourceResponse>::Type CrossThreadCopierBas e<false, false, ResourceResponse>::copy(const ResourceResponse& response)
65 {
66 return response.copyData();
67 }
68
69 // Test CrossThreadCopier using COMPILE_ASSERT.
70
71 // Verify that ThreadSafeRefCounted objects get handled correctly.
72 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadS afeRefCountedTest> {
73 };
74
75 COMPILE_ASSERT((WTF::IsSameType<
76 PassRefPtr<CopierThreadSafeRefCountedTest>,
77 CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest> > ::Type
78 >::value),
79 PassRefPtrTest);
80 COMPILE_ASSERT((WTF::IsSameType<
81 PassRefPtr<CopierThreadSafeRefCountedTest>,
82 CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest> >::Ty pe
83 >::value),
84 RefPtrTest);
85 COMPILE_ASSERT((WTF::IsSameType<
86 PassRefPtr<CopierThreadSafeRefCountedTest>,
87 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type
88 >::value),
89 RawPointerTest);
90
91
92 // Add a generic specialization which will let's us verify that no other templat e matches.
93 template<typename T> struct CrossThreadCopierBase<false, false, T> {
94 typedef int Type;
95 };
96
97 // Verify that RefCounted objects only match our generic template which exposes Type as int.
98 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {
99 };
100
101 COMPILE_ASSERT((WTF::IsSameType<
102 int,
103 CrossThreadCopier<PassRefPtr<CopierRefCountedTest> >::Type
104 >::value),
105 PassRefPtrRefCountedTest);
106
107 COMPILE_ASSERT((WTF::IsSameType<
108 int,
109 CrossThreadCopier<RefPtr<CopierRefCountedTest> >::Type
110 >::value),
111 RefPtrRefCountedTest);
112
113 COMPILE_ASSERT((WTF::IsSameType<
114 int,
115 CrossThreadCopier<CopierRefCountedTest*>::Type
116 >::value),
117 RawPointerRefCountedTest);
118
119 // Verify that PassOwnPtr gets passed through.
120 COMPILE_ASSERT((WTF::IsSameType<
121 PassOwnPtr<float>,
122 CrossThreadCopier<PassOwnPtr<float> >::Type
123 >::value),
124 PassOwnPtrTest);
125
126 // Verify that PassOwnPtr does not get passed through.
127 COMPILE_ASSERT((WTF::IsSameType<
128 int,
129 CrossThreadCopier<OwnPtr<float> >::Type
130 >::value),
131 OwnPtrTest);
132
133 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/CrossThreadCopier.h ('k') | Source/modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698