Chromium Code Reviews| 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/message_loop/message_loop.h" | |
| 10 #include "remoting/base/url_request_context_getter.h" | |
| 11 | |
| 12 namespace remoting { | |
| 13 | |
| 14 // 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.
| |
| 15 // for use. Example: | |
| 16 // | |
| 17 // On Android, the UI thread is managed by Java, so we need to attach and | |
| 18 // start a special type of message loop to allow Chromium code to run tasks. | |
| 19 // | |
| 20 // scoped_ptr<base::MessageLoopForUI> ui_loop; | |
| 21 // ui_loop_.reset(new base::MessageLoopForUI()); | |
| 22 // ui_loop_->Start(); | |
| 23 // scoped_ptr<ChromotingClientRuntime> runtime = | |
| 24 // ChromotingClientRuntime::Create(ui_loop.get()); | |
| 25 // | |
| 26 // On iOS we created a new message loop and now attach it. | |
| 27 // | |
| 28 // scoped_ptr<base::MessageLoopForUI> ui_loop; | |
| 29 // ui_loop_.reset(new base::MessageLoopForUI()); | |
| 30 // base::MessageLoopForUI::current()->Attach(); | |
| 31 // scoped_ptr<ChromotingClientRuntime> runtime = | |
| 32 // ChromotingClientRuntime::Create(ui_loop.get()); | |
| 33 // | |
| 34 // | |
| 35 scoped_ptr<ChromotingClientRuntime> ChromotingClientRuntime::Create( | |
| 36 base::MessageLoopForUI* ui_loop) { | |
| 37 DCHECK(ui_loop); | |
| 38 | |
| 39 // |ui_loop_| runs on the main thread, so |ui_task_runner_| will run on the | |
| 40 // main thread. We can not kill the main thread when the message loop becomes | |
| 41 // idle so the callback function does nothing (as opposed to the typical | |
| 42 // base::MessageLoop::QuitClosure()) | |
| 43 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( | |
| 44 ui_loop->task_runner(), base::Bind(&base::DoNothing)); | |
| 45 | |
| 46 scoped_refptr<AutoThreadTaskRunner> display_task_runner = | |
| 47 AutoThread::Create("native_disp", ui_task_runner); | |
| 48 scoped_refptr<AutoThreadTaskRunner> network_task_runner = | |
| 49 AutoThread::CreateWithType("native_net", ui_task_runner, | |
| 50 base::MessageLoop::TYPE_IO); | |
| 51 scoped_refptr<AutoThreadTaskRunner> file_task_runner = | |
| 52 AutoThread::CreateWithType("native_file", ui_task_runner, | |
| 53 base::MessageLoop::TYPE_IO); | |
| 54 scoped_refptr<net::URLRequestContextGetter> url_requester = | |
| 55 new URLRequestContextGetter(network_task_runner, file_task_runner); | |
| 56 | |
| 57 return make_scoped_ptr(new ChromotingClientRuntime( | |
| 58 display_task_runner, network_task_runner, file_task_runner, | |
| 59 url_requester)); | |
| 60 } | |
| 61 | |
| 62 ChromotingClientRuntime::ChromotingClientRuntime( | |
| 63 scoped_refptr<AutoThreadTaskRunner> display_task_runner, | |
| 64 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | |
| 65 scoped_refptr<AutoThreadTaskRunner> file_task_runner, | |
| 66 scoped_refptr<net::URLRequestContextGetter> url_requester) | |
| 67 : display_task_runner_(display_task_runner), | |
| 68 network_task_runner_(network_task_runner), | |
| 69 file_task_runner_(file_task_runner), | |
| 70 url_requester_(url_requester) {} | |
| 71 | |
| 72 ChromotingClientRuntime::~ChromotingClientRuntime() {} | |
| 73 | |
| 74 } // namespace remoting | |
| OLD | NEW |