13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file. 43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/renderer/in_process_renderer_thread.h" 63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/renderer/render_process.h" 83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/renderer/render_process_impl.h" 93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/renderer/render_thread_impl.h" 103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace content { 123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)InProcessRendererThread::InProcessRendererThread(const std::string& channel_id) 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) : Thread("Chrome_InProcRendererThread"), channel_id_(channel_id) { 153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)InProcessRendererThread::~InProcessRendererThread() { 183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Stop(); 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void InProcessRendererThread::Init() { 223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) render_process_.reset(new RenderProcessImpl()); 233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) new RenderThreadImpl(channel_id_); 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void InProcessRendererThread::CleanUp() { 273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) render_process_.reset(); 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // It's a little lame to manually set this flag. But the single process 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // RendererThread will receive the WM_QUIT. We don't need to assert on 313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // this thread, so just force the flag manually. 323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // If we want to avoid this, we could create the InProcRendererThread 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // directly with _beginthreadex() rather than using the Thread class. 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // We used to set this flag in the Init function above. However there 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // other threads like WebThread which are created by this thread 363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // which resets this flag. Please see Thread::StartWithOptions. Setting 373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // this flag to true in Cleanup works around these problems. 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetThreadWasQuitProperly(true); 393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)base::Thread* CreateInProcessRendererThread(const std::string& channel_id) { 4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return new InProcessRendererThread(channel_id); 433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} // namespace content 46