OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/testing/weburl_loader_mock.h" | 5 #include "platform/testing/weburl_loader_mock.h" |
6 | 6 |
7 #include "platform/testing/weburl_loader_mock_factory_impl.h" | 7 #include "platform/testing/weburl_loader_mock_factory_impl.h" |
8 #include "public/platform/URLConversion.h" | 8 #include "public/platform/URLConversion.h" |
9 #include "public/platform/WebData.h" | 9 #include "public/platform/WebData.h" |
10 #include "public/platform/WebURLError.h" | 10 #include "public/platform/WebURLError.h" |
11 #include "public/platform/WebURLLoaderClient.h" | 11 #include "public/platform/WebURLLoaderClient.h" |
| 12 #include "wtf/PassOwnPtr.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, | 16 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, |
16 WebURLLoader* default_loader) | 17 WebURLLoader* default_loader) |
17 : factory_(factory), | 18 : factory_(factory), |
18 default_loader_(wrapUnique(default_loader)), | 19 default_loader_(adoptPtr(default_loader)), |
19 weak_factory_(this) { | 20 weak_factory_(this) { |
20 } | 21 } |
21 | 22 |
22 WebURLLoaderMock::~WebURLLoaderMock() { | 23 WebURLLoaderMock::~WebURLLoaderMock() { |
23 cancel(); | 24 cancel(); |
24 } | 25 } |
25 | 26 |
26 void WebURLLoaderMock::ServeAsynchronousRequest( | 27 void WebURLLoaderMock::ServeAsynchronousRequest( |
27 WebURLLoaderTestDelegate* delegate, | 28 WebURLLoaderTestDelegate* delegate, |
28 const WebURLResponse& response, | 29 const WebURLResponse& response, |
29 const WebData& data, | 30 const WebData& data, |
30 const WebURLError& error) { | 31 const WebURLError& error) { |
31 DCHECK(!using_default_loader_); | 32 DCHECK(!using_default_loader_); |
32 if (!client_) | 33 if (!client_) |
33 return; | 34 return; |
34 | 35 |
35 // If no delegate is provided then create an empty one. The default behavior | 36 // If no delegate is provided then create an empty one. The default behavior |
36 // will just proxy to the client. | 37 // will just proxy to the client. |
37 std::unique_ptr<WebURLLoaderTestDelegate> default_delegate; | 38 OwnPtr<WebURLLoaderTestDelegate> default_delegate; |
38 if (!delegate) { | 39 if (!delegate) { |
39 default_delegate = wrapUnique(new WebURLLoaderTestDelegate()); | 40 default_delegate = adoptPtr(new WebURLLoaderTestDelegate()); |
40 delegate = default_delegate.get(); | 41 delegate = default_delegate.get(); |
41 } | 42 } |
42 | 43 |
43 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() | 44 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() |
44 // to be called which will make the ResourceLoader to delete |this|. | 45 // to be called which will make the ResourceLoader to delete |this|. |
45 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); | 46 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); |
46 | 47 |
47 delegate->didReceiveResponse(client_, this, response); | 48 delegate->didReceiveResponse(client_, this, response); |
48 if (!self) | 49 if (!self) |
49 return; | 50 return; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods | 159 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods |
159 // the console during webkit unit tests, so we leave the function empty. | 160 // the console during webkit unit tests, so we leave the function empty. |
160 DCHECK(runner); | 161 DCHECK(runner); |
161 } | 162 } |
162 | 163 |
163 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { | 164 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { |
164 return weak_factory_.createWeakPtr(); | 165 return weak_factory_.createWeakPtr(); |
165 } | 166 } |
166 | 167 |
167 } // namespace blink | 168 } // namespace blink |
OLD | NEW |