| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "base/thread_task_runner_handle.h" | 31 #include "base/thread_task_runner_handle.h" |
| 32 #include "base/trace_event/memory_dump_manager.h" | 32 #include "base/trace_event/memory_dump_manager.h" |
| 33 #include "platform/PartitionAllocMemoryDumpProvider.h" | 33 #include "platform/PartitionAllocMemoryDumpProvider.h" |
| 34 #include "platform/fonts/FontCacheMemoryDumpProvider.h" |
| 34 #include "platform/graphics/CompositorFactory.h" | 35 #include "platform/graphics/CompositorFactory.h" |
| 35 #include "platform/web_memory_dump_provider_adapter.h" | 36 #include "platform/web_memory_dump_provider_adapter.h" |
| 36 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 37 #include "wtf/HashMap.h" | 38 #include "wtf/HashMap.h" |
| 38 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 static Platform* s_platform = 0; | 43 static Platform* s_platform = 0; |
| 43 using ProviderToAdapterMap = HashMap<WebMemoryDumpProvider*, OwnPtr<WebMemoryDum
pProviderAdapter>>; | 44 using ProviderToAdapterMap = HashMap<WebMemoryDumpProvider*, OwnPtr<WebMemoryDum
pProviderAdapter>>; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 { | 58 { |
| 58 } | 59 } |
| 59 | 60 |
| 60 void Platform::initialize(Platform* platform) | 61 void Platform::initialize(Platform* platform) |
| 61 { | 62 { |
| 62 ASSERT(platform); | 63 ASSERT(platform); |
| 63 s_platform = platform; | 64 s_platform = platform; |
| 64 s_platform->m_mainThread = platform->currentThread(); | 65 s_platform->m_mainThread = platform->currentThread(); |
| 65 | 66 |
| 66 // TODO(ssid): remove this check after fixing crbug.com/486782. | 67 // TODO(ssid): remove this check after fixing crbug.com/486782. |
| 67 if (s_platform->m_mainThread) | 68 if (s_platform->m_mainThread) { |
| 68 s_platform->registerMemoryDumpProvider(PartitionAllocMemoryDumpProvider:
:instance(), "PartitionAlloc"); | 69 s_platform->registerMemoryDumpProvider(PartitionAllocMemoryDumpProvider:
:instance(), "PartitionAlloc"); |
| 70 s_platform->registerMemoryDumpProvider(FontCacheMemoryDumpProvider::inst
ance(), "FontCaches"); |
| 71 } |
| 69 | 72 |
| 70 CompositorFactory::initializeDefault(); | 73 CompositorFactory::initializeDefault(); |
| 71 } | 74 } |
| 72 | 75 |
| 73 void Platform::shutdown() | 76 void Platform::shutdown() |
| 74 { | 77 { |
| 75 CompositorFactory::shutdown(); | 78 CompositorFactory::shutdown(); |
| 76 | 79 |
| 77 if (s_platform->m_mainThread) | 80 if (s_platform->m_mainThread) { |
| 81 s_platform->unregisterMemoryDumpProvider(FontCacheMemoryDumpProvider::in
stance()); |
| 78 s_platform->unregisterMemoryDumpProvider(PartitionAllocMemoryDumpProvide
r::instance()); | 82 s_platform->unregisterMemoryDumpProvider(PartitionAllocMemoryDumpProvide
r::instance()); |
| 83 } |
| 79 | 84 |
| 80 s_platform->m_mainThread = nullptr; | 85 s_platform->m_mainThread = nullptr; |
| 81 s_platform = nullptr; | 86 s_platform = nullptr; |
| 82 } | 87 } |
| 83 | 88 |
| 84 void Platform::setCurrentPlatformForTesting(Platform* platform) | 89 void Platform::setCurrentPlatformForTesting(Platform* platform) |
| 85 { | 90 { |
| 86 ASSERT(platform); | 91 ASSERT(platform); |
| 87 s_platform = platform; | 92 s_platform = platform; |
| 88 s_platform->m_mainThread = platform->currentThread(); | 93 s_platform->m_mainThread = platform->currentThread(); |
| 89 } | 94 } |
| 90 | 95 |
| 91 Platform* Platform::current() | 96 Platform* Platform::current() |
| 92 { | 97 { |
| 93 return s_platform; | 98 return s_platform; |
| 94 } | 99 } |
| 95 | 100 |
| 96 WebThread* Platform::mainThread() const | 101 WebThread* Platform::mainThread() const |
| 97 { | 102 { |
| 98 return m_mainThread; | 103 return m_mainThread; |
| 99 } | 104 } |
| 100 | 105 |
| 101 void Platform::registerMemoryDumpProvider(WebMemoryDumpProvider* provider, const
char* name) | 106 void Platform::registerMemoryDumpProvider(WebMemoryDumpProvider* provider, const
char* name) |
| 102 { | 107 { |
| 108 // MemoryDumpProvider needs a message loop. |
| 109 if (!Platform::current()->currentThread()) |
| 110 return; |
| 111 |
| 103 WebMemoryDumpProviderAdapter* adapter = new WebMemoryDumpProviderAdapter(pro
vider); | 112 WebMemoryDumpProviderAdapter* adapter = new WebMemoryDumpProviderAdapter(pro
vider); |
| 104 ProviderToAdapterMap::AddResult result = memoryDumpProviders().add(provider,
adoptPtr(adapter)); | 113 ProviderToAdapterMap::AddResult result = memoryDumpProviders().add(provider,
adoptPtr(adapter)); |
| 105 if (!result.isNewEntry) | 114 if (!result.isNewEntry) |
| 106 return; | 115 return; |
| 107 adapter->set_is_registered(true); | 116 adapter->set_is_registered(true); |
| 108 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(ad
apter, name, base::ThreadTaskRunnerHandle::Get()); | 117 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(ad
apter, name, base::ThreadTaskRunnerHandle::Get()); |
| 109 } | 118 } |
| 110 | 119 |
| 111 void Platform::unregisterMemoryDumpProvider(WebMemoryDumpProvider* provider) | 120 void Platform::unregisterMemoryDumpProvider(WebMemoryDumpProvider* provider) |
| 112 { | 121 { |
| 122 // MemoryDumpProvider needs a message loop. |
| 123 if (!Platform::current()->currentThread()) |
| 124 return; |
| 125 |
| 113 ProviderToAdapterMap::iterator it = memoryDumpProviders().find(provider); | 126 ProviderToAdapterMap::iterator it = memoryDumpProviders().find(provider); |
| 114 if (it == memoryDumpProviders().end()) | 127 if (it == memoryDumpProviders().end()) |
| 115 return; | 128 return; |
| 116 WebMemoryDumpProviderAdapter* adapter = it->value.get(); | 129 WebMemoryDumpProviderAdapter* adapter = it->value.get(); |
| 117 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
adapter); | 130 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
adapter); |
| 118 adapter->set_is_registered(false); | 131 adapter->set_is_registered(false); |
| 119 memoryDumpProviders().remove(it); | 132 memoryDumpProviders().remove(it); |
| 120 } | 133 } |
| 121 | 134 |
| 122 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |