OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/test/weburl_loader_mock.h" | 5 #include "content/test/weburl_loader_mock.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/test/weburl_loader_mock_factory.h" | 8 #include "content/test/weburl_loader_mock_factory.h" |
9 #include "third_party/WebKit/public/platform/WebData.h" | 9 #include "third_party/WebKit/public/platform/WebData.h" |
10 #include "third_party/WebKit/public/platform/WebURLError.h" | 10 #include "third_party/WebKit/public/platform/WebURLError.h" |
11 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 11 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
12 | 12 |
13 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory, | 13 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory, |
14 blink::WebURLLoader* default_loader) | 14 blink::WebURLLoader* default_loader) |
15 : factory_(factory), | 15 : factory_(factory), |
16 client_(NULL), | 16 client_(NULL), |
17 default_loader_(default_loader), | 17 default_loader_(default_loader), |
18 using_default_loader_(false), | 18 using_default_loader_(false), |
19 is_deferred_(false) { | 19 is_deferred_(false), |
| 20 this_deleted_(NULL) { |
20 } | 21 } |
21 | 22 |
22 WebURLLoaderMock::~WebURLLoaderMock() { | 23 WebURLLoaderMock::~WebURLLoaderMock() { |
| 24 // When |this_deleted_| is not null, there is someone interested to know if |
| 25 // |this| got deleted. We notify them by setting the pointed value to true. |
| 26 if (this_deleted_) |
| 27 *this_deleted_ = true; |
23 } | 28 } |
24 | 29 |
25 void WebURLLoaderMock::ServeAsynchronousRequest( | 30 void WebURLLoaderMock::ServeAsynchronousRequest( |
26 const blink::WebURLResponse& response, | 31 const blink::WebURLResponse& response, |
27 const blink::WebData& data, | 32 const blink::WebData& data, |
28 const blink::WebURLError& error) { | 33 const blink::WebURLError& error) { |
29 DCHECK(!using_default_loader_); | 34 DCHECK(!using_default_loader_); |
30 if (!client_) | 35 if (!client_) |
31 return; | 36 return; |
32 | 37 |
| 38 bool this_deleted = false; |
| 39 this_deleted_ = &this_deleted; |
33 client_->didReceiveResponse(this, response); | 40 client_->didReceiveResponse(this, response); |
34 | 41 |
| 42 // didReceiveResponse might end up getting ::cancel() to be called which will |
| 43 // make the ResourceLoader to delete |this|. If that happens, |this_deleted|, |
| 44 // created on the stack, will be set to true. |
| 45 if (this_deleted) |
| 46 return; |
| 47 this_deleted_ = NULL; |
| 48 |
35 if (error.reason) { | 49 if (error.reason) { |
36 client_->didFail(this, error); | 50 client_->didFail(this, error); |
37 return; | 51 return; |
38 } | 52 } |
39 client_->didReceiveData(this, data.data(), data.size(), data.size()); | 53 client_->didReceiveData(this, data.data(), data.size(), data.size()); |
40 client_->didFinishLoading(this, 0, data.size()); | 54 client_->didFinishLoading(this, 0, data.size()); |
41 } | 55 } |
42 | 56 |
43 blink::WebURLRequest WebURLLoaderMock::ServeRedirect( | 57 blink::WebURLRequest WebURLLoaderMock::ServeRedirect( |
44 const blink::WebURLResponse& redirectResponse) { | 58 const blink::WebURLResponse& redirectResponse) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 103 } |
90 | 104 |
91 void WebURLLoaderMock::setDefersLoading(bool deferred) { | 105 void WebURLLoaderMock::setDefersLoading(bool deferred) { |
92 is_deferred_ = deferred; | 106 is_deferred_ = deferred; |
93 if (using_default_loader_) { | 107 if (using_default_loader_) { |
94 default_loader_->setDefersLoading(deferred); | 108 default_loader_->setDefersLoading(deferred); |
95 return; | 109 return; |
96 } | 110 } |
97 NOTIMPLEMENTED(); | 111 NOTIMPLEMENTED(); |
98 } | 112 } |
OLD | NEW |