Chromium Code Reviews| Index: remoting/client/chromoting_client_runtime.cc |
| diff --git a/remoting/client/chromoting_client_runtime.cc b/remoting/client/chromoting_client_runtime.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b35dbd305b9cd2615b4097b6a7e8493b3486847e |
| --- /dev/null |
| +++ b/remoting/client/chromoting_client_runtime.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2016 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 "remoting/client/chromoting_client_runtime.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "remoting/base/url_request_context_getter.h" |
| + |
| +namespace remoting { |
| + |
| +// Caller to create is responsible for creating and attaching a new ui thread |
|
Sergey Ulanov
2016/03/11 21:41:45
nit: move this comment to the .cc file please.
|
| +// for use. Example: |
| +// |
| +// On Android, the UI thread is managed by Java, so we need to attach and |
| +// start a special type of message loop to allow Chromium code to run tasks. |
| +// |
| +// scoped_ptr<base::MessageLoopForUI> ui_loop; |
| +// ui_loop_.reset(new base::MessageLoopForUI()); |
| +// ui_loop_->Start(); |
| +// scoped_ptr<ChromotingClientRuntime> runtime = |
| +// ChromotingClientRuntime::Create(ui_loop.get()); |
| +// |
| +// On iOS we created a new message loop and now attach it. |
| +// |
| +// scoped_ptr<base::MessageLoopForUI> ui_loop; |
| +// ui_loop_.reset(new base::MessageLoopForUI()); |
| +// base::MessageLoopForUI::current()->Attach(); |
| +// scoped_ptr<ChromotingClientRuntime> runtime = |
| +// ChromotingClientRuntime::Create(ui_loop.get()); |
| +// |
| +// |
| +scoped_ptr<ChromotingClientRuntime> ChromotingClientRuntime::Create( |
| + base::MessageLoopForUI* ui_loop) { |
| + DCHECK(ui_loop); |
| + |
| + // |ui_loop_| runs on the main thread, so |ui_task_runner_| will run on the |
| + // main thread. We can not kill the main thread when the message loop becomes |
| + // idle so the callback function does nothing (as opposed to the typical |
| + // base::MessageLoop::QuitClosure()) |
| + scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( |
| + ui_loop->task_runner(), base::Bind(&base::DoNothing)); |
| + |
| + scoped_refptr<AutoThreadTaskRunner> display_task_runner = |
| + AutoThread::Create("native_disp", ui_task_runner); |
| + scoped_refptr<AutoThreadTaskRunner> network_task_runner = |
| + AutoThread::CreateWithType("native_net", ui_task_runner, |
| + base::MessageLoop::TYPE_IO); |
| + scoped_refptr<AutoThreadTaskRunner> file_task_runner = |
| + AutoThread::CreateWithType("native_file", ui_task_runner, |
| + base::MessageLoop::TYPE_IO); |
| + scoped_refptr<net::URLRequestContextGetter> url_requester = |
| + new URLRequestContextGetter(network_task_runner, file_task_runner); |
| + |
| + return make_scoped_ptr(new ChromotingClientRuntime( |
| + display_task_runner, network_task_runner, file_task_runner, |
| + url_requester)); |
| +} |
| + |
| +ChromotingClientRuntime::ChromotingClientRuntime( |
| + scoped_refptr<AutoThreadTaskRunner> display_task_runner, |
| + scoped_refptr<AutoThreadTaskRunner> network_task_runner, |
| + scoped_refptr<AutoThreadTaskRunner> file_task_runner, |
| + scoped_refptr<net::URLRequestContextGetter> url_requester) |
| + : display_task_runner_(display_task_runner), |
| + network_task_runner_(network_task_runner), |
| + file_task_runner_(file_task_runner), |
| + url_requester_(url_requester) {} |
| + |
| +ChromotingClientRuntime::~ChromotingClientRuntime() {} |
| + |
| +} // namespace remoting |