| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/fetch/MockResourceClient.h" | 5 #include "core/fetch/MockResourceClient.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 MockResourceClient::MockResourceClient(Resource* resource) | 11 MockResourceClient::MockResourceClient(Resource* resource) |
| 12 : m_resource(resource), | 12 : m_resource(resource), |
| 13 m_notifyFinishedCalled(false), | 13 m_notifyFinishedCalled(false), |
| 14 m_encodedSizeOnNotifyFinished(0) { | 14 m_encodedSizeOnNotifyFinished(0) { |
| 15 ThreadState::current()->registerPreFinalizer(this); | |
| 16 m_resource->addClient(this); | 15 m_resource->addClient(this); |
| 17 } | 16 } |
| 18 | 17 |
| 19 MockResourceClient::~MockResourceClient() {} | 18 MockResourceClient::~MockResourceClient() {} |
| 20 | 19 |
| 21 void MockResourceClient::notifyFinished(Resource* resource) { | 20 void MockResourceClient::notifyFinished(Resource* resource) { |
| 22 ASSERT_FALSE(m_notifyFinishedCalled); | 21 ASSERT_FALSE(m_notifyFinishedCalled); |
| 23 m_notifyFinishedCalled = true; | 22 m_notifyFinishedCalled = true; |
| 24 m_encodedSizeOnNotifyFinished = resource->encodedSize(); | 23 m_encodedSizeOnNotifyFinished = resource->encodedSize(); |
| 25 } | 24 } |
| 26 | 25 |
| 27 void MockResourceClient::removeAsClient() { | 26 void MockResourceClient::removeAsClient() { |
| 28 m_resource->removeClient(this); | 27 m_resource->removeClient(this); |
| 29 m_resource = nullptr; | 28 m_resource = nullptr; |
| 30 } | 29 } |
| 31 | 30 |
| 32 void MockResourceClient::dispose() { | 31 void MockResourceClient::dispose() { |
| 33 if (m_resource) { | 32 if (m_resource) { |
| 34 m_resource->removeClient(this); | 33 m_resource->removeClient(this); |
| 35 m_resource = nullptr; | 34 m_resource = nullptr; |
| 36 } | 35 } |
| 37 } | 36 } |
| 38 | 37 |
| 39 DEFINE_TRACE(MockResourceClient) { | 38 DEFINE_TRACE(MockResourceClient) { |
| 40 visitor->trace(m_resource); | 39 visitor->trace(m_resource); |
| 41 ResourceClient::trace(visitor); | 40 ResourceClient::trace(visitor); |
| 42 } | 41 } |
| 43 | 42 |
| 44 } // namespace blink | 43 } // namespace blink |
| OLD | NEW |