Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / loader / ThreadableLoaderClientWrapper.h
blobc751875ace1750e90da41931a501e41a9219b0cc
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef ThreadableLoaderClientWrapper_h
32 #define ThreadableLoaderClientWrapper_h
34 #include "core/loader/ThreadableLoaderClient.h"
35 #include "wtf/Noncopyable.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/ThreadSafeRefCounted.h"
38 #include "wtf/Threading.h"
40 namespace blink {
42 class ThreadableLoaderClientWrapper : public ThreadSafeRefCounted<ThreadableLoaderClientWrapper> {
43 public:
44 class ResourceTimingClient {
45 public:
46 virtual void didReceiveResourceTiming(const ResourceTimingInfo&) = 0;
49 static PassRefPtr<ThreadableLoaderClientWrapper> create(ThreadableLoaderClient* client)
51 return adoptRef(new ThreadableLoaderClientWrapper(client));
54 void clearClient()
56 m_done = true;
57 m_client = 0;
58 clearResourceTimingClient();
61 bool done() const
63 return m_done;
66 void setResourceTimingClient(ResourceTimingClient* client)
68 m_resourceTimingClient = client;
71 void clearResourceTimingClient()
73 m_resourceTimingClient = nullptr;
76 void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
78 if (m_client)
79 m_client->didSendData(bytesSent, totalBytesToBeSent);
82 void didReceiveResponse(unsigned long identifier, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
84 if (m_client)
85 m_client->didReceiveResponse(identifier, response, handle);
88 void didReceiveData(const char* data, unsigned dataLength)
90 if (m_client)
91 m_client->didReceiveData(data, dataLength);
94 void didReceiveCachedMetadata(const char* data, int dataLength)
96 if (m_client)
97 m_client->didReceiveCachedMetadata(data, dataLength);
100 void didFinishLoading(unsigned long identifier, double finishTime)
102 m_done = true;
103 if (m_client)
104 m_client->didFinishLoading(identifier, finishTime);
107 void didFail(const ResourceError& error)
109 m_done = true;
110 if (m_client)
111 m_client->didFail(error);
114 void didFailAccessControlCheck(const ResourceError& error)
116 m_done = true;
117 if (m_client)
118 m_client->didFailAccessControlCheck(error);
121 void didFailRedirectCheck()
123 m_done = true;
124 if (m_client)
125 m_client->didFailRedirectCheck();
128 void didReceiveAuthenticationCancellation(unsigned long identifier, const ResourceResponse& response)
130 if (m_client)
131 m_client->didReceiveResponse(identifier, response, nullptr);
134 void didDownloadData(int dataLength)
136 if (m_client)
137 m_client->didDownloadData(dataLength);
140 void didReceiveResourceTiming(const ResourceTimingInfo& info)
142 if (m_resourceTimingClient)
143 m_resourceTimingClient->didReceiveResourceTiming(info);
146 protected:
147 explicit ThreadableLoaderClientWrapper(ThreadableLoaderClient* client)
148 : m_client(client)
149 , m_resourceTimingClient(nullptr)
150 , m_done(false)
154 ThreadableLoaderClient* m_client;
155 ResourceTimingClient* m_resourceTimingClient;
156 bool m_done;
159 } // namespace blink
161 #endif // ThreadableLoaderClientWrapper_h