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" | |
13 | 12 |
14 namespace blink { | 13 namespace blink { |
15 | 14 |
16 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, | 15 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, |
17 WebURLLoader* default_loader) | 16 WebURLLoader* default_loader) |
18 : factory_(factory), | 17 : factory_(factory), |
19 default_loader_(adoptPtr(default_loader)), | 18 default_loader_(wrapUnique(default_loader)), |
20 weak_factory_(this) { | 19 weak_factory_(this) { |
21 } | 20 } |
22 | 21 |
23 WebURLLoaderMock::~WebURLLoaderMock() { | 22 WebURLLoaderMock::~WebURLLoaderMock() { |
24 cancel(); | 23 cancel(); |
25 } | 24 } |
26 | 25 |
27 void WebURLLoaderMock::ServeAsynchronousRequest( | 26 void WebURLLoaderMock::ServeAsynchronousRequest( |
28 WebURLLoaderTestDelegate* delegate, | 27 WebURLLoaderTestDelegate* delegate, |
29 const WebURLResponse& response, | 28 const WebURLResponse& response, |
30 const WebData& data, | 29 const WebData& data, |
31 const WebURLError& error) { | 30 const WebURLError& error) { |
32 DCHECK(!using_default_loader_); | 31 DCHECK(!using_default_loader_); |
33 if (!client_) | 32 if (!client_) |
34 return; | 33 return; |
35 | 34 |
36 // If no delegate is provided then create an empty one. The default behavior | 35 // If no delegate is provided then create an empty one. The default behavior |
37 // will just proxy to the client. | 36 // will just proxy to the client. |
38 OwnPtr<WebURLLoaderTestDelegate> default_delegate; | 37 std::unique_ptr<WebURLLoaderTestDelegate> default_delegate; |
39 if (!delegate) { | 38 if (!delegate) { |
40 default_delegate = adoptPtr(new WebURLLoaderTestDelegate()); | 39 default_delegate = wrapUnique(new WebURLLoaderTestDelegate()); |
41 delegate = default_delegate.get(); | 40 delegate = default_delegate.get(); |
42 } | 41 } |
43 | 42 |
44 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() | 43 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() |
45 // to be called which will make the ResourceLoader to delete |this|. | 44 // to be called which will make the ResourceLoader to delete |this|. |
46 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); | 45 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); |
47 | 46 |
48 delegate->didReceiveResponse(client_, this, response); | 47 delegate->didReceiveResponse(client_, this, response); |
49 if (!self) | 48 if (!self) |
50 return; | 49 return; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods | 158 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods |
160 // the console during webkit unit tests, so we leave the function empty. | 159 // the console during webkit unit tests, so we leave the function empty. |
161 DCHECK(runner); | 160 DCHECK(runner); |
162 } | 161 } |
163 | 162 |
164 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { | 163 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { |
165 return weak_factory_.createWeakPtr(); | 164 return weak_factory_.createWeakPtr(); |
166 } | 165 } |
167 | 166 |
168 } // namespace blink | 167 } // namespace blink |
OLD | NEW |