| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "remoting/client/chromoting_client_runtime.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" |
| 10 #include "remoting/base/url_request_context_getter.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 ChromotingClientRuntime::ChromotingClientRuntime() { |
| 15 if (!base::MessageLoop::current()) { |
| 16 VLOG(1) << "Starting main message loop"; |
| 17 ui_loop_.reset(new base::MessageLoopForUI()); |
| 18 #if defined(OS_IOS) |
| 19 // On iOS we created a new message loop and now attach it. |
| 20 base::MessageLoopForUI::current()->Attach(); |
| 21 #elif defined(OS_ANDROID) |
| 22 // On Android, the UI thread is managed by Java, so we need to attach and |
| 23 // start a special type of message loop to allow Chromium code to run tasks. |
| 24 ui_loop_->Start(); |
| 25 #else |
| 26 NOTREACHED(); |
| 27 #endif |
| 28 } else { |
| 29 VLOG(1) << "Using existing main message loop"; |
| 30 ui_loop_.reset(base::MessageLoopForUI::current()); |
| 31 } |
| 32 |
| 33 // |ui_loop_| runs on the main thread, so |ui_task_runner_| will run on the |
| 34 // main thread. We can not kill the main thread when the message loop becomes |
| 35 // idle so the callback function does nothing (as opposed to the typical |
| 36 // base::MessageLoop::QuitClosure()) |
| 37 ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->task_runner(), |
| 38 base::Bind(&base::DoNothing)); |
| 39 |
| 40 display_task_runner_ = AutoThread::Create("native_disp", ui_task_runner_); |
| 41 network_task_runner_ = AutoThread::CreateWithType( |
| 42 "native_net", ui_task_runner_, base::MessageLoop::TYPE_IO); |
| 43 file_task_runner_ = AutoThread::CreateWithType("native_file", ui_task_runner_, |
| 44 base::MessageLoop::TYPE_IO); |
| 45 url_requester_ = |
| 46 new URLRequestContextGetter(network_task_runner_, file_task_runner_); |
| 47 } |
| 48 |
| 49 // static |
| 50 ChromotingClientRuntime* ChromotingClientRuntime::GetInstance() { |
| 51 return base::Singleton<ChromotingClientRuntime>::get(); |
| 52 } |
| 53 |
| 54 ChromotingClientRuntime::~ChromotingClientRuntime() {} |
| 55 |
| 56 } // namespace remoting |
| OLD | NEW |