| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/profiling/profiling_globals.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "build/build_config.h" |
| 10 |
| 11 namespace profiling { |
| 12 |
| 13 ProfilingGlobals::ProfilingGlobals() |
| 14 : io_thread_("IO thread") { |
| 15 #if defined(OS_WIN) |
| 16 io_thread_.init_com_with_mta(true); |
| 17 #endif |
| 18 base::Thread::Options options; |
| 19 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 20 io_thread_.StartWithOptions(options); |
| 21 } |
| 22 |
| 23 ProfilingGlobals::~ProfilingGlobals() {} |
| 24 |
| 25 // static |
| 26 ProfilingGlobals* ProfilingGlobals::Get() { |
| 27 static ProfilingGlobals singleton; |
| 28 return &singleton; |
| 29 } |
| 30 |
| 31 base::TaskRunner* ProfilingGlobals::GetIORunner() { |
| 32 return io_thread_.task_runner().get(); |
| 33 } |
| 34 |
| 35 scoped_refptr<base::SingleThreadTaskRunner> ProfilingGlobals::GetMainThread() |
| 36 const { |
| 37 CHECK(base::MessageLoop::current() == main_message_loop_); |
| 38 return main_message_loop_->task_runner(); |
| 39 } |
| 40 |
| 41 void ProfilingGlobals::RunMainMessageLoop() { |
| 42 // TODO(brettw) if we never add anything interesting on the main thread here, |
| 43 // we can change this so the main thread *is* the I/O thread. This will save |
| 44 // some resources. |
| 45 base::MessageLoopForUI message_loop; |
| 46 DCHECK(!main_message_loop_); |
| 47 main_message_loop_ = &message_loop; |
| 48 |
| 49 base::RunLoop run_loop; |
| 50 run_loop.Run(); |
| 51 |
| 52 main_message_loop_ = nullptr; |
| 53 } |
| 54 |
| 55 void ProfilingGlobals::QuitWhenIdle() { |
| 56 main_message_loop_->QuitWhenIdle(); |
| 57 } |
| 58 |
| 59 } // namespace profiling |
| OLD | NEW |