 Chromium Code Reviews
 Chromium Code Reviews Issue 2257533006:
  Free worker context resources on idle.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cleanup2
    
  
    Issue 2257533006:
  Free worker context resources on idle.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cleanup2| Index: content/renderer/render_thread_impl.cc | 
| diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc | 
| index be2f9b1376bf5c2994b23b544c0bbdf9f6e7081f..5843061c42a23eaa8fb7c1b02de6b653f0278c92 100644 | 
| --- a/content/renderer/render_thread_impl.cc | 
| +++ b/content/renderer/render_thread_impl.cc | 
| @@ -123,6 +123,7 @@ | 
| #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" | 
| #include "gin/public/debug.h" | 
| #include "gpu/GLES2/gl2extchromium.h" | 
| +#include "gpu/command_buffer/client/context_support.h" | 
| #include "gpu/command_buffer/client/shared_memory_limits.h" | 
| #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 
| #include "gpu/ipc/client/gpu_channel_host.h" | 
| @@ -160,6 +161,7 @@ | 
| #include "third_party/WebKit/public/web/WebView.h" | 
| #include "third_party/icu/source/i18n/unicode/timezone.h" | 
| #include "third_party/skia/include/core/SkGraphics.h" | 
| +#include "third_party/skia/include/gpu/GrContext.h" | 
| #include "ui/base/layout.h" | 
| #include "ui/base/ui_base_switches.h" | 
| @@ -440,6 +442,24 @@ bool IsRunningInMash() { | 
| return cmdline->HasSwitch(switches::kIsRunningInMash); | 
| } | 
| +void OnSharedWorkerContextIdle(cc::ContextProvider* context_provider) { | 
| + // If we can't acquire the lock, someone has started using this context, so | 
| + // we are no longer idle. | 
| + base::Lock* lock = context_provider->GetLock(); | 
| + if (!lock->Try()) | 
| + return; | 
| + | 
| + context_provider->DetachFromThread(); | 
| + context_provider->BindToCurrentThread(); | 
| + | 
| + context_provider->DeleteCachedResources(); | 
| + context_provider->ContextSupport()->TrimResources(); | 
| 
danakj
2016/08/23 01:26:24
Why do we need a separate TrimResources from Delet
 | 
| + | 
| + // Detach from thread to allow a new thread to attach. | 
| + context_provider->DetachFromThread(); | 
| + lock->Release(); | 
| +} | 
| + | 
| } // namespace | 
| // For measuring memory usage after each task. Behind a command line flag. | 
| @@ -2126,6 +2146,14 @@ RenderThreadImpl::SharedCompositorWorkerContextProvider() { | 
| stream_priority); | 
| if (!shared_worker_context_provider_->BindToCurrentThread()) | 
| shared_worker_context_provider_ = nullptr; | 
| + | 
| + // Set the idle callback. This callback is only called if ContextSupport | 
| + // is alive, so we know that the unreatained worker context provider | 
| 
danakj
2016/08/23 01:26:24
unretained
 | 
| + // pointer will also be alive. | 
| + shared_worker_context_provider_->ContextSupport()->SetIdleCallback( | 
| + base::Bind(&OnSharedWorkerContextIdle, | 
| + base::Unretained(shared_worker_context_provider_.get())), | 
| + base::ThreadTaskRunnerHandle::Get()); | 
| 
danakj
2016/08/23 01:26:24
what about just making it use the task runner the
 
ericrk
2016/08/24 18:32:21
The current callback systems always funnels throug
 | 
| return shared_worker_context_provider_; | 
| } |