Chromium Code Reviews| Index: chrome/profiling/profiling_globals.cc |
| diff --git a/chrome/profiling/profiling_globals.cc b/chrome/profiling/profiling_globals.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7cff8ca7083934369ccd4e386064e1b03da45969 |
| --- /dev/null |
| +++ b/chrome/profiling/profiling_globals.cc |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/profiling/profiling_globals.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/threading/thread.h" |
| +#include "build/build_config.h" |
| + |
| +namespace profiling { |
| + |
| +ProfilingGlobals::ProfilingGlobals() |
| + : io_thread_(base::MakeUnique<base::Thread>("IO thread")) { |
|
awong
2017/06/14 23:15:19
Don't change this code, but do we actually want an
brettw
2017/06/14 23:23:55
I changed it. I did it that way because I was thin
|
| +#if defined(OS_WIN) |
| + io_thread_->init_com_with_mta(true); |
| +#endif |
| + base::Thread::Options options; |
| + options.message_loop_type = base::MessageLoop::TYPE_IO; |
| + io_thread_->StartWithOptions(options); |
| +} |
| + |
| +ProfilingGlobals::~ProfilingGlobals() {} |
| + |
| +// static |
| +ProfilingGlobals* ProfilingGlobals::Get() { |
| + static ProfilingGlobals singleton; |
| + return &singleton; |
| +} |
| + |
| +base::TaskRunner* ProfilingGlobals::GetIORunner() { |
| + return io_thread_->task_runner().get(); |
| +} |
| + |
| +scoped_refptr<base::SingleThreadTaskRunner> ProfilingGlobals::GetMainThread() |
| + const { |
| + CHECK(base::MessageLoop::current() == main_message_loop_); |
| + return main_message_loop_->task_runner(); |
| +} |
| + |
| +void ProfilingGlobals::RunMainMessageLoop() { |
| + base::MessageLoopForUI message_loop; |
| + DCHECK(!main_message_loop_); |
| + main_message_loop_ = &message_loop; |
| + |
| + base::RunLoop run_loop; |
| + run_loop.Run(); |
| + |
| + main_message_loop_ = nullptr; |
| +} |
| + |
| +void ProfilingGlobals::QuitWhenIdle() { |
| + main_message_loop_->QuitWhenIdle(); |
| +} |
| + |
| +} // namespace profiling |